Skip to content

Commit c9a986a

Browse files
committed
feat: implement new Docker publish workflow and remove old publish configuration
1 parent a9ee865 commit c9a986a

2 files changed

Lines changed: 112 additions & 80 deletions

File tree

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Build & Publish Docker Image
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags: ["v*.*.*"]
7+
8+
permissions:
9+
contents: read
10+
11+
env:
12+
IMAGE_NAME: evoapicloud/evo-bot-runtime
13+
14+
jobs:
15+
build:
16+
name: Build ${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
17+
runs-on: ${{ matrix.runner }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- platform: linux/amd64
23+
runner: ubuntu-latest
24+
- platform: linux/arm64
25+
runner: ubuntu-24.04-arm
26+
steps:
27+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
29+
- uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
30+
31+
- uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
32+
with:
33+
username: ${{ secrets.DOCKERHUB_USERNAME }}
34+
password: ${{ secrets.DOCKERHUB_TOKEN }}
35+
36+
- name: Build and push by digest
37+
id: build
38+
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
39+
with:
40+
context: .
41+
file: ./Dockerfile
42+
platforms: ${{ matrix.platform }}
43+
push: true
44+
provenance: mode=max
45+
sbom: true
46+
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true
47+
cache-from: type=gha,scope=${{ matrix.platform }}
48+
cache-to: type=gha,scope=${{ matrix.platform }},mode=max
49+
50+
- name: Export digest
51+
run: |
52+
mkdir -p /tmp/digests
53+
digest="${{ steps.build.outputs.digest }}"
54+
touch "/tmp/digests/${digest#sha256:}"
55+
56+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
57+
with:
58+
name: digest-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
59+
path: /tmp/digests/*
60+
retention-days: 1
61+
62+
merge:
63+
name: Merge Manifests & Tag
64+
needs: build
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
68+
with:
69+
pattern: digest-*
70+
path: /tmp/digests
71+
merge-multiple: true
72+
73+
- uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
74+
75+
- uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
76+
with:
77+
username: ${{ secrets.DOCKERHUB_USERNAME }}
78+
password: ${{ secrets.DOCKERHUB_TOKEN }}
79+
80+
- name: Resolve tags
81+
id: tags
82+
env:
83+
GH_REF: ${{ github.ref }}
84+
GH_REF_NAME: ${{ github.ref_name }}
85+
GH_SHA: ${{ github.sha }}
86+
run: |
87+
IMAGE="${{ env.IMAGE_NAME }}"
88+
SHA_SHORT="${GH_SHA:0:7}"
89+
TAGS=""
90+
91+
if [[ "${GH_REF}" == refs/tags/v* ]]; then
92+
VERSION="${GH_REF_NAME#v}"
93+
TAGS="${IMAGE}:${VERSION},${IMAGE}:latest"
94+
elif [[ "${GH_REF}" == refs/heads/main ]]; then
95+
TAGS="${IMAGE}:latest,${IMAGE}:main-${SHA_SHORT}"
96+
fi
97+
98+
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
99+
100+
- name: Create and push manifest
101+
working-directory: /tmp/digests
102+
env:
103+
MERGE_TAGS: ${{ steps.tags.outputs.tags }}
104+
run: |
105+
IFS=',' read -ra TAG_ARRAY <<< "${MERGE_TAGS}"
106+
TAG_ARGS=""
107+
for tag in "${TAG_ARRAY[@]}"; do
108+
TAG_ARGS="${TAG_ARGS} -t ${tag}"
109+
done
110+
111+
docker buildx imagetools create ${TAG_ARGS} \
112+
$(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *)

.github/workflows/publish.yml

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

0 commit comments

Comments
 (0)