Skip to content

Commit 772362e

Browse files
authored
fix #298 gh action docker image build failure (#301)
* chore: fix badge of docker build gh action * fix: Dockerfile for multiarch * fix: #298 Docker build failure * chore: add usage of Docker and notes for dictionary
1 parent 4b8aea7 commit 772362e

File tree

6 files changed

+168
-221
lines changed

6 files changed

+168
-221
lines changed

.github/workflows/build-docker-latest.yml

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

.github/workflows/release.yml

Lines changed: 15 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name: Release
22

33
on:
4+
workflow_dispatch:
45
push:
56
tags:
67
- 'v*'
7-
env:
8-
NAME_IMAGE: "${{ secrets.DOCKER_USERNAME }}/kagome"
98

109
jobs:
1110
goreleaser:
@@ -14,93 +13,36 @@ jobs:
1413
- name: Checkout
1514
uses: actions/checkout@v3
1615
with:
16+
# required for the changelog of goreleaser to work correctly.
1717
fetch-depth: 0
18+
19+
# Setup Go
1820
- name: Set up Go
1921
uses: actions/setup-go@v4
2022
with:
2123
go-version-file: 'go.mod'
2224
cache: true
23-
- name: Run GoReleaser
24-
uses: goreleaser/goreleaser-action@v4
25-
with:
26-
version: latest
27-
args: release --rm-dist --config .goreleaser.yml
28-
env:
29-
GITHUB_TOKEN: ${{ secrets.GO_RELEASER_TOKEN }}
3025

31-
docker:
32-
runs-on: ubuntu-latest
33-
steps:
34-
# Clone and checkout the repo. "fetch-depth" is needed in order to get the
35-
# version tag information.
36-
- name: Checkout the code
37-
uses: actions/checkout@v3
38-
with:
39-
fetch-depth: 0
40-
41-
# Install QEMU emulators for Buildx
26+
# Multiarch build
4227
- name: Set up QEMU
4328
uses: docker/setup-qemu-action@v2
44-
with:
45-
platforms: all
4629

47-
# Install Buildx to build multi-arch docker images.
4830
- name: Set up Docker Buildx
4931
id: buildx
5032
uses: docker/setup-buildx-action@v2
51-
with:
52-
version: latest
53-
54-
# View available platforms
55-
- name: Available platforms of Buildx
56-
run: echo ${{ steps.buildx.outputs.platforms }}
5733

58-
# Login to Docker Hub. You need to set the below two secreat env variables
59-
# in the repo's [Settings]-[Secrets] settings in advance:
60-
# DOCKER_USERNAME ... Login user name of Docker Hub
61-
# DOCKER_PASSWORD ... Access Token from https://hub.docker.com/settings/security
62-
- name: Login to DockerHub
63-
if: success() && github.event_name != 'pull_request'
34+
# Login to DockerHub before push.
35+
- name: Login to Docker Hub
6436
uses: docker/login-action@v2
6537
with:
6638
username: ${{ secrets.DOCKER_USERNAME }}
6739
password: ${{ secrets.DOCKER_PASSWORD }}
6840

69-
# To make the "latest" tag work not only for x86_64(Intel/AMD) but with ARMs
70-
# such as ARM v6, v7 and ARM64 architectures, we need a temporary workaround
71-
# due to the bug of Docker. https://github.com/moby/moby/issues/37647
72-
- name: Build the images
73-
# Build images for each architecture and push them.
74-
run: |
75-
docker system prune -f -a && \
76-
docker buildx build --push --tag ${{ env.NAME_IMAGE }}:arm32v6 --platform linux/arm/v6 --build-arg GOARCH=arm --build-arg GOARM=6 . && \
77-
docker buildx build --push --tag ${{ env.NAME_IMAGE }}:arm32v7 --platform linux/arm/v7 --build-arg GOARCH=arm --build-arg GOARM=7 . && \
78-
docker buildx build --push --tag ${{ env.NAME_IMAGE }}:arm64 --platform linux/arm64 --build-arg GOARCH=arm64 . && \
79-
docker buildx build --push --tag ${{ env.NAME_IMAGE }}:amd64 --platform linux/amd64 .
80-
- name: Pull back the images
81-
# We need to pull back the built images to use the manifest which Docker
82-
# Hub did attach.
83-
run: |
84-
docker system prune -f -a && \
85-
docker pull ${{ env.NAME_IMAGE }}:arm32v6 && \
86-
docker pull ${{ env.NAME_IMAGE }}:arm32v7 && \
87-
docker pull ${{ env.NAME_IMAGE }}:arm64 && \
88-
docker pull ${{ env.NAME_IMAGE }}:amd64
89-
- name: Create current manifest and push
90-
# Create manifest of current Kagome version with "vX.Y.Z" tag.
91-
run: |
92-
git_tag=$(git describe --tag) && \
93-
version_curr=$(echo "${git_tag}" | grep -o -E "(v[0-9]+\.){1}[0-9]+(\.[0-9]+)?" | head -n1) && \
94-
echo '- Removing latest image (prevent conflict)' && \
95-
docker image rm -f ${{ env.NAME_IMAGE }}:latest && \
96-
echo "- Creating manifest for Kagome version: ${version_curr}" && \
97-
export DOCKER_CLI_EXPERIMENTAL=enabled && \
98-
docker manifest create ${{ env.NAME_IMAGE }}:${version_curr} \
99-
${{ env.NAME_IMAGE }}:arm32v6 \
100-
${{ env.NAME_IMAGE }}:arm32v7 \
101-
${{ env.NAME_IMAGE }}:arm64 \
102-
${{ env.NAME_IMAGE }}:amd64 && \
103-
docker manifest annotate ${{ env.NAME_IMAGE }}:${version_curr} ${{ env.NAME_IMAGE }}:arm32v6 --variant v6l && \
104-
docker manifest annotate ${{ env.NAME_IMAGE }}:${version_curr} ${{ env.NAME_IMAGE }}:arm32v7 --variant v7l && \
105-
docker manifest inspect ${{ env.NAME_IMAGE }}:${version_curr} && \
106-
docker manifest push ${{ env.NAME_IMAGE }}:${version_curr} --purge
41+
# Build and release
42+
- name: Run GoReleaser
43+
uses: goreleaser/goreleaser-action@v4
44+
with:
45+
version: latest
46+
args: release --config .goreleaser.yml --clean
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GO_RELEASER_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

.goreleaser.yml

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,56 @@
1+
# =============================================================================
2+
# GoReleaser configuration file for Kagome
3+
# =============================================================================
4+
# For local testing run:
5+
# goreleaser --skip-publish --clean --snapshot
6+
#
7+
# Note:
8+
# To build multiarch Docker image, you may be required to install Docker buildx
9+
# plugin and QEMU.
110
env:
211
- GO111MODULE=on
12+
313
before:
414
hooks:
515
- go mod download
16+
617
builds:
718
- env:
819
- CGO_ENABLED=0
20+
binary: kagome
921
goos:
1022
- linux
1123
- darwin
1224
- windows
1325
goarch:
1426
- amd64
15-
- arm
1627
- arm64
28+
- arm
29+
# Variant for ARM32
30+
goarm:
31+
- "5"
32+
- "6"
33+
- "7"
34+
# Ignore ARM32 build for both macOS and Windows
35+
ignore:
36+
- goos: darwin
37+
goarch: arm
38+
- goos: windows
39+
goarch: arm
1740
mod_timestamp: '{{ .CommitTimestamp }}'
1841
flags:
1942
- -trimpath
2043
ldflags:
21-
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
44+
- -s -w -extldflags '-static' -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
45+
46+
# macOS universal binaries. It will join the binaries for AMD64 and Amd64 into
47+
# a single binary. Suitable for Apple Silicon (Arm64) and Intel (amd64).
48+
universal_binaries:
49+
-
50+
name_template: 'kagome'
51+
# Remove each after joining
52+
replace: true
53+
2254
brews:
2355
- tap:
2456
owner: ikawaha
@@ -32,4 +64,67 @@ brews:
3264
install: |
3365
bin.install "kagome"
3466
test: |
35-
system "#{bin}/kagome version"
67+
system "#{bin}/kagome version"
68+
69+
# Build Docker images. It will copy the built binary from the "builds" step above.
70+
dockers:
71+
- image_templates:
72+
- "ikawaha/kagome:{{ .Version }}-amd64"
73+
use: buildx
74+
goarch: amd64
75+
dockerfile: Dockerfile
76+
build_flag_templates:
77+
- "--platform=linux/amd64"
78+
79+
- image_templates:
80+
- "ikawaha/kagome:{{ .Version }}-arm64"
81+
use: buildx
82+
goarch: arm64
83+
dockerfile: Dockerfile
84+
build_flag_templates:
85+
- "--platform=linux/arm64/v8"
86+
87+
- image_templates:
88+
- "ikawaha/kagome:{{ .Version }}-arm32v5"
89+
use: buildx
90+
goarch: arm
91+
goarm: 5
92+
dockerfile: Dockerfile
93+
build_flag_templates:
94+
- "--platform=linux/arm/v5"
95+
96+
- image_templates:
97+
- "ikawaha/kagome:{{ .Version }}-arm32v6"
98+
use: buildx
99+
goarch: arm
100+
goarm: 6
101+
dockerfile: Dockerfile
102+
build_flag_templates:
103+
- "--platform=linux/arm/v6"
104+
105+
- image_templates:
106+
- "ikawaha/kagome:{{ .Version }}-arm32v7"
107+
use: buildx
108+
goarch: arm
109+
goarm: 7
110+
dockerfile: Dockerfile
111+
build_flag_templates:
112+
- "--platform=linux/arm/v7"
113+
114+
# Create multiarch manifest file of Docker image. This will bind all the images
115+
# above into a single manifest file for "latest" and each version tag.
116+
docker_manifests:
117+
- name_template: ikawaha/kagome:{{ .Version }}
118+
image_templates:
119+
- ikawaha/kagome:{{ .Version }}-amd64
120+
- ikawaha/kagome:{{ .Version }}-arm64
121+
- ikawaha/kagome:{{ .Version }}-arm32v5
122+
- ikawaha/kagome:{{ .Version }}-arm32v6
123+
- ikawaha/kagome:{{ .Version }}-arm32v7
124+
- name_template: ikawaha/kagome:latest
125+
image_templates:
126+
- ikawaha/kagome:{{ .Version }}-amd64
127+
- ikawaha/kagome:{{ .Version }}-arm64
128+
- ikawaha/kagome:{{ .Version }}-arm32v5
129+
- ikawaha/kagome:{{ .Version }}-arm32v6
130+
- ikawaha/kagome:{{ .Version }}-arm32v7

Dockerfile

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
1-
# This is a Docker image of Kagome on Alpine Linux.
2-
# =================================================
3-
4-
# 1st stage: Build binary.
5-
# ------------------------
6-
FROM --platform=$BUILDPLATFORM golang:alpine AS build-app
7-
8-
ARG BUILDPLATFORM
9-
ARG TARGETPLATFORM
10-
ARG GOOS=linux
11-
ARG GOARCH=amd64
12-
ARG GOARM=
13-
14-
# Copy the current dir including .git dir for versioning.
15-
COPY . /go/src/github.com/ikawaha/kagome
16-
WORKDIR /go/src/github.com/ikawaha/kagome
17-
18-
# Shell script to build the image (with the tag as version).
19-
RUN \
20-
apk --no-cache add git && \
21-
version_app=$(git describe --tag) && \
22-
echo "- Running on ${BUILDPLATFORM}, building for ${TARGETPLATFORM}" && \
23-
echo "- Current platform: $(uname -a)" && \
24-
echo "- Current git tag: ${version_app}" && \
25-
echo "- Current Go version: $(go version)" && \
26-
echo "- Kagome version to be build:${version_app}" && \
27-
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build \
28-
--ldflags "-w -s -extldflags \"-static\" -X 'main.version=${version_app}'" \
29-
-o /go/bin/kagome \
30-
/go/src/github.com/ikawaha/kagome && \
31-
echo "- Smoke test (run kagome version command) ... $(/go/bin/kagome version)"
32-
33-
# 2nd stage: Copy only the built binary to shrink the image size.
34-
# ---------------------------------------------------------------
35-
FROM --platform=$BUILDPLATFORM alpine:latest
36-
37-
COPY --from=build-app /go/bin/kagome /usr/local/bin/kagome
38-
39-
ENTRYPOINT [ "kagome" ]
1+
FROM scratch
2+
COPY kagome /
3+
ENTRYPOINT ["/kagome"]

0 commit comments

Comments
 (0)