Skip to content

Commit 973fba1

Browse files
add github action auto build image
1 parent b52a9bf commit 973fba1

File tree

2 files changed

+116
-1
lines changed

2 files changed

+116
-1
lines changed

.github/workflows/build.yaml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# This workflow builds and pushes a multi-arch image to Quay.io
2+
# Adapted from actions-arm64-native-example by @gartnera
3+
# ref: https://github.com/gartnera/actions-arm64-native-example/blob/main/.github/workflows/build.yml
4+
5+
name: build
6+
7+
on:
8+
push:
9+
pull_request:
10+
11+
env:
12+
QUAY_REPO: quay.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
13+
14+
jobs:
15+
build:
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- platform: linux/amd64
21+
runner: ubuntu-22.04
22+
- platform: linux/arm64
23+
runner: ubuntu-22.04-arm
24+
runs-on: ${{ matrix.runner || 'ubuntu-22.04' }}
25+
steps:
26+
- name: Prepare
27+
run: |
28+
platform=${{ matrix.platform }}
29+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
30+
31+
- name: Docker meta
32+
id: meta
33+
uses: docker/metadata-action@v5
34+
with:
35+
images: |
36+
${{ env.QUAY_REPO }}
37+
38+
- name: Login to Quay.io
39+
uses: docker/login-action@v3
40+
with:
41+
registry: quay.io
42+
username: ${{ secrets.QUAY_USERNAME }}
43+
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
44+
45+
- name: Set up QEMU
46+
uses: docker/setup-qemu-action@v3
47+
48+
- name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@v3
50+
51+
- name: Build and push by digest
52+
id: build
53+
uses: docker/build-push-action@v6
54+
with:
55+
platforms: ${{ matrix.platform }}
56+
labels: ${{ steps.meta.outputs.labels }}
57+
outputs: type=image,name=${{ env.QUAY_REPO }},push-by-digest=true,name-canonical=true,push=true
58+
59+
- name: Export digest
60+
run: |
61+
mkdir -p ${{ runner.temp }}/digests
62+
digest="${{ steps.build.outputs.digest }}"
63+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
64+
65+
- name: Upload digest
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: digests-${{ env.PLATFORM_PAIR }}
69+
path: ${{ runner.temp }}/digests/*
70+
if-no-files-found: error
71+
retention-days: 1
72+
73+
merge:
74+
runs-on: ubuntu-latest
75+
needs:
76+
- build
77+
steps:
78+
- name: Download digests
79+
uses: actions/download-artifact@v4
80+
with:
81+
path: ${{ runner.temp }}/digests
82+
pattern: digests-*
83+
merge-multiple: true
84+
85+
- name: Login to Quay.io
86+
uses: docker/login-action@v3
87+
with:
88+
registry: quay.io
89+
username: ${{ secrets.QUAY_USERNAME }}
90+
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
91+
92+
- name: Set up Docker Buildx
93+
uses: docker/setup-buildx-action@v3
94+
95+
- name: Docker meta
96+
id: meta
97+
uses: docker/metadata-action@v5
98+
with:
99+
images: |
100+
${{ env.QUAY_REPO }}
101+
tags: |
102+
type=ref,event=branch
103+
type=ref,event=pr
104+
type=semver,pattern={{version}}
105+
type=semver,pattern={{major}}.{{minor}}
106+
107+
- name: Create manifest list and push
108+
working-directory: ${{ runner.temp }}/digests
109+
run: |
110+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
111+
$(printf '${{ env.QUAY_REPO }}@sha256:%s ' *)
112+
113+
- name: Inspect image
114+
run: |
115+
docker buildx imagetools inspect ${{ env.QUAY_REPO }}:${{ steps.meta.outputs.version }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use the official Golang image as the base image
2-
FROM golang:1.23-alpine
2+
FROM golang:1.24.2-alpine
33

44
# Set the Current Working Directory inside the container
55
WORKDIR /app

0 commit comments

Comments
 (0)