|
1 | | -name: Build / Test / Push |
| 1 | +name: Build image |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - branches: |
6 | | - - '**' |
7 | | - workflow_dispatch: |
8 | | - |
9 | | -env: |
10 | | - BUILD_SUFFIX: -build-${{ github.run_id }}_${{ github.run_attempt }} |
11 | | - DOCKER_METADATA_SET_OUTPUT_ENV: 'true' |
| 4 | + workflow_call: |
| 5 | + outputs: |
| 6 | + image: |
| 7 | + description: ID of the image created by the workflow run |
| 8 | + value: ${{ jobs.merge.outputs.image }} |
12 | 9 |
|
13 | 10 | jobs: |
14 | 11 | build: |
15 | 12 | runs-on: ${{ matrix.runner }} |
16 | 13 | outputs: |
17 | | - build-image-arm: ${{ steps.gen-output.outputs.image-arm64 }} |
| 14 | + image-digest-arm: ${{ steps.gen-output.outputs.image-arm64 }} |
18 | 15 | build-image-x64: ${{ steps.gen-output.outputs.image-x64 }} |
| 16 | + build-tag: ${{ steps.build-meta.outputs.tags }} |
19 | 17 | strategy: |
20 | 18 | fail-fast: false |
21 | 19 | matrix: |
|
41 | 39 | uses: docker/metadata-action@v5 |
42 | 40 | with: |
43 | 41 | images: ghcr.io/${{ github.repository }} |
44 | | - tags: type=sha,suffix=${{ env.BUILD_SUFFIX }} |
| 42 | + tags: type=sha,suffix=-build-${{ github.run_id }}_ ${{ github.run_attempt }} |
45 | 43 |
|
46 | 44 | # Build cache is shared among all builds of the same architecture |
47 | 45 | - id: cache-meta |
@@ -71,17 +69,17 @@ jobs: |
71 | 69 | - id: gen-output |
72 | 70 | name: Write arch-specific image digest to outputs |
73 | 71 | run: | |
74 | | - echo "image-${RUNNER_ARCH,,}=${{ steps.get-registry.outputs.registry }}@${{ steps.build.outputs.digest }}" | tee -a "$GITHUB_OUTPUT" |
| 72 | + echo "image-digest-${RUNNER_ARCH,,}=${{ steps.get-registry.outputs.registry }}@${{ steps.build.outputs.digest }}" | tee -a "$GITHUB_OUTPUT" |
75 | 73 |
|
76 | 74 | merge: |
| 75 | + needs: build |
77 | 76 | runs-on: ubuntu-24.04 |
78 | | - needs: |
79 | | - - build |
80 | 77 | env: |
81 | | - DOCKER_APP_IMAGE_ARM64: ${{ needs.build.outputs.build-image-arm }} |
82 | | - DOCKER_APP_IMAGE_X64: ${{ needs.build.outputs.build-image-x64 }} |
| 78 | + DOCKER_APP_IMAGE: ${{ needs.build.outputs.build-tag }} |
| 79 | + DOCKER_APP_IMAGE_DIGEST_ARM64: ${{ needs.build.outputs.image-digest-arm }} |
| 80 | + DOCKER_APP_IMAGE_DIGEST_X64: ${{ needs.build.outputs.build-image-x64 }} |
83 | 81 | outputs: |
84 | | - build-image: ${{ steps.meta.outputs.tags }} |
| 82 | + image: ${{ needs.build.outputs.build-tag }} |
85 | 83 | steps: |
86 | 84 | - name: Checkout code |
87 | 85 | uses: actions/checkout@v4 |
|
96 | 94 | username: ${{ github.actor }} |
97 | 95 | password: ${{ secrets.GITHUB_TOKEN }} |
98 | 96 |
|
99 | | - - name: Docker meta |
100 | | - id: meta |
101 | | - uses: docker/metadata-action@v5 |
102 | | - with: |
103 | | - images: ghcr.io/${{ github.repository }} |
104 | | - tags: | |
105 | | - type=sha,suffix=-build-${{ github.run_id }}_${{ github.run_attempt }} |
106 | | -
|
107 | 97 | - name: Push the multi-platform image |
108 | 98 | run: | |
109 | 99 | docker buildx imagetools create \ |
110 | | - --tag "$DOCKER_METADATA_OUTPUT_TAGS" \ |
111 | | - "$DOCKER_APP_IMAGE_ARM64" "$DOCKER_APP_IMAGE_X64" |
112 | | -
|
113 | | - test: |
114 | | - runs-on: ubuntu-24.04 |
115 | | - needs: |
116 | | - - merge |
117 | | - env: |
118 | | - COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml |
119 | | - DOCKER_APP_IMAGE: ${{ needs.merge.outputs.build-image }} |
120 | | - steps: |
121 | | - - name: Checkout code |
122 | | - uses: actions/checkout@v4 |
123 | | - |
124 | | - - name: Set up Docker Compose |
125 | | - uses: docker/setup-compose-action@v1 |
126 | | - |
127 | | - - name: Login to GitHub Container Registry |
128 | | - uses: docker/login-action@v3 |
129 | | - with: |
130 | | - registry: ghcr.io |
131 | | - username: ${{ github.actor }} |
132 | | - password: ${{ secrets.GITHUB_TOKEN }} |
133 | | - |
134 | | - - name: Run the test script |
135 | | - run: | |
136 | | - docker compose run --rm --user root app chown -R avplayer:avplayer artifacts |
137 | | - docker compose up --detach --wait |
138 | | - docker compose exec app bin/test |
139 | | -
|
140 | | - push: |
141 | | - runs-on: ubuntu-24.04 |
142 | | - needs: |
143 | | - - merge |
144 | | - - test |
145 | | - env: |
146 | | - DOCKER_APP_IMAGE: ${{ needs.merge.outputs.build-image }} |
147 | | - steps: |
148 | | - - name: Checkout code |
149 | | - uses: actions/checkout@v4 |
150 | | - |
151 | | - - name: Login to GitHub Container Registry |
152 | | - uses: docker/login-action@v3 |
153 | | - with: |
154 | | - registry: ghcr.io |
155 | | - username: ${{ github.actor }} |
156 | | - password: ${{ secrets.GITHUB_TOKEN }} |
157 | | - |
158 | | - - name: Produce permanent image tags |
159 | | - id: branch-meta |
160 | | - uses: docker/metadata-action@v5 |
161 | | - with: |
162 | | - images: ghcr.io/${{ github.repository }} |
163 | | - tags: | |
164 | | - type=sha |
165 | | - type=ref,event=branch |
166 | | - type=raw,value=latest,enable={{is_default_branch}} |
167 | | -
|
168 | | - - name: Retag and push the image |
169 | | - run: | |
170 | | - docker pull "$DOCKER_APP_IMAGE" |
171 | | - echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr ' ' '\n' | xargs -n1 docker tag "$DOCKER_APP_IMAGE" |
172 | | - docker push --all-tags "$(echo "$DOCKER_APP_IMAGE" | cut -f1 -d:)" |
| 100 | + --tag "$DOCKER_APP_IMAGE" \ |
| 101 | + "$DOCKER_APP_IMAGE_DIGEST_ARM64" "$DOCKER_APP_IMAGE_DIGEST_X64" |
0 commit comments