Skip to content

Commit ce919a8

Browse files
authored
Merge pull request #93 from AkihiroSuda/dev
rootless: add `containerd-rootless-setuptool.sh install-buildkit`
2 parents 701a05d + ce97026 commit ce919a8

4 files changed

Lines changed: 64 additions & 5 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,6 @@ RUN useradd -m -s /bin/bash rootless && \
138138
VOLUME /home/rootless/.local/share
139139
RUN go test -o /usr/local/bin/nerdctl.test -c .
140140
CMD ["machinectl", "shell", "rootless@", "/bin/sh", "-euxc", \
141-
"containerd-rootless-setuptool.sh install && exec nerdctl.test -test.v -test.kill-daemon"]
141+
"containerd-rootless-setuptool.sh install && containerd-rootless-setuptool.sh install-buildkit && exec nerdctl.test -test.v -test.kill-daemon"]
142142

143143
FROM base AS demo

docs/rootless.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ Depending on your kernel version, you may need to enable FUSE-OverlayFS or set `
3737
(See below.)
3838

3939
## Add-ons
40+
### BuildKit
41+
To enable BuildKit, run the following command:
42+
43+
```console
44+
$ containerd-rootless-setuptool.sh install-buildkit
45+
```
46+
4047
### FUSE-OverlayFS
4148

4249
The `overlayfs` snapshotter only works on the following hosts:

extras/rootless/containerd-rootless-setuptool.sh

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ERROR() {
4545
# constants
4646
CONTAINERD_ROOTLESS_SH="containerd-rootless.sh"
4747
SYSTEMD_CONTAINERD_UNIT="containerd.service"
48+
SYSTEMD_BUILDKIT_UNIT="buildkit.service"
4849
SYSTEMD_FUSE_OVERLAYFS_UNIT="containerd-fuse-overlayfs.service"
4950

5051
# global vars
@@ -238,17 +239,51 @@ cmd_entrypoint_install() {
238239
INFO "You do NOT need to specify \$CONTAINERD_ADDRESS explicitly."
239240
}
240241

242+
# CLI subcommand: "install-buildkit"
243+
cmd_entrypoint_install_buildkit() {
244+
init
245+
if ! command -v "buildkitd" >/dev/null 2>&1; then
246+
ERROR "buildkitd (https://github.com/moby/buildkit) needs to be present under \$PATH"
247+
exit 1
248+
fi
249+
if ! systemctl --user --no-pager status "${SYSTEMD_CONTAINERD_UNIT}" >/dev/null 2>&1; then
250+
ERROR "Install containerd first (\`$ARG0 install\`)"
251+
exit 1
252+
fi
253+
cat <<-EOT | install_systemd_unit "${SYSTEMD_BUILDKIT_UNIT}"
254+
[Unit]
255+
Description=BuildKit (Rootless)
256+
PartOf=${SYSTEMD_CONTAINERD_UNIT}
257+
258+
[Service]
259+
Environment=PATH=$BIN:/sbin:/usr/sbin:$PATH
260+
ExecStart="$REALPATH0" nsenter buildkitd
261+
ExecReload=/bin/kill -s HUP \$MAINPID
262+
RestartSec=2
263+
Restart=always
264+
Type=simple
265+
KillMode=mixed
266+
267+
[Install]
268+
WantedBy=default.target
269+
EOT
270+
}
271+
241272
# CLI subcommand: "install-fuse-overlayfs"
242273
cmd_entrypoint_install_fuse_overlayfs() {
243274
init
244-
if ! command -v "containerd-fuse-overlayfs-grpc" 2>/dev/null; then
275+
if ! command -v "containerd-fuse-overlayfs-grpc" >/dev/null 2>&1; then
245276
ERROR "containerd-fuse-overlayfs-grpc (https://github.com/AkihiroSuda/containerd-fuse-overlayfs) needs to be present under \$PATH"
246277
exit 1
247278
fi
248-
if ! command -v "containerd-fuse-overlayfs-grpc" 2>/dev/null; then
279+
if ! command -v "containerd-fuse-overlayfs-grpc" >/dev/null 2>&1; then
249280
ERROR "fuse-overlayfs (https://github.com/containers/fuse-overlayfs) needs to be present under \$PATH"
250281
exit 1
251282
fi
283+
if ! systemctl --user --no-pager status "${SYSTEMD_CONTAINERD_UNIT}" >/dev/null 2>&1; then
284+
ERROR "Install containerd first (\`$ARG0 install\`)"
285+
exit 1
286+
fi
252287
cat <<-EOT | install_systemd_unit "${SYSTEMD_FUSE_OVERLAYFS_UNIT}"
253288
[Unit]
254289
Description=containerd-fuse-overlayfs (Rootless)
@@ -281,13 +316,22 @@ cmd_entrypoint_install_fuse_overlayfs() {
281316
# CLI subcommand: "uninstall"
282317
cmd_entrypoint_uninstall() {
283318
init
319+
uninstall_systemd_unit "${SYSTEMD_BUILDKIT_UNIT}"
284320
uninstall_systemd_unit "${SYSTEMD_FUSE_OVERLAYFS_UNIT}"
285321
uninstall_systemd_unit "${SYSTEMD_CONTAINERD_UNIT}"
286322

287323
INFO "This uninstallation tool does NOT remove containerd binaries and data."
288324
INFO "To remove data, run: \`$BIN/rootlesskit rm -rf ${XDG_DATA_HOME}/containerd\`"
289325
}
290326

327+
# CLI subcommand: "uninstall-buildkit"
328+
cmd_entrypoint_uninstall_buildkit() {
329+
init
330+
uninstall_systemd_unit "${SYSTEMD_BUILDKIT_UNIT}"
331+
INFO "This uninstallation tool does NOT remove data."
332+
INFO "To remove data, run: \`$BIN/rootlesskit rm -rf ${XDG_DATA_HOME}/buildkit"
333+
}
334+
291335
# CLI subcommand: "uninstall-fuse-overlayfs"
292336
cmd_entrypoint_uninstall_fuse_overlayfs() {
293337
init
@@ -308,7 +352,11 @@ usage() {
308352
echo " install Install systemd unit and show how to manage the service"
309353
echo " uninstall Uninstall systemd unit"
310354
echo
311-
echo "Add-on commands:"
355+
echo "Add-on commands (BuildKit):"
356+
echo " install-buildkit Install the systemd unit for BuildKit"
357+
echo " uninstall-buildkit Uninstall the systemd unit for BuildKit"
358+
echo
359+
echo "Add-on commands (fuse-overlayfs):"
312360
echo " install-fuse-overlayfs Install the systemd unit for fuse-overlayfs snapshotter"
313361
echo " uninstall-fuse-overlayfs Uninstall the systemd unit for fuse-overlayfs snapshotter"
314362
}

pkg/buildkitutil/buildkitutil.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"os"
2222
"os/exec"
2323

24+
"github.com/AkihiroSuda/nerdctl/pkg/rootlessutil"
2425
"github.com/pkg/errors"
2526
"github.com/sirupsen/logrus"
2627
)
@@ -34,7 +35,10 @@ func BuildctlBaseArgs(buildkitHost string) []string {
3435
}
3536

3637
func PingBKDaemon(buildkitHost string) error {
37-
const hint = "`buildctl` needs to be installed and `buildkitd` needs to be running, see https://github.com/moby/buildkit"
38+
hint := "`buildctl` needs to be installed and `buildkitd` needs to be running, see https://github.com/moby/buildkit"
39+
if rootlessutil.IsRootless() {
40+
hint += " , and `containerd-rootless-setuptool.sh install-buildkit`"
41+
}
3842
buildctlBinary, err := BuildctlBinary()
3943
if err != nil {
4044
return errors.Wrap(err, hint)

0 commit comments

Comments
 (0)