Skip to content

Commit fad9081

Browse files
committed
add build CI
1 parent db2fa3a commit fad9081

1 file changed

Lines changed: 127 additions & 0 deletions

File tree

.github/workflows/build.yaml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: build
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: '30 9 * * 1' # runs workflow every Monday at 9:30 UTC.
6+
7+
jobs:
8+
build:
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
platform:
13+
- linux/amd64
14+
- linux/arm64
15+
runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-24.04' || matrix.platform == 'linux/arm64' && 'ubuntu-24.04-arm' }}
16+
name: ${{ matrix.platform }} build
17+
outputs:
18+
tag: ${{ steps.envvars.outputs.tag }}
19+
steps:
20+
- name: checkout
21+
uses: actions/checkout@v5.0.0
22+
23+
- name: Prepare env
24+
id: envvars
25+
run: |
26+
platform=${{ matrix.platform }}
27+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
28+
TAG="$(date +'%Y-%m-%d')"
29+
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
30+
31+
- name: Metadata
32+
id: meta
33+
uses: docker/metadata-action@v5.8.0
34+
with:
35+
images: ghcr.io/${{ github.repository }}
36+
37+
- name: Authenticate with GHCR
38+
id: auth
39+
uses: docker/login-action@v3.5.0
40+
with:
41+
registry: ghcr.io
42+
username: ${{github.actor}}
43+
password: ${{secrets.BUILD_TOKEN}}
44+
45+
- name: Set up Docker Buildx
46+
id: buildx
47+
uses: docker/setup-buildx-action@v3.11.1
48+
49+
- name: Build and push by digest
50+
id: build
51+
uses: docker/build-push-action@v6.18.0
52+
with:
53+
platforms: ${{ matrix.platform }}
54+
labels: ${{ steps.meta.outputs.labels }}
55+
tags: ghcr.io/${{ github.repository }}
56+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
57+
58+
- name: Export digest
59+
run: |
60+
mkdir -p ${{ runner.temp }}/digests
61+
digest="${{ steps.build.outputs.digest }}"
62+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
63+
64+
- name: Upload digest
65+
uses: actions/upload-artifact@v4.6.2
66+
with:
67+
name: digests-${{ env.PLATFORM_PAIR }}
68+
path: ${{ runner.temp }}/digests/*
69+
if-no-files-found: error
70+
retention-days: 1
71+
72+
merge:
73+
runs-on: ubuntu-24.04
74+
needs:
75+
- build
76+
steps:
77+
- name: Download digests
78+
uses: actions/download-artifact@v5.0.0
79+
with:
80+
path: ${{ runner.temp }}/digests
81+
pattern: digests-*
82+
merge-multiple: true
83+
84+
- name: Authenticate with GHCR
85+
id: auth
86+
uses: docker/login-action@v3.5.0
87+
with:
88+
registry: ghcr.io
89+
username: ${{github.actor}}
90+
password: ${{secrets.BUILD_TOKEN}}
91+
92+
- name: Set up Docker Buildx
93+
id: buildx
94+
uses: docker/setup-buildx-action@v3.11.1
95+
96+
- name: Metadata
97+
id: meta
98+
uses: docker/metadata-action@v5.8.0
99+
with:
100+
images: ghcr.io/${{ github.repository }}
101+
tags: |
102+
latest
103+
${{ needs.build.outputs.tag }}
104+
105+
- name: Create manifest list and push
106+
id: annotate
107+
continue-on-error: true
108+
working-directory: ${{ runner.temp }}/digests
109+
run: |
110+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
111+
--annotation='index:org.opencontainers.image.description=${{ github.event.repository.description }}' \
112+
--annotation='index:org.opencontainers.image.licenses=MIT' \
113+
--annotation='index:org.opencontainers.image.created=${{ steps.timestamp.outputs.timestamp }}' \
114+
--annotation='index:org.opencontainers.image.url=${{ github.event.repository.url }}' \
115+
--annotation='index:org.opencontainers.image.source=${{ github.event.repository.url }}' \
116+
$(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *)
117+
118+
- name: Create manifest list and push without annotations
119+
if: steps.annotate.outcome == 'failure'
120+
working-directory: ${{ runner.temp }}/digests
121+
run: |
122+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
123+
$(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *)
124+
125+
- name: Inspect image
126+
run: |
127+
docker buildx imagetools inspect ghcr.io/${{ github.repository }}:${{ needs.build.outputs.tag }}

0 commit comments

Comments
 (0)