Skip to content

Commit 8f12347

Browse files
committed
chore: Modify GitHub Actions workflow
1 parent 5636ae0 commit 8f12347

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed

.github/workflows/container.yml

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
name: Build and Release
1+
name: Build and Release Container
22
on:
3+
release:
4+
types: [released]
35
push:
46
branches:
57
- '*'
6-
pull_request:
7-
branches:
8-
- 'release-*'
9-
types:
10-
# action should run when the pull request is closed
11-
# (regardless of whether it was merged or just closed)
12-
- closed
13-
# Make sure the action runs every time new commits are
14-
# pushed to the pull request's branch
15-
- synchronize
168

179
env:
1810
REGISTRY: ghcr.io
@@ -25,10 +17,13 @@ jobs:
2517
fail-fast: false
2618
matrix:
2719
platform:
28-
- linux/arm64
20+
- linux/386
2921
- linux/amd64
30-
- linux/s390x
22+
- linux/arm/v6
23+
- linux/arm/v7
24+
- linux/arm64/v8
3125
- linux/ppc64le
26+
- linux/s390x
3227

3328
permissions:
3429
contents: read
@@ -46,12 +41,16 @@ jobs:
4641
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
4742

4843
# Extract metadata (tags, labels) for Docker
44+
# If the pull request is not merged, do not include the edge tag and only include the sha tag.
4945
# https://github.com/docker/metadata-action
5046
- name: Extract Docker metadata
51-
id: meta
5247
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
5348
with:
54-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
49+
images: |
50+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
51+
tags: |
52+
type=semver,pattern=v{{version}}
53+
type=sha
5554
5655
# Set up QEMU
5756
# https://github.com/docker/setup-qemu-action
@@ -81,21 +80,19 @@ jobs:
8180
with:
8281
context: .
8382
platforms: ${{ matrix.platform }}
84-
labels: ${{ steps.meta.outputs.labels }}
85-
push: ${{ github.event.pull_request.merged == true }}
83+
labels: ${{ env.DOCKER_METADATA_OUTPUT_LABELS }}
84+
push: true
8685
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true
8786

8887
# Export digest
8988
- name: Export digest
90-
if: github.event.pull_request.merged == true
9189
run: |
9290
mkdir -p /tmp/digests
9391
digest="${{ steps.build.outputs.digest }}"
9492
touch "/tmp/digests/${digest#sha256:}"
9593
9694
# Upload digest
9795
- name: Upload digest
98-
if: github.event.pull_request.merged == true
9996
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
10097
with:
10198
name: digests
@@ -104,8 +101,8 @@ jobs:
104101
retention-days: 1
105102

106103
merge:
104+
name: Merge Container Manifests
107105
runs-on: ubuntu-latest
108-
if: github.event.pull_request.merged == true
109106
needs:
110107
- build
111108
steps:
@@ -128,12 +125,16 @@ jobs:
128125
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
129126

130127
# Extract metadata (tags, labels) for Docker
128+
# If the pull request is not merged, do not include the edge tag and only include the sha tag.
131129
# https://github.com/docker/metadata-action
132130
- name: Extract Docker metadata
133-
id: meta
134131
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
135132
with:
136-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
133+
images: |
134+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
135+
tags: |
136+
type=semver,pattern=v{{version}}
137+
type=sha
137138
138139
# Login to Docker registry
139140
# https://github.com/docker/login-action
@@ -148,9 +149,18 @@ jobs:
148149
- name: Create manifest list and push
149150
working-directory: /tmp/digests
150151
run: |
151-
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
152-
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
152+
# Base command to create a manifest list with the selected tag(s) and push
153+
CMD="docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
154+
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)"
155+
156+
# If the branch is 'release-*', add the 'edge' tag
157+
if [[ "${{ github.ref }}" == refs/heads/release-* ]]; then
158+
CMD="$CMD -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:edge"
159+
fi
160+
161+
# Execute the command
162+
eval "$CMD"
153163
154164
- name: Inspect image
155165
run: |
156-
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
166+
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.DOCKER_METADATA_OUTPUT_VERSION }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the kfutil binary
2-
FROM golang:1.19 as builder
2+
FROM golang:1.20 as builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

0 commit comments

Comments
 (0)