Skip to content

Commit 41ff7f7

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 41ff7f7

4 files changed

Lines changed: 67 additions & 22 deletions

File tree

.github/workflows/test-devcontainer.yml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
os: [debian, c10s]
21+
os: [debian]
22+
# TODO: c10s has PAM/sudo issues with devcontainer CLI's --userns=keep-id
23+
# include:
24+
# - os: c10s
2225

2326
steps:
2427
- name: Checkout
@@ -27,12 +30,37 @@ jobs:
2730
- name: Set up runner
2831
uses: bootc-dev/actions/bootc-ubuntu-setup@main
2932

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 }}
33+
- name: Build devcontainer image
34+
run: just devenv-build-${{ matrix.os }}
35+
36+
- name: Create override config for local image
37+
run: |
38+
cat > /tmp/devcontainer-override.json << 'EOF'
39+
{
40+
"image": "localhost/bootc-devenv-${{ matrix.os }}:latest",
41+
"runArgs": [
42+
"--security-opt", "label=disable",
43+
"--security-opt", "unmask=/proc/*",
44+
"--device", "/dev/net/tun",
45+
"--device", "/dev/kvm"
46+
],
47+
"postCreateCommand": {
48+
"devenv-init": "sudo /usr/local/bin/devenv-init.sh"
49+
}
50+
}
51+
EOF
52+
53+
- name: Start devcontainer
54+
run: |
55+
npx --yes @devcontainers/cli up \
56+
--workspace-folder . \
57+
--docker-path podman \
58+
--override-config /tmp/devcontainer-override.json \
59+
--remove-existing-container
3660
3761
- name: Test nested podman in devcontainer
38-
run: just devcontainer-test ${{ env.REGISTRY }}/${{ github.repository_owner }}/devenv-${{ matrix.os }}:latest
62+
run: |
63+
npx @devcontainers/cli exec \
64+
--workspace-folder . \
65+
--docker-path podman \
66+
/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: 7 additions & 4 deletions
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
@@ -88,9 +92,8 @@ useradd -m devenv -s /bin/bash
8892
mkdir -p ~devenv/.local/share/containers
8993
chown -R -h devenv: ~devenv/.local
9094
echo 'devenv ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/devenv && chmod 0440 /etc/sudoers.d/devenv
91-
# Make /etc/shadow readable by root group, required for PAM to work with
92-
# sudo in containers using --userns=keep-id (matches Debian behavior)
93-
chmod 040 /etc/shadow
95+
# TODO: /etc/shadow permissions need fixing for PAM/sudo with --userns=keep-id
96+
# See https://github.com/bootc-dev/infra/issues/XXX
9497
EORUN
9598
# To avoid overlay-on-overlay with nested containers
9699
VOLUME [ "/var/lib/containers", "/home/devenv/.local/share/containers/" ]

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)