raz / .github / workflows / container.yml

100 lines · 3.8 KiB · raw · history · last change 0442dd12

1name: CI image and registry
2on:
3 push:
4 branches: [main]
5 paths:
6 - 'containers/ci/**'
7 - 'registry/**'
8 - '.github/workflows/container.yml'
9 pull_request:
10 paths:
11 - 'containers/ci/**'
12 - 'registry/**'
13 - '.github/workflows/container.yml'
14 workflow_dispatch:
15 inputs:
16 publish:
17 description: Push the validated image to the configured Cloudflare registry
18 type: boolean
19 default: false
20permissions:
21 contents: read
22concurrency:
23 group: raz-ci-image
24 cancel-in-progress: false
25env:
26 IMAGE_TAG: 0.21.0-debian12-r1
27jobs:
28 registry:
29 runs-on: ubuntu-24.04
30 defaults:
31 run:
32 working-directory: registry
33 steps:
34 - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
35 - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
36 with:
37 node-version: '24'
38 cache: npm
39 cache-dependency-path: registry/package-lock.json
40 - run: npm ci
41 - run: npm test
42 - run: npm run dry-run
43 image:
44 needs: registry
45 runs-on: ubuntu-24.04
46 steps:
47 - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
48 - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
49 with:
50 node-version: '24'
51 cache: npm
52 cache-dependency-path: registry/package-lock.json
53 - name: Build the pinned tools and run their tests
54 run: docker build --platform linux/amd64 -t "raz:$IMAGE_TAG" containers/ci
55 - name: Check layer sizes against the registry upload limit
56 run: docker save "raz:$IMAGE_TAG" | python3 containers/ci/check-layers.py
57 - name: Smoke-test the final image
58 run: docker run --rm "raz:$IMAGE_TAG" sh /usr/local/share/raz-ci/smoke.sh
59 - name: Record the exact image contents
60 run: docker run --rm "raz:$IMAGE_TAG" cat /usr/local/share/raz-ci/versions.txt
61 - name: Test Docker publishing and anonymous pulling locally
62 working-directory: registry
63 run: |
64 npm ci
65 npm run test:docker -- "raz:$IMAGE_TAG"
66 - name: Check the release tag has not been published
67 if: github.event_name == 'workflow_dispatch' && inputs.publish
68 env:
69 REGISTRY: ${{ vars.RAZ_REGISTRY || 'raz-registry.lucelad.workers.dev' }}
70 run: |
71 status=$(curl --silent --show-error --head --output /dev/null --write-out '%{http_code}' \
72 "https://$REGISTRY/v2/raz/manifests/$IMAGE_TAG")
73 if [ "$status" != 404 ]; then
74 echo "Expected an unpublished tag (404); got $status. Refusing to replace a release."
75 exit 1
76 fi
77 - name: Log in for publishing
78 if: github.event_name == 'workflow_dispatch' && inputs.publish
79 uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
80 with:
81 registry: ${{ vars.RAZ_REGISTRY || 'raz-registry.lucelad.workers.dev' }}
82 username: publisher
83 password: ${{ secrets.RAZ_REGISTRY_PASSWORD }}
84 - name: Publish the validated image
85 if: github.event_name == 'workflow_dispatch' && inputs.publish
86 env:
87 REGISTRY: ${{ vars.RAZ_REGISTRY || 'raz-registry.lucelad.workers.dev' }}
88 run: |
89 docker tag "raz:$IMAGE_TAG" "$REGISTRY/raz:$IMAGE_TAG"
90 docker push "$REGISTRY/raz:$IMAGE_TAG"
91 - name: Verify an anonymous pull
92 if: github.event_name == 'workflow_dispatch' && inputs.publish
93 env:
94 REGISTRY: ${{ vars.RAZ_REGISTRY || 'raz-registry.lucelad.workers.dev' }}
95 run: |
96 docker_config=$(mktemp -d)
97 docker --config "$docker_config" pull "$REGISTRY/raz:$IMAGE_TAG"
98 docker --config "$docker_config" run --rm "$REGISTRY/raz:$IMAGE_TAG" \
99 sh /usr/local/share/raz-ci/smoke.sh
100 rm -r "$docker_config"