Skip to content

Commit 191ed99

Browse files
committed
CI/Docker: split in two steps the build & publish
1 parent c98971f commit 191ed99

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

.github/workflows/docker.yaml

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,32 @@ jobs:
3737
3838
- name: Login to Docker Hub
3939
uses: docker/login-action@v3
40+
if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')) && github.event_name == 'push' }}
4041
with:
4142
username: ${{ secrets.DOCKERHUB_USERNAME }}
4243
password: ${{ secrets.DOCKERHUB_PASSWORD }}
4344

4445
- name: Set up Docker Buildx
4546
uses: docker/setup-buildx-action@v3
4647

47-
- name: Build and push by digest
48+
- name: Build Docker image
4849
id: build
4950
uses: docker/build-push-action@v6
5051
with:
5152
context: .
5253
platforms: ${{ matrix.arch.platform }}
5354
cache-from: type=gha
5455
cache-to: type=gha,mode=max
55-
# :warning:
56-
# Push only if:
57-
# - main
58-
# - develop
59-
# - a tag
60-
outputs: type=image,name=${{ env.REGISTRY_NODE_IMAGE }},push-by-digest=true,name-canonical=true,push=${{ github.ref_name == 'main' || github.ref_name == 'develop' || startsWith(github.ref, 'refs/tags/') }}
56+
outputs: type=image,name=${{ env.REGISTRY_NODE_IMAGE }},push-by-digest=true,name-canonical=true,push=false
57+
58+
- name: Push Docker image by digest
59+
if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')) && github.event_name == 'push' }}
60+
uses: docker/build-push-action@v6
61+
with:
62+
context: .
63+
platforms: ${{ matrix.arch.platform }}
64+
cache-from: type=gha
65+
outputs: type=image,name=${{ env.REGISTRY_NODE_IMAGE }},push-by-digest=true,name-canonical=true,push=true
6166

6267
- name: Export digest
6368
run: |
@@ -75,12 +80,7 @@ jobs:
7580

7681
merge-openmina-node-image:
7782
runs-on: ubuntu-latest
78-
# :warning:
79-
# Only if:
80-
# - main
81-
# - develop
82-
# - a tag
83-
if: github.ref_name == 'main' || github.ref_name == 'develop' || startsWith(github.ref, 'refs/tags/')
83+
if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')) && github.event_name == 'push' }}
8484
needs:
8585
- build-openmina-node-image
8686
steps:
@@ -147,14 +147,15 @@ jobs:
147147

148148
- name: Login to Docker Hub
149149
uses: docker/login-action@v3
150+
if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')) && github.event_name == 'push' }}
150151
with:
151152
username: ${{ secrets.DOCKERHUB_USERNAME }}
152153
password: ${{ secrets.DOCKERHUB_PASSWORD }}
153154

154155
- name: Set up Docker Buildx
155156
uses: docker/setup-buildx-action@v3
156157

157-
- name: Build and push by digest
158+
- name: Build Docker image
158159
id: build
159160
uses: docker/build-push-action@v6
160161
with:
@@ -164,11 +165,18 @@ jobs:
164165
BUILD_CONFIGURATION=${{ matrix.configuration.build_configuration }}
165166
cache-from: type=gha
166167
cache-to: type=gha,mode=max
167-
# Only if:
168-
# - main
169-
# - develop
170-
# - a tag
171-
outputs: type=image,name=${{ env.REGISTRY_FRONTEND_IMAGE }},push-by-digest=true,name-canonical=true,push=${{ github.ref_name == 'main' || github.ref_name == 'develop' || startsWith(github.ref, 'refs/tags/') }}
168+
outputs: type=image,name=${{ env.REGISTRY_FRONTEND_IMAGE }},push-by-digest=true,name-canonical=true,push=false
169+
170+
- name: Push Docker image by digest
171+
if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')) && github.event_name == 'push' }}
172+
uses: docker/build-push-action@v6
173+
with:
174+
context: ./frontend
175+
platforms: ${{ matrix.arch.platform }}
176+
build-args: |
177+
BUILD_CONFIGURATION=${{ matrix.configuration.build_configuration }}
178+
cache-from: type=gha
179+
outputs: type=image,name=${{ env.REGISTRY_FRONTEND_IMAGE }},push-by-digest=true,name-canonical=true,push=true
172180

173181
- name: Export digest
174182
run: |
@@ -190,7 +198,7 @@ jobs:
190198
configuration:
191199
- build_configuration: production
192200
runs-on: ubuntu-latest
193-
if: github.ref_name == 'main' || github.ref_name == 'develop' || startsWith(github.ref, 'refs/tags/')
201+
if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')) && github.event_name == 'push' }}
194202
needs:
195203
- build-openmina-frontend-image
196204
steps:

0 commit comments

Comments
 (0)