Skip to content

Commit 9eaec01

Browse files
committed
chore: push-image workflow
Signed-off-by: Yukai Huang <yukaihuangtw@gmail.com>
1 parent dd5bdcd commit 9eaec01

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

.github/workflows/push-image.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Build and push image
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
runtime:
9+
description: 'Runtime image'
10+
required: true
11+
default: 'hackmdio/runtime:16.20.2-58224661'
12+
buildpack:
13+
description: 'Buildpack image'
14+
required: true
15+
default: 'hackmdio/buildpack:16.20.2-58224661'
16+
17+
env:
18+
REGISTRY_IMAGE: hackmdio/hackmd
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
platform:
27+
- linux/amd64
28+
# - linux/arm64
29+
steps:
30+
-
31+
name: Prepare
32+
run: |
33+
platform=${{ matrix.platform }}
34+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
35+
-
36+
name: Checkout
37+
uses: actions/checkout@v4
38+
-
39+
name: Docker meta
40+
id: meta
41+
uses: docker/metadata-action@v5
42+
with:
43+
images: ${{ env.REGISTRY_IMAGE }}
44+
tags:
45+
type=match,pattern=\d.\d.\d
46+
type=sha
47+
-
48+
name: Set up QEMU
49+
uses: docker/setup-qemu-action@v3
50+
-
51+
name: Set up Docker Buildx
52+
uses: docker/setup-buildx-action@v3
53+
-
54+
name: Login to Docker Hub
55+
uses: docker/login-action@v3
56+
with:
57+
username: ${{ secrets.DOCKERHUB_USERNAME }}
58+
password: ${{ secrets.DOCKERHUB_TOKEN }}
59+
-
60+
name: Build and push by digest
61+
id: build
62+
uses: docker/build-push-action@v5
63+
with:
64+
context: .
65+
file: ./deployments/Dockerfile
66+
platforms: ${{ matrix.platform }}
67+
tags: ${{ steps.meta.outputs.tags }}
68+
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
69+
build-args: |
70+
RUNTIME=${{ github.event.inputs.runtime || 'hackmdio/runtime:16.20.2-58224661' }}
71+
BUILDPACK=${{ github.event.inputs.buildpack || 'hackmdio/buildpack:16.20.2-58224661' }}
72+
-
73+
name: Export digest
74+
run: |
75+
mkdir -p /tmp/digests
76+
digest="${{ steps.build.outputs.digest }}"
77+
touch "/tmp/digests/${digest#sha256:}"
78+
-
79+
name: Upload digest
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: digests-${{ env.PLATFORM_PAIR }}
83+
path: /tmp/digests/*
84+
if-no-files-found: error
85+
retention-days: 1
86+
87+
merge:
88+
runs-on: ubuntu-latest
89+
needs:
90+
- build
91+
steps:
92+
-
93+
name: Download digests
94+
uses: actions/download-artifact@v4
95+
with:
96+
path: /tmp/digests
97+
pattern: digests-*
98+
merge-multiple: true
99+
-
100+
name: Set up Docker Buildx
101+
uses: docker/setup-buildx-action@v3
102+
-
103+
name: Docker meta
104+
id: meta
105+
uses: docker/metadata-action@v5
106+
with:
107+
images: ${{ env.REGISTRY_IMAGE }}
108+
-
109+
name: Login to Docker Hub
110+
uses: docker/login-action@v3
111+
with:
112+
username: ${{ secrets.DOCKERHUB_USERNAME }}
113+
password: ${{ secrets.DOCKERHUB_TOKEN }}
114+
-
115+
name: Create manifest list and push
116+
working-directory: /tmp/digests
117+
run: |
118+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
119+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
120+
-
121+
name: Inspect image
122+
run: |
123+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)