|
| 1 | +name: Test Docker Image |
| 2 | + |
| 3 | +permissions: {} |
| 4 | + |
| 5 | +on: |
| 6 | + # Manual runs can pin a specific vp version or verify a PR's registry-bridge |
| 7 | + # build. Leave both blank to use the Dockerfile defaults (VP_VERSION=latest). |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + vp_version: |
| 11 | + description: 'vp version or dist-tag to install (blank = Dockerfile default: latest)' |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + vp_pr_version: |
| 15 | + description: 'PR number or commit SHA to build a preview image from the registry bridge (overrides vp_version)' |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + pull_request: |
| 19 | + paths: |
| 20 | + - 'docker/**' |
| 21 | + - '.github/workflows/test-docker-image.yml' |
| 22 | + |
| 23 | +concurrency: |
| 24 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} |
| 25 | + cancel-in-progress: true |
| 26 | + |
| 27 | +defaults: |
| 28 | + run: |
| 29 | + shell: bash |
| 30 | + |
| 31 | +jobs: |
| 32 | + build-and-smoke-test: |
| 33 | + name: Build and smoke-test the toolchain image |
| 34 | + runs-on: ubuntu-latest |
| 35 | + timeout-minutes: 20 |
| 36 | + permissions: |
| 37 | + contents: read |
| 38 | + env: |
| 39 | + IMAGE: vite-plus:ci-smoke |
| 40 | + steps: |
| 41 | + - uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2 |
| 42 | + |
| 43 | + - uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0 |
| 44 | + |
| 45 | + # Only forward build-args that were provided (manual runs), so |
| 46 | + # empty inputs fall back to the Dockerfile defaults instead of overriding |
| 47 | + # them with empty strings. |
| 48 | + - name: Resolve build args |
| 49 | + id: buildargs |
| 50 | + env: |
| 51 | + VP_VERSION: ${{ inputs.vp_version }} |
| 52 | + VP_PR_VERSION: ${{ inputs.vp_pr_version }} |
| 53 | + run: | |
| 54 | + { |
| 55 | + echo "args<<__EOF__" |
| 56 | + if [ -n "$VP_VERSION" ]; then echo "VP_VERSION=$VP_VERSION"; fi |
| 57 | + if [ -n "$VP_PR_VERSION" ]; then echo "VP_PR_VERSION=$VP_PR_VERSION"; fi |
| 58 | + echo "__EOF__" |
| 59 | + } >> "$GITHUB_OUTPUT" |
| 60 | +
|
| 61 | + # Build the toolchain image locally and load it into the daemon (no push). |
| 62 | + # amd64-only keeps it fast; the release build covers arm64. |
| 63 | + - name: Build image |
| 64 | + uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 |
| 65 | + with: |
| 66 | + context: docker |
| 67 | + file: docker/Dockerfile |
| 68 | + platforms: linux/amd64 |
| 69 | + load: true |
| 70 | + push: false |
| 71 | + tags: ${{ env.IMAGE }} |
| 72 | + build-args: ${{ steps.buildargs.outputs.args }} |
| 73 | + provenance: false |
| 74 | + |
| 75 | + # Guard the security/DX balance the image commits to: it stays non-root by |
| 76 | + # default, yet the vp user can reach root through sudo. The apt-get check is |
| 77 | + # the exact escalation `playwright install --with-deps` performs, so this |
| 78 | + # would have caught the missing-sudo failure from issue #2087. |
| 79 | + - name: Smoke test |
| 80 | + run: | |
| 81 | + docker run --rm "$IMAGE" sh -euc ' |
| 82 | + echo "== default user is the non-root vp (uid 1000) ==" |
| 83 | + user=$(whoami); uid=$(id -u) |
| 84 | + echo "user=$user uid=$uid" |
| 85 | + [ "$user" = vp ] || { echo "FAIL: expected default user vp, got $user"; exit 1; } |
| 86 | + [ "$uid" = 1000 ] || { echo "FAIL: expected uid 1000, got $uid"; exit 1; } |
| 87 | +
|
| 88 | + echo "== sudo present so playwright install --with-deps takes the sudo branch ==" |
| 89 | + command -v sudo >/dev/null || { echo "FAIL: sudo not on PATH"; exit 1; } |
| 90 | +
|
| 91 | + echo "== passwordless sudo works (no su-root password fallback) ==" |
| 92 | + sudo -n true || { echo "FAIL: passwordless sudo did not work"; exit 1; } |
| 93 | +
|
| 94 | + echo "== the exact apt-get escalation playwright runs succeeds ==" |
| 95 | + sudo -n -- sh -c "apt-get --version >/dev/null" || { echo "FAIL: elevated apt-get"; exit 1; } |
| 96 | +
|
| 97 | + echo "== vp is installed and runnable ==" |
| 98 | + vp --version |
| 99 | +
|
| 100 | + echo "ALL SMOKE CHECKS PASSED" |
| 101 | + ' |
| 102 | +
|
| 103 | + # End-to-end proof for issue #2087: run a real Vitest browser-mode test |
| 104 | + # (Playwright, headless Chromium) with `vp test` inside the image. This |
| 105 | + # exercises the whole path the report needed and the smoke test only |
| 106 | + # simulates: `playwright install --with-deps` escalating to root via sudo, |
| 107 | + # then launching Chromium as the non-root vp user. On the old (sudo-less) |
| 108 | + # image the install step fails with `su: Authentication failure`. |
| 109 | + # Repro repo: https://github.com/why-reproductions-are-required/vite-plus-vitest-browser-mode |
| 110 | + - name: Vitest browser mode e2e (vp test) |
| 111 | + run: | |
| 112 | + docker run --rm -w /app "$IMAGE" bash -euc ' |
| 113 | + git clone --depth 1 https://github.com/why-reproductions-are-required/vite-plus-vitest-browser-mode . |
| 114 | + vp install --frozen-lockfile |
| 115 | + vp exec playwright install --with-deps chromium |
| 116 | + vp test |
| 117 | + ' |
0 commit comments