Skip to content

Commit 7657783

Browse files
authored
feat(workflows/docker-publish): improve and push to ghcr
1 parent 18ae31a commit 7657783

File tree

2 files changed

+138
-81
lines changed

2 files changed

+138
-81
lines changed

.github/workflows/build-images-and-deploy.yml

Lines changed: 0 additions & 81 deletions
This file was deleted.

.github/workflows/docker-publish.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: Docker image build
2+
3+
concurrency:
4+
group: ci-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
push:
9+
branches: [main, develop]
10+
# Publish semver tags as releases.
11+
tags: ["v*.*.*"]
12+
pull_request:
13+
branches: [develop]
14+
15+
env:
16+
# Use docker.io for Docker Hub if empty
17+
REGISTRY: ghcr.io
18+
# github.repository as <account>/<repo>
19+
IMAGE_NAME: ${{ github.repository }}
20+
21+
jobs:
22+
build:
23+
strategy:
24+
fail-fast: true
25+
26+
matrix:
27+
type:
28+
- linux-amd64
29+
- linux-arm64
30+
include:
31+
- type: linux-amd64
32+
docker-platform: linux/amd64
33+
runner: ubuntu-22.04
34+
- type: linux-arm64
35+
docker-platform: linux/arm64
36+
runner: arc-runner-aylamusica
37+
38+
runs-on: ${{ matrix.runner }}
39+
40+
permissions:
41+
contents: read
42+
packages: write
43+
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v4
47+
48+
- name: Login in registry ${{ env.REGISTRY }}
49+
if: github.event_name != 'pull_request'
50+
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
51+
with:
52+
registry: ${{ env.REGISTRY }}
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Extract Docker metadata
57+
id: meta
58+
uses: docker/metadata-action@a64d0487d7069df33b279515d35d60fa80e2ea62
59+
with:
60+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
61+
tags: |
62+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
63+
type=raw,value=unstable,enable=${{ github.ref == format('refs/heads/{0}', 'develop') }}
64+
65+
- name: Setup Docker Buildx
66+
uses: docker/setup-buildx-action@2ad185228a349d19414702819e06df9fa4314287
67+
68+
- name: Build and push by digest
69+
id: build
70+
uses: docker/build-push-action@090ca155fc9b214cbcac536c450455a0e96f52c6
71+
with:
72+
context: .
73+
platforms: ${{ matrix.docker-platform }}
74+
labels: ${{ steps.meta.outputs.labels }}
75+
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
76+
77+
- name: Export digest
78+
run: |
79+
mkdir -p /tmp/digests
80+
digest="${{ steps.build.outputs.digest }}"
81+
touch "/tmp/digests/${digest#sha256:}"
82+
83+
- name: Upload digest
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: ${{ matrix.type }}-digests
87+
path: /tmp/digests/*
88+
if-no-files-found: error
89+
retention-days: 1
90+
merge:
91+
runs-on: ubuntu-latest
92+
93+
if: github.event_name != 'pull_request'
94+
95+
permissions:
96+
contents: read
97+
packages: write
98+
99+
needs:
100+
- build
101+
102+
steps:
103+
- name: Create digests directory
104+
run: mkdir -p /tmp/digests
105+
106+
- name: Download digests
107+
uses: actions/download-artifact@v4
108+
with:
109+
path: /tmp/digests
110+
111+
- name: Set up Docker Buildx
112+
uses: docker/setup-buildx-action@v3
113+
114+
- name: Extract Docker metadata
115+
id: meta
116+
uses: docker/metadata-action@a64d0487d7069df33b279515d35d60fa80e2ea62
117+
with:
118+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
119+
tags: |
120+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
121+
type=raw,value=unstable,enable=${{ github.ref == format('refs/heads/{0}', 'develop') }}
122+
123+
- name: Login in registry ${{ env.REGISTRY }}
124+
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
125+
with:
126+
registry: ${{ env.REGISTRY }}
127+
username: ${{ github.actor }}
128+
password: ${{ secrets.GITHUB_TOKEN }}
129+
130+
- name: Create manifest list and push
131+
working-directory: /tmp/digests
132+
run: |
133+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
134+
$(find . -type f -printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%f ')
135+
136+
- name: Inspect image
137+
run: |
138+
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)