Skip to content

Commit 43688d0

Browse files
committed
rework ci-cd
1 parent f90d795 commit 43688d0

File tree

1 file changed

+43
-40
lines changed

1 file changed

+43
-40
lines changed

.github/workflows/docker.yml

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,56 +25,28 @@ on:
2525
types: [ published ]
2626

2727
jobs:
28-
build:
29-
if: github.event_name != 'release'
30-
runs-on: ubuntu-latest
31-
steps:
32-
- &checkout-step
33-
name: Check out repository
34-
uses: actions/checkout@v4
35-
36-
- &setup-qemu-step
37-
name: Set up QEMU
38-
uses: docker/setup-qemu-action@v3
39-
40-
- &login-step
41-
name: Login to Docker Hub
42-
uses: docker/login-action@v3
43-
with:
44-
username: ${{ secrets.DOCKERHUB_USERNAME }}
45-
password: ${{ secrets.DOCKERHUB_TOKEN }}
46-
47-
- &setup-buildx-step
48-
name: Set up Docker Buildx
49-
uses: docker/setup-buildx-action@v3
50-
51-
- name: Build and push
52-
uses: docker/build-push-action@v6
53-
with:
54-
context: .
55-
push: true
56-
platforms: linux/amd64
57-
cache-from: type=gha
58-
cache-to: type=gha,mode=max
59-
tags: |
60-
${{ env.IMAGE_NAME }}:latest-${{ github.ref_name }}
61-
6228
build-matrix:
63-
if: github.event_name == 'release'
29+
if: github.event_name != 'pull_request'
30+
outputs:
31+
safe_ref: ${{ steps.ref.outputs.safe_ref }}
6432
runs-on: ${{ matrix.runner }}
6533
strategy:
6634
matrix:
6735
include:
6836
- arch: amd64
6937
platform: linux/amd64
70-
runner: ubuntu-latest
38+
runner: ubuntu-22.04
7139
- arch: arm64
7240
platform: linux/arm64
73-
runner: ubuntu-latest-arm64
41+
runner: ubuntu-22.04-arm64
7442
steps:
7543
- name: Check out repository
7644
uses: actions/checkout@v4
7745

46+
- name: Prepare ref name
47+
id: ref
48+
run: echo "safe_ref=${GITHUB_REF_NAME//\//-}" >> "$GITHUB_OUTPUT"
49+
7850
- name: Login to Docker Hub
7951
uses: docker/login-action@v3
8052
with:
@@ -84,7 +56,8 @@ jobs:
8456
- name: Set up Docker Buildx
8557
uses: docker/setup-buildx-action@v3
8658

87-
- name: Build and push architecture-specific image
59+
- name: Build and push branch images
60+
if: github.event_name == 'push'
8861
uses: docker/build-push-action@v6
8962
with:
9063
context: .
@@ -93,10 +66,40 @@ jobs:
9366
cache-from: type=gha
9467
cache-to: type=gha,mode=max
9568
tags: |
96-
${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }}-${{ matrix.arch }}
69+
${{ env.IMAGE_NAME }}:latest-${{ steps.ref.outputs.safe_ref }}-${{ matrix.arch }}
70+
71+
- name: Build and push release images
72+
if: github.event_name == 'release'
73+
uses: docker/build-push-action@v6
74+
with:
75+
context: .
76+
push: true
77+
platforms: ${{ matrix.platform }}
78+
cache-from: type=gha
79+
cache-to: type=gha,mode=max
80+
tags: |
81+
${{ env.IMAGE_NAME }}:${{ steps.ref.outputs.safe_ref }}-${{ matrix.arch }}
9782
${{ env.IMAGE_NAME }}:latest-${{ matrix.arch }}
9883
99-
create-manifest:
84+
create-branch-manifest:
85+
if: github.event_name == 'push'
86+
needs: build-matrix
87+
runs-on: ubuntu-latest
88+
steps:
89+
- name: Login to Docker Hub
90+
uses: docker/login-action@v3
91+
with:
92+
username: ${{ secrets.DOCKERHUB_USERNAME }}
93+
password: ${{ secrets.DOCKERHUB_TOKEN }}
94+
95+
- name: Create and push multi-arch manifest for branch tip
96+
run: |
97+
docker manifest create ${{ env.IMAGE_NAME }}:latest-${{ needs.build-matrix.outputs.safe_ref }} \
98+
--amend ${{ env.IMAGE_NAME }}:latest-${{ needs.build-matrix.outputs.safe_ref }}-amd64 \
99+
--amend ${{ env.IMAGE_NAME }}:latest-${{ needs.build-matrix.outputs.safe_ref }}-arm64
100+
docker manifest push ${{ env.IMAGE_NAME }}:latest-${{ needs.build-matrix.outputs.safe_ref }}
101+
102+
create-release-manifest:
100103
if: github.event_name == 'release'
101104
needs: build-matrix
102105
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)