Skip to content

Commit 0bc8508

Browse files
authored
Merge pull request #123 from AkihiroSuda/rootless-stargz
rootless: support stargz
2 parents f555cde + 10780ec commit 0bc8508

File tree

7 files changed

+116
-28
lines changed

7 files changed

+116
-28
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
timeout-minutes: 20
4343
strategy:
4444
matrix:
45-
containerd: [1.4.4, 1.5.0-beta.3]
45+
containerd: [1.4.4, 1.5.0-beta.4]
4646
env:
4747
CONTAINERD_VERSION: "${{ matrix.containerd }}"
4848
steps:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ARG CNI_ISOLATION_VERSION=0.0.3
2525
# Extra deps: Build
2626
ARG BUILDKIT_VERSION=0.8.2
2727
# Extra deps: Lazy-pulling
28-
ARG STARGZ_SNAPSHOTTER_VERSION=0.4.1
28+
ARG STARGZ_SNAPSHOTTER_VERSION=0.5.0
2929
# Extra deps: Encryption
3030
ARG IMGCRYPT_VERSION=1.1.0
3131
# Extra deps: Rootless

docs/rootless.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ To enable `fuse-overlayfs` snapshotter, run the following command:
5858
$ containerd-rootless-setuptool.sh install-fuse-overlayfs
5959
```
6060

61-
Then, add the following config to `~/.config/containerd/config.toml`:
61+
Then, add the following config to `~/.config/containerd/config.toml`, and run `systemctl --user restart containerd.service`:
6262
```toml
6363
[proxy_plugins]
6464
[proxy_plugins."fuse-overlayfs"]
@@ -75,6 +75,36 @@ $ nerdctl run -it --rm alpine
7575

7676
If `fuse-overlayfs` does not work, try `export CONTAINERD_SNAPSHOTTER=native`.
7777

78+
### Stargz Snapshotter
79+
[Stargz Snapshotter](./stargz.md) enables lazy-pulling of images.
80+
81+
As of Stargz Snapshotter 0.5.0, Rootless Stargz Snapshotter supports the following hosts:
82+
- Any distro, with kernel >= 5.11
83+
- Ubuntu (>= 15.XX)
84+
- Debian (>= 10)
85+
86+
To enable Stargz snapshotter, run the following command:
87+
```console
88+
$ containerd-rootless-setuptool.sh install-stargz
89+
```
90+
91+
Then, add the following config to `~/.config/containerd/config.toml` and run `systemctl --user restart containerd.service`:
92+
```toml
93+
[proxy_plugins]
94+
[proxy_plugins."stargz"]
95+
type = "snapshot"
96+
# NOTE: replace "1000" with your actual UID
97+
address = "/run/user/1000/containerd-stargz-grpc/containerd-stargz-grpc.sock"
98+
```
99+
100+
The snapshotter can be specified as `$CONTAINERD_SNAPSHOTTER`.
101+
```console
102+
$ export CONTAINERD_SNAPSHOTTER=stargz
103+
$ nerdctl run -it --rm ghcr.io/stargz-containers/alpine:3.10.2-esgz
104+
```
105+
106+
See https://github.com/containerd/stargz-snapshotter/blob/master/docs/pre-converted-images.md for the image list.
107+
78108
## Troubleshooting
79109

80110
### Hint to Fedora 33 users

docs/stargz.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ See https://github.com/containerd/stargz-snapshotter to learn further informatio
77
[![asciicast](https://asciinema.org/a/378377.svg)](https://asciinema.org/a/378377)
88

99
## Enable lazy-pulling for `nerdctl run`
10+
11+
> **NOTE**
12+
> For rootless installation, see [`rootless.md`](./rootless.md#stargz-snapshotter)
13+
1014
- Install Stargz plugin (`containerd-stargz-grpc`) from https://github.com/containerd/stargz-snapshotter
1115

1216
- Add the following to `/etc/containerd/config.toml`:

extras/rootless/containerd-rootless-setuptool.sh

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ CONTAINERD_ROOTLESS_SH="containerd-rootless.sh"
4848
SYSTEMD_CONTAINERD_UNIT="containerd.service"
4949
SYSTEMD_BUILDKIT_UNIT="buildkit.service"
5050
SYSTEMD_FUSE_OVERLAYFS_UNIT="containerd-fuse-overlayfs.service"
51+
SYSTEMD_STARGZ_UNIT="stargz-snapshotter.service"
5152

5253
# global vars
5354
ARG0="$0"
@@ -301,7 +302,7 @@ cmd_entrypoint_install_fuse_overlayfs() {
301302
[Install]
302303
WantedBy=default.target
303304
EOT
304-
INFO "Add the following lines to \"${XDG_CONFIG_HOME}/containerd/config.toml\" manually:"
305+
INFO "Add the following lines to \"${XDG_CONFIG_HOME}/containerd/config.toml\" manually, and then run \`systemctl --user restart ${SYSTEMD_CONTAINERD_UNIT}\`:"
305306
cat <<-EOT
306307
### BEGIN ###
307308
[proxy_plugins]
@@ -313,6 +314,50 @@ cmd_entrypoint_install_fuse_overlayfs() {
313314
INFO "Set \`export CONTAINERD_SNAPSHOTTER=\"fuse-overlayfs\"\` to use the fuse-overlayfs snapshotter."
314315
}
315316

317+
# CLI subcommand: "install-stargz"
318+
cmd_entrypoint_install_stargz() {
319+
init
320+
if ! command -v "containerd-stargz-grpc" >/dev/null 2>&1; then
321+
ERROR "containerd-stargz-grpc (https://github.com/containerd/stargz-snapshotter) needs to be present under \$PATH"
322+
exit 1
323+
fi
324+
if ! systemctl --user --no-pager status "${SYSTEMD_CONTAINERD_UNIT}" >/dev/null 2>&1; then
325+
ERROR "Install containerd first (\`$ARG0 install\`)"
326+
exit 1
327+
fi
328+
if [ ! -f "${XDG_CONFIG_HOME}/containerd-stargz-grpc/config.toml" ]; then
329+
mkdir -p "${XDG_CONFIG_HOME}/containerd-stargz-grpc"
330+
touch "${XDG_CONFIG_HOME}/containerd-stargz-grpc/config.toml"
331+
fi
332+
cat <<-EOT | install_systemd_unit "${SYSTEMD_STARGZ_UNIT}"
333+
[Unit]
334+
Description=stargz snapshotter (Rootless)
335+
PartOf=${SYSTEMD_CONTAINERD_UNIT}
336+
337+
[Service]
338+
Environment=PATH=$BIN:/sbin:/usr/sbin:$PATH
339+
ExecStart="$REALPATH0" nsenter -- containerd-stargz-grpc -address "${XDG_RUNTIME_DIR}/containerd-stargz-grpc/containerd-stargz-grpc.sock" -root "${XDG_DATA_HOME}/containerd-stargz-grpc" -config "${XDG_CONFIG_HOME}/containerd-stargz-grpc/config.toml"
340+
ExecReload=/bin/kill -s HUP \$MAINPID
341+
RestartSec=2
342+
Restart=always
343+
Type=simple
344+
KillMode=mixed
345+
346+
[Install]
347+
WantedBy=default.target
348+
EOT
349+
INFO "Add the following lines to \"${XDG_CONFIG_HOME}/containerd/config.toml\" manually, and then run \`systemctl --user restart ${SYSTEMD_CONTAINERD_UNIT}\`:"
350+
cat <<-EOT
351+
### BEGIN ###
352+
[proxy_plugins]
353+
[proxy_plugins."stargz"]
354+
type = "snapshot"
355+
address = "${XDG_RUNTIME_DIR}/containerd-stargz-grpc/containerd-stargz-grpc.sock"
356+
### END ###
357+
EOT
358+
INFO "Set \`export CONTAINERD_SNAPSHOTTER=\"stargz\"\` to use the stargz snapshotter."
359+
}
360+
316361
# CLI subcommand: "uninstall"
317362
cmd_entrypoint_uninstall() {
318363
init
@@ -340,6 +385,14 @@ cmd_entrypoint_uninstall_fuse_overlayfs() {
340385
INFO "To remove data, run: \`$BIN/rootlesskit rm -rf ${XDG_DATA_HOME}/containerd-fuse-overlayfs"
341386
}
342387

388+
# CLI subcommand: "uninstall-stargz"
389+
cmd_entrypoint_uninstall_stargz() {
390+
init
391+
uninstall_systemd_unit "${SYSTEMD_STARGZ_UNIT}"
392+
INFO "This uninstallation tool does NOT remove data."
393+
INFO "To remove data, run: \`$BIN/rootlesskit rm -rf ${XDG_DATA_HOME}/containerd-stargz-grpc"
394+
}
395+
343396
# text for --help
344397
usage() {
345398
echo "Usage: ${ARG0} [OPTIONS] COMMAND"
@@ -359,6 +412,10 @@ usage() {
359412
echo "Add-on commands (fuse-overlayfs):"
360413
echo " install-fuse-overlayfs Install the systemd unit for fuse-overlayfs snapshotter"
361414
echo " uninstall-fuse-overlayfs Uninstall the systemd unit for fuse-overlayfs snapshotter"
415+
echo
416+
echo "Add-on commands (stargz):"
417+
echo " install-stargz Install the systemd unit for stargz snapshotter"
418+
echo " uninstall-stargz Uninstall the systemd unit for stargz snapshotter"
362419
}
363420

364421
# parse CLI args

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ go 1.16
55
require (
66
github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68
77
github.com/containerd/console v1.0.1
8-
github.com/containerd/containerd v1.5.0-beta.3
8+
github.com/containerd/containerd v1.5.0-beta.4
99
github.com/containerd/go-cni v1.0.1
10-
github.com/containerd/imgcrypt v1.1.0
11-
github.com/containerd/stargz-snapshotter v0.4.1
12-
github.com/containerd/stargz-snapshotter/estargz v0.4.1
10+
github.com/containerd/imgcrypt v1.1.1-0.20210312161619-7ed62a527887
11+
github.com/containerd/stargz-snapshotter v0.5.0
12+
github.com/containerd/stargz-snapshotter/estargz v0.5.0
1313
github.com/containerd/typeurl v1.0.1
1414
github.com/containernetworking/cni v0.8.1
1515
github.com/containernetworking/plugins v0.9.1

0 commit comments

Comments
 (0)