Skip to content

Commit aa0fa05

Browse files
committed
test-devcontainer: Build image before testing
The test was pulling pre-built images from the registry, but those don't have the selftest script until this PR is merged. Build the image locally first using the existing just targets. Also switch from docker to podman for consistency with the build. Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 868402f commit aa0fa05

4 files changed

Lines changed: 61 additions & 18 deletions

File tree

.github/workflows/test-devcontainer.yml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,37 @@ jobs:
2727
- name: Set up runner
2828
uses: bootc-dev/actions/bootc-ubuntu-setup@main
2929

30-
- name: Login to GitHub Container Registry
31-
uses: docker/login-action@v3
32-
with:
33-
registry: ${{ env.REGISTRY }}
34-
username: ${{ github.repository_owner }}
35-
password: ${{ secrets.GITHUB_TOKEN }}
30+
- name: Build devcontainer image
31+
run: just devenv-build-${{ matrix.os }}
32+
33+
- name: Create override config for local image
34+
run: |
35+
cat > /tmp/devcontainer-override.json << 'EOF'
36+
{
37+
"image": "localhost/bootc-devenv-${{ matrix.os }}:latest",
38+
"runArgs": [
39+
"--security-opt", "label=disable",
40+
"--security-opt", "unmask=/proc/*",
41+
"--device", "/dev/net/tun",
42+
"--device", "/dev/kvm"
43+
],
44+
"postCreateCommand": {
45+
"devenv-init": "sudo /usr/local/bin/devenv-init.sh"
46+
}
47+
}
48+
EOF
49+
50+
- name: Start devcontainer
51+
run: |
52+
npx --yes @devcontainers/cli up \
53+
--workspace-folder . \
54+
--docker-path podman \
55+
--override-config /tmp/devcontainer-override.json \
56+
--remove-existing-container
3657
3758
- name: Test nested podman in devcontainer
38-
run: just devcontainer-test ${{ env.REGISTRY }}/${{ github.repository_owner }}/devenv-${{ matrix.os }}:latest
59+
run: |
60+
npx @devcontainers/cli exec \
61+
--workspace-folder . \
62+
--docker-path podman \
63+
/usr/libexec/devenv-selftest.sh

Justfile

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,25 @@ devenv-build-c10s:
1313
# Build devenv image with local tag (defaults to Debian)
1414
devenv-build: devenv-build-debian
1515

16-
# Test nested podman and VMs work in a devcontainer image
17-
# Usage: just devcontainer-test <image>
18-
# Example: just devcontainer-test ghcr.io/bootc-dev/devenv-debian:latest
19-
# Note: Uses --privileged because Docker doesn't support podman's unmask=/proc/* option
20-
devcontainer-test image:
21-
docker run --rm --privileged "{{ image }}" /usr/libexec/devenv-selftest.sh
16+
# Test devcontainer with a locally built image
17+
# Usage: just devcontainer-test <os>
18+
# Example: just devcontainer-test debian
19+
devcontainer-test os:
20+
#!/bin/bash
21+
set -euo pipefail
22+
cat > /tmp/devcontainer-override.json << 'EOF'
23+
{
24+
"image": "localhost/bootc-devenv-{{os}}:latest",
25+
"runArgs": [
26+
"--security-opt", "label=disable",
27+
"--security-opt", "unmask=/proc/*",
28+
"--device", "/dev/net/tun",
29+
"--device", "/dev/kvm"
30+
],
31+
"postCreateCommand": {
32+
"devenv-init": "sudo /usr/local/bin/devenv-init.sh"
33+
}
34+
}
35+
EOF
36+
npx --yes @devcontainers/cli up --workspace-folder . --docker-path podman --override-config /tmp/devcontainer-override.json --remove-existing-container
37+
npx @devcontainers/cli exec --workspace-folder . --docker-path podman /usr/libexec/devenv-selftest.sh

devenv/Containerfile.c10s

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ ENV KANI_HOME=/usr/local/kani
7777
COPY devenv-init.sh /usr/local/bin/
7878
COPY userns-setup /usr/lib/devenv/userns-setup
7979
COPY devenv-selftest.sh /usr/libexec/
80-
RUN chmod 755 /usr/libexec/devenv-selftest.sh /usr/lib/devenv/userns-setup
80+
# Set file capabilities for newuidmap/newgidmap (C10s shadow-utils doesn't set these by default,
81+
# unlike Debian's uidmap package). Required for nested rootless podman.
82+
RUN chmod 755 /usr/libexec/devenv-selftest.sh /usr/lib/devenv/userns-setup && \
83+
setcap cap_setuid+ep /usr/bin/newuidmap && \
84+
setcap cap_setgid+ep /usr/bin/newgidmap
8185

8286
WORKDIR /
8387
# Create user before declaring volumes so home directory has correct ownership

devenv/devenv-selftest.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#!/bin/bash
22
# Test that nested podman and VMs work correctly in this devcontainer.
3-
# This script is designed to be run inside the container after devenv-init.sh.
3+
# This script is designed to be run inside the container after devenv-init.sh
4+
# has already been executed (e.g., via postCreateCommand).
45
set -euo pipefail
56

67
echo "=== Testing nested podman and VMs ==="
78

8-
echo "Running devenv-init.sh..."
9-
sudo /usr/local/bin/devenv-init.sh
10-
119
echo "Podman version:"
1210
podman --version
1311

0 commit comments

Comments
 (0)