|
1 | 1 | name: CI/CD |
2 | | - |
3 | 2 | on: |
4 | 3 | push: |
5 | | - branches: |
6 | | - - master |
| 4 | + branches: [master] |
7 | 5 | pull_request: |
8 | 6 | workflow_dispatch: |
9 | 7 | schedule: |
10 | 8 | - cron: '0 0 * * 0' |
11 | | - |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 13 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
12 | 14 | jobs: |
| 15 | + checks: |
| 16 | + runs-on: ubuntu-24.04 |
| 17 | + outputs: |
| 18 | + tags: ${{ steps.tags.outputs.tags }} |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v7 |
| 21 | + - name: Check generated contexts and architecture selection |
| 22 | + run: | |
| 23 | + docker run --rm -v "$PWD:/app" fireworkweb/fwd:v1.0 fwd template |
| 24 | + git diff --exit-code |
| 25 | + bash tests/architecture.sh |
| 26 | + - id: tags |
| 27 | + run: echo "tags=$(jq -c '[.builds[].name] + [\"24-nginx\"]' fwd-template.json)" >> "$GITHUB_OUTPUT" |
13 | 28 | build: |
| 29 | + needs: checks |
| 30 | + runs-on: ${{ matrix.platform.runner }} |
14 | 31 | strategy: |
| 32 | + fail-fast: false |
15 | 33 | matrix: |
16 | | - version: [22, 24, 26] |
17 | | - runs-on: [ubuntu-24.04, ubuntu-24.04-arm] |
18 | | - runs-on: ${{ matrix.runs-on }} |
19 | | - |
| 34 | + version: ["22", "24", "26"] |
| 35 | + platform: |
| 36 | + - {arch: amd64, runner: ubuntu-24.04} |
| 37 | + - {arch: arm64, runner: ubuntu-24.04-arm} |
20 | 38 | steps: |
21 | | - - name: Checkout code |
22 | | - uses: actions/checkout@v6 |
23 | | - |
24 | | - - name: Set up Docker Buildx |
25 | | - uses: docker/setup-buildx-action@v3 |
26 | | - |
27 | | - - name: Check generated contexts and architecture selection |
28 | | - run: | |
29 | | - python3 tests/generated.py |
30 | | - sh tests/architecture.sh |
31 | | -
|
32 | | - - name: Compute cache week |
33 | | - id: cachekey |
34 | | - run: echo "week=$(date -u +%Y-%V)" >> "$GITHUB_OUTPUT" |
35 | | - |
36 | | - - name: Cache Docker layers |
37 | | - uses: actions/cache@v5 |
| 39 | + - uses: actions/checkout@v7 |
| 40 | + - uses: kool-dev/action/image-build@6a6d04e8d1e1c66afc178e32c7d77d76169c7717 |
| 41 | + with: |
| 42 | + arch: ${{ matrix.platform.arch }} |
| 43 | + - name: Build fresh base |
| 44 | + id: base |
| 45 | + uses: docker/build-push-action@v7 |
38 | 46 | with: |
39 | | - path: /tmp/.buildx-cache |
40 | | - key: docker-buildx-${{ matrix.runs-on }}-${{ matrix.version }}-${{ steps.cachekey.outputs.week }}-${{ github.sha }} |
41 | | - restore-keys: docker-buildx-${{ matrix.runs-on }}-${{ matrix.version }}-${{ steps.cachekey.outputs.week }}- |
42 | | - |
43 | | - - name: Build |
| 47 | + context: ${{ matrix.version }} |
| 48 | + platforms: linux/${{ matrix.platform.arch }} |
| 49 | + pull: true |
| 50 | + load: true |
| 51 | + provenance: false |
| 52 | + tags: kooldev/node:${{ matrix.version }} |
| 53 | + - name: Test base |
| 54 | + env: |
| 55 | + IMAGE: ${{ steps.base.outputs.imageid }} |
| 56 | + run: bash tests/image.sh "$IMAGE" |
| 57 | + - name: Build nginx from this job's Node 24 |
| 58 | + if: matrix.version == '24' |
| 59 | + id: nginx |
| 60 | + uses: docker/build-push-action@v7 |
| 61 | + with: |
| 62 | + context: 24-nginx |
| 63 | + build-args: NODE_IMAGE=kooldev/node:24 |
| 64 | + platforms: linux/${{ matrix.platform.arch }} |
| 65 | + load: true |
| 66 | + provenance: false |
| 67 | + tags: kooldev/node:24-nginx |
| 68 | + - uses: kool-dev/action/image-parent@6a6d04e8d1e1c66afc178e32c7d77d76169c7717 |
| 69 | + if: matrix.version == '24' |
| 70 | + with: |
| 71 | + base-ref: kooldev/node:24 |
| 72 | + base-id: ${{ steps.base.outputs.imageid }} |
| 73 | + image-id: ${{ steps.nginx.outputs.imageid }} |
| 74 | + - name: Test nginx |
| 75 | + if: matrix.version == '24' |
| 76 | + env: |
| 77 | + IMAGE: ${{ steps.nginx.outputs.imageid }} |
44 | 78 | run: | |
45 | | - docker buildx build \ |
46 | | - --pull \ |
47 | | - --cache-from type=local,src=/tmp/.buildx-cache/${{ matrix.version }} \ |
48 | | - --cache-to type=local,dest=/tmp/.buildx-cache/${{ matrix.version }} \ |
49 | | - --output type=docker \ |
50 | | - --tag "kooldev/node:${{ matrix.version }}-$(arch)" \ |
51 | | - ${{ matrix.version }} |
52 | | -
|
53 | | - - name: Tests |
54 | | - run: sh tests/image.sh "kooldev/node:${{ matrix.version }}-$(arch)" |
55 | | - |
56 | | - # Use the Docker engine's loaded, freshly tested parent, not yesterday's Hub tag. |
57 | | - - name: Build and test nginx from this run's Node 24 |
58 | | - if: matrix.version == 24 |
| 79 | + bash tests/image.sh "$IMAGE" |
| 80 | + docker run --rm "$IMAGE" nginx -t |
| 81 | + - name: Collect tested IDs |
| 82 | + id: images |
| 83 | + env: |
| 84 | + VERSION: ${{ matrix.version }} |
| 85 | + BASE_ID: ${{ steps.base.outputs.imageid }} |
| 86 | + NGINX_ID: ${{ steps.nginx.outputs.imageid }} |
59 | 87 | run: | |
60 | | - docker build --builder default --pull=false \ |
61 | | - --build-arg "NODE_IMAGE=kooldev/node:24-$(arch)" \ |
62 | | - --tag "kooldev/node:24-nginx-$(arch)" 24-nginx |
63 | | - sh tests/image.sh "kooldev/node:24-nginx-$(arch)" |
64 | | - docker run --rm "kooldev/node:24-nginx-$(arch)" nginx -t |
65 | | -
|
66 | | - - name: Login to DockerHub |
67 | | - uses: docker/login-action@v3 |
| 88 | + images=$(jq -cn --arg version "$VERSION" --arg bid "$BASE_ID" --arg nid "$NGINX_ID" \ |
| 89 | + '[{tag:$version,id:$bid}] + if $nid == "" then [] else [{tag:"24-nginx",id:$nid}] end') |
| 90 | + echo "images=$images" >> "$GITHUB_OUTPUT" |
| 91 | + - uses: kool-dev/action/image-stage@6a6d04e8d1e1c66afc178e32c7d77d76169c7717 |
68 | 92 | if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-node' |
69 | 93 | with: |
| 94 | + canonical-repository: kool-dev/docker-node |
| 95 | + default-branch: master |
| 96 | + repository: kooldev/node |
| 97 | + arch: ${{ matrix.platform.arch }} |
| 98 | + group: ${{ matrix.version }} |
| 99 | + images: ${{ steps.images.outputs.images }} |
70 | 100 | username: ${{ secrets.DOCKER_USERNAME }} |
71 | 101 | password: ${{ secrets.DOCKER_PASSWORD }} |
72 | | - |
73 | | - - name: Push to DockerHub |
74 | | - if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-node' |
75 | | - run: | |
76 | | - docker push "kooldev/node:${{ matrix.version }}-$(arch)" |
77 | | - if [ "${{ matrix.version }}" = "24" ]; then |
78 | | - docker push "kooldev/node:24-nginx-$(arch)" |
79 | | - fi |
80 | | -
|
81 | | - amend: |
| 102 | + publish: |
| 103 | + needs: [checks, build] |
82 | 104 | if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-node' |
83 | | - needs: build |
84 | 105 | runs-on: ubuntu-24.04 |
85 | | - strategy: |
86 | | - matrix: |
87 | | - version: [22, 24, 24-nginx, 26] |
88 | | - |
89 | 106 | steps: |
90 | | - - uses: docker/login-action@v3 |
| 107 | + - uses: kool-dev/action/image-publish@6a6d04e8d1e1c66afc178e32c7d77d76169c7717 |
91 | 108 | with: |
| 109 | + canonical-repository: kool-dev/docker-node |
| 110 | + default-branch: master |
| 111 | + repository: kooldev/node |
| 112 | + tags: ${{ needs.checks.outputs.tags }} |
| 113 | + architecture-aliases: true |
92 | 114 | username: ${{ secrets.DOCKER_USERNAME }} |
93 | 115 | password: ${{ secrets.DOCKER_PASSWORD }} |
94 | | - |
95 | | - - run: | |
96 | | - docker manifest create kooldev/node:${{ matrix.version }} \ |
97 | | - --amend kooldev/node:${{ matrix.version }}-x86_64 \ |
98 | | - --amend kooldev/node:${{ matrix.version }}-aarch64 |
99 | | -
|
100 | | - docker manifest push kooldev/node:${{ matrix.version }} |
|
0 commit comments