Skip to content

Commit aa23c52

Browse files
committed
Add test that nerdctl run binds to 0.0.0.0 by default
and that lima can detect this with guestIPMustBeZero. Signed-off-by: Jan Dubois <[email protected]>
1 parent 105aee6 commit aa23c52

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ task:
3030
- cat /proc/cpuinfo
3131
install_deps_script:
3232
- apt-get update
33-
- apt-get install -y --no-install-recommends ca-certificates curl git golang openssh-client make netcat ovmf sudo qemu-system-x86 qemu-utils
33+
- apt-get install -y --no-install-recommends ca-certificates curl git golang jq openssh-client make netcat ovmf sudo qemu-system-x86 qemu-utils
3434
go_cache:
3535
fingerprint_script: uname -s ; cat go.sum
3636
folder: $GOPATH/pkg/mod

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ jobs:
121121
# QEMU: required by Lima itself
122122
# bash: required by test-example.sh (OS version of bash is too old)
123123
# coreutils: required by test-example.sh for the "timeout" command
124+
# These would need to be added to run the alpine.yaml config on the macOS runner:
125+
# curl: required by test-example.sh to download nerdctl for alpine
126+
# jq: required by test-example.sh to determine download URL for nerdctl
124127
run: |
125128
set -x
126129
# Github runners seem to symlink to python2.7 version of 2to3,

hack/test-example.sh

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,14 @@ if [[ -n ${CHECKS["mount-home"]} ]]; then
168168
fi
169169
fi
170170

171+
# Use GHCR to avoid hitting Docker Hub rate limit
172+
nginx_image="ghcr.io/stargz-containers/nginx:1.19-alpine-org"
173+
alpine_image="ghcr.io/containerd/alpine:3.14.0"
174+
171175
if [[ -n ${CHECKS["containerd-user"]} ]]; then
172176
INFO "Run a nginx container with port forwarding 127.0.0.1:8080"
173177
set -x
174178
limactl shell "$NAME" nerdctl info
175-
# Use GHCR to avoid hitting Docker Hub rate limit
176-
nginx_image="ghcr.io/stargz-containers/nginx:1.19-alpine-org"
177179
limactl shell "$NAME" nerdctl pull --quiet ${nginx_image}
178180
limactl shell "$NAME" nerdctl run -d --name nginx -p 127.0.0.1:8080:80 ${nginx_image}
179181

@@ -189,7 +191,6 @@ if [[ -n ${CHECKS["containerd-user"]} ]]; then
189191
mkdir -p "$hometmp"
190192
defer "rm -rf \"$hometmp\""
191193
set -x
192-
alpine_image="ghcr.io/containerd/alpine:3.14.0"
193194
limactl shell "$NAME" nerdctl pull --quiet ${alpine_image}
194195
echo "random-content-${RANDOM}" >"$hometmp/random"
195196
expected="$(cat "$hometmp/random")"
@@ -219,6 +220,34 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
219220
limactl shell "$NAME" sudo zypper in -y netcat-openbsd
220221
fi
221222
"${scriptdir}/test-port-forwarding.pl" "${NAME}"
223+
224+
if [[ -n ${CHECKS["containerd-user"]} || ${NAME} == "alpine" ]]; then
225+
INFO "Testing that 'nerdctl run' binds to 0.0.0.0 by default and is forwarded to the host"
226+
if [ "$(uname)" = "Darwin" ]; then
227+
# macOS runners seem to use `localhost` as the hostname, so the perl lookup just returns `127.0.0.1`
228+
hostip=$(system_profiler SPNetworkDataType -json | jq -r 'first(.SPNetworkDataType[] | select(.ip_address) | .ip_address) | first')
229+
else
230+
hostip=$(perl -MSocket -MSys::Hostname -E 'say inet_ntoa(scalar gethostbyname(hostname()))')
231+
fi
232+
if [ -n "${hostip}" ]; then
233+
sudo=""
234+
if [ "${NAME}" = "alpine" ]; then
235+
arch=$(limactl info | jq -r .defaultTemplate.arch)
236+
nerdctl=$(limactl info | jq -r ".defaultTemplate.containerd.archives[] | select(.arch==\"$arch\").location")
237+
curl -Lso nerdctl-full.tgz "${nerdctl}"
238+
limactl shell "$NAME" sudo apk add containerd
239+
limactl shell "$NAME" sudo rc-service containerd start
240+
limactl shell "$NAME" sudo tar xzf "${PWD}/nerdctl-full.tgz" -C /usr/local
241+
rm nerdctl-full.tgz
242+
sudo="sudo"
243+
fi
244+
limactl shell "$NAME" $sudo nerdctl info
245+
limactl shell "$NAME" $sudo nerdctl pull --quiet ${nginx_image}
246+
limactl shell "$NAME" $sudo nerdctl run -d --name nginx -p 8888:80 ${nginx_image}
247+
248+
timeout 3m bash -euxc "until curl -f --retry 30 --retry-connrefused http://${hostip}:8888; do sleep 3; done"
249+
fi
250+
fi
222251
set +x
223252
fi
224253

hack/test-port-forwarding.pl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,10 @@ sub JoinHostPort {
304304
# forward: :: 4041 → 127.0.0.1 4041
305305
# ignore: 127.0.0.1 4043 → 127.0.0.1 4043
306306
# ignore: 192.168.5.15 4044 → 127.0.0.1 4044
307+
308+
# This rule exist to test `nerdctl run` binding to 0.0.0.0 by default,
309+
# and making sure it gets forwarded to the external host IP.
310+
# The actual test code is in test-example.sh in the "port-forwarding" block.
311+
- guestIPMustBeZero: true
312+
guestPort: 8888
313+
hostIP: 0.0.0.0

0 commit comments

Comments
 (0)