|
7 | 7 | workflow_call: |
8 | 8 | workflow_dispatch: |
9 | 9 |
|
10 | | -env: |
11 | | - BUILD_SUFFIX: -build-${{ github.run_id }}_${{ github.run_attempt }} |
12 | | - DOCKER_METADATA_SET_OUTPUT_ENV: 'true' |
13 | 10 |
|
14 | 11 | jobs: |
15 | | - build: |
16 | | - runs-on: ${{ matrix.runner }} |
17 | | - outputs: |
18 | | - build-image-arm: ${{ steps.gen-output.outputs.image-arm64 }} |
19 | | - build-image-x64: ${{ steps.gen-output.outputs.image-x64 }} |
20 | | - strategy: |
21 | | - fail-fast: false |
22 | | - matrix: |
23 | | - include: |
24 | | - - platform: linux/amd64 |
25 | | - runner: ubuntu-24.04 |
26 | | - - platform: linux/arm64 |
27 | | - runner: ubuntu-24.04-arm |
28 | | - steps: |
29 | | - - name: Checkout code |
30 | | - uses: actions/checkout@v4 |
31 | | - |
32 | | - - name: Set up Docker Buildx |
33 | | - uses: docker/setup-buildx-action@v3 |
34 | | - |
35 | | - - name: Login to GitHub Container Registry |
36 | | - uses: docker/login-action@v3 |
37 | | - with: |
38 | | - registry: ghcr.io |
39 | | - username: ${{ github.actor }} |
40 | | - password: ${{ secrets.GITHUB_TOKEN }} |
41 | | - |
42 | | - - id: build-meta |
43 | | - name: Docker meta |
44 | | - uses: docker/metadata-action@v5 |
45 | | - with: |
46 | | - images: ghcr.io/${{ github.repository }} |
47 | | - tags: type=sha,suffix=${{ env.BUILD_SUFFIX }} |
48 | | - |
49 | | - # Build cache is shared among all builds of the same architecture |
50 | | - - id: cache-meta |
51 | | - name: Docker meta |
52 | | - uses: docker/metadata-action@v5 |
53 | | - with: |
54 | | - images: ghcr.io/${{ github.repository }} |
55 | | - tags: type=raw,value=buildcache-${{ runner.arch }} |
56 | | - |
57 | | - - id: get-registry |
58 | | - name: Get the sanitized registry name |
59 | | - run: | |
60 | | - echo "registry=$(echo '${{ steps.build-meta.outputs.tags }}' | cut -f1 -d:)" | tee -a "$GITHUB_OUTPUT" |
61 | | -
|
62 | | - - id: set_build_url |
63 | | - name: Set BUILD_URL |
64 | | - run: | |
65 | | - echo "build_url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" | tee -a "$GITHUB_OUTPUT" |
66 | | -
|
67 | | - - id: build |
68 | | - name: Build/push the arch-specific image |
69 | | - uses: docker/build-push-action@v6 |
70 | | - with: |
71 | | - platforms: ${{ matrix.platform }} |
72 | | - build-args: | |
73 | | - BUILD_TIMESTAMP=${{ github.event.repository.updated_at }} |
74 | | - BUILD_URL=${{ steps.set_build_url.outputs.build_url }} |
75 | | - GIT_REF_NAME=${{ github.ref_name }} |
76 | | - GIT_SHA=${{ github.sha }} |
77 | | - GIT_REPOSITORY_URL=${{ github.repositoryUrl }} |
78 | | - cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }} |
79 | | - cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max |
80 | | - labels: ${{ steps.build-meta.outputs.labels }} |
81 | | - provenance: mode=max |
82 | | - sbom: true |
83 | | - tags: ${{ steps.get-registry.outputs.registry }} |
84 | | - outputs: type=image,push-by-digest=true,push=true |
85 | | - |
86 | | - - id: gen-output |
87 | | - name: Write arch-specific image digest to outputs |
88 | | - run: | |
89 | | - echo "image-${RUNNER_ARCH,,}=${{ steps.get-registry.outputs.registry }}@${{ steps.build.outputs.digest }}" | tee -a "$GITHUB_OUTPUT" |
90 | | -
|
91 | | - merge: |
92 | | - runs-on: ubuntu-latest |
93 | | - needs: |
94 | | - - build |
95 | | - env: |
96 | | - DOCKER_APP_IMAGE_ARM64: ${{ needs.build.outputs.build-image-arm }} |
97 | | - DOCKER_APP_IMAGE_X64: ${{ needs.build.outputs.build-image-x64 }} |
98 | | - outputs: |
99 | | - build-image: ${{ steps.meta.outputs.tags }} |
100 | | - build-image-arm: ${{ needs.build.outputs.build-image-arm }} |
101 | | - build-image-x64: ${{ needs.build.outputs.build-image-x64 }} |
102 | | - steps: |
103 | | - - name: Checkout code |
104 | | - uses: actions/checkout@v4 |
105 | | - |
106 | | - - name: Set up Docker Buildx |
107 | | - uses: docker/setup-buildx-action@v3 |
108 | | - |
109 | | - - name: Login to GitHub Container Registry |
110 | | - uses: docker/login-action@v3 |
111 | | - with: |
112 | | - registry: ghcr.io |
113 | | - username: ${{ github.actor }} |
114 | | - password: ${{ secrets.GITHUB_TOKEN }} |
115 | | - |
116 | | - - name: Docker meta |
117 | | - id: meta |
118 | | - uses: docker/metadata-action@v5 |
119 | | - with: |
120 | | - images: ghcr.io/${{ github.repository }} |
121 | | - tags: | |
122 | | - type=sha,suffix=-build-${{ github.run_id }}_${{ github.run_attempt }} |
123 | | -
|
124 | | - - name: Push the multi-platform image |
125 | | - run: | |
126 | | - docker buildx imagetools create \ |
127 | | - --tag "$DOCKER_METADATA_OUTPUT_TAGS" \ |
128 | | - "$DOCKER_APP_IMAGE_ARM64" "$DOCKER_APP_IMAGE_X64" |
| 12 | + docker-build: |
| 13 | + uses: BerkeleyLibrary/.github/.github/workflows/docker-build.yml@v2.0.0 |
| 14 | + with: |
| 15 | + image: ghcr.io/${{ github.repository }} |
| 16 | + secrets: inherit |
129 | 17 |
|
130 | 18 | test: |
131 | 19 | runs-on: ubuntu-latest |
132 | 20 | needs: |
133 | | - - merge |
134 | | - env: |
135 | | - COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml |
136 | | - DOCKER_APP_IMAGE: ${{ needs.merge.outputs.build-image }} |
| 21 | + - docker-build |
137 | 22 | steps: |
138 | 23 | - name: Checkout code |
139 | | - uses: actions/checkout@v4 |
| 24 | + uses: actions/checkout@v6 |
140 | 25 |
|
141 | 26 | - name: Set up Docker Compose |
142 | | - uses: docker/setup-compose-action@v1 |
| 27 | + uses: docker/setup-compose-action@v2 |
143 | 28 |
|
144 | 29 | - name: Login to GitHub Container Registry |
145 | | - uses: docker/login-action@v3 |
| 30 | + uses: docker/login-action@v4 |
146 | 31 | with: |
147 | 32 | registry: ghcr.io |
148 | 33 | username: ${{ github.actor }} |
@@ -179,39 +64,12 @@ jobs: |
179 | 64 | if-no-files-found: error |
180 | 65 |
|
181 | 66 | push: |
182 | | - runs-on: ubuntu-latest |
183 | 67 | needs: |
184 | | - - merge |
| 68 | + - docker-build |
185 | 69 | - test |
186 | | - env: |
187 | | - DOCKER_APP_IMAGE: ${{ needs.merge.outputs.build-image }} |
188 | | - DOCKER_APP_IMAGE_ARM64: ${{ needs.merge.outputs.build-image-arm }} |
189 | | - DOCKER_APP_IMAGE_X64: ${{ needs.merge.outputs.build-image-x64 }} |
190 | | - steps: |
191 | | - - name: Checkout code |
192 | | - uses: actions/checkout@v4 |
193 | | - |
194 | | - - name: Set up Docker Buildx |
195 | | - uses: docker/setup-buildx-action@v3 |
196 | | - |
197 | | - - name: Login to GitHub Container Registry |
198 | | - uses: docker/login-action@v3 |
199 | | - with: |
200 | | - registry: ghcr.io |
201 | | - username: ${{ github.actor }} |
202 | | - password: ${{ secrets.GITHUB_TOKEN }} |
203 | | - |
204 | | - - name: Produce permanent image tags |
205 | | - id: branch-meta |
206 | | - uses: docker/metadata-action@v5 |
207 | | - with: |
208 | | - images: ghcr.io/${{ github.repository }} |
209 | | - tags: | |
210 | | - type=sha |
211 | | - type=ref,event=branch |
212 | | - type=raw,value=latest,enable={{is_default_branch}} |
213 | | -
|
214 | | - - name: Retag and push the image |
215 | | - run: | |
216 | | - docker buildx imagetools create \ |
217 | | - $(jq -cr '.tags | map("--tag " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") $DOCKER_APP_IMAGE_ARM64 $DOCKER_APP_IMAGE_X64 |
| 70 | + uses: BerkeleyLibrary/.github/.github/workflows/docker-push.yml@v2.0.0 |
| 71 | + with: |
| 72 | + image: ghcr.io/${{ github.repository }} |
| 73 | + build-image-arm64: ${{ needs.docker-build.outputs.image-arm64 }} |
| 74 | + build-image-x64: ${{ needs.docker-build.outputs.image-x64 }} |
| 75 | + secrets: inherit |
0 commit comments