Skip to content

Commit cb1cb67

Browse files
authored
feat: add arm64 build
1 parent dde9854 commit cb1cb67

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

.semaphore/semaphore.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ global_job_config:
3939
- curl -sfL https://gist.githubusercontent.com/traefiker/6d7ac019c11d011e4f131bb2cca8900e/raw/goreleaser.sh | bash -s -- -b "${GOPATH}/bin"
4040
- checkout
4141
- cache restore "mod-${SEMAPHORE_PROJECT_NAME}-${SEMAPHORE_GIT_BRANCH}-$(checksum go.mod),mod-${SEMAPHORE_PROJECT_NAME}-$(checksum go.mod),mod-${SEMAPHORE_PROJECT_NAME}"
42+
- docker buildx create --use
43+
- docker run --privileged --rm tonistiigi/binfmt --install all
4244
blocks:
4345
- name: Warm cache
4446
dependencies: []
@@ -61,7 +63,9 @@ blocks:
6163
- name: Build on branches
6264
commands:
6365
- make
64-
- make image publish-latest
66+
- make multi-arch-image-latest
67+
- make multi-arch-image-${SEMAPHORE_GIT_BRANCH}-${SEMAPHORE_GIT_SHA:0:7}-$(date +%s)
68+
6569
- name: Build on PR
6670
dependencies: ["Warm cache"]
6771
run:
@@ -71,6 +75,8 @@ blocks:
7175
- name: Run build
7276
commands:
7377
- make
78+
- make multi-arch-image-${SEMAPHORE_GIT_PR_NUMBER}
79+
7480
- name: Tag - Build release
7581
dependencies: ["Warm cache"]
7682
run:
@@ -80,4 +86,4 @@ blocks:
8086
- name: Tag - Build release
8187
commands:
8288
- make
83-
- make image publish
89+
- make multi-arch-image-${SEMAPHORE_GIT_TAG_NAME}

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ RUN apk --no-cache --no-progress add git ca-certificates tzdata make \
44
&& update-ca-certificates \
55
&& rm -rf /var/cache/apk/*
66

7-
COPY piceus .
7+
COPY ./dist/linux/amd64/piceus .
88

99
ENTRYPOINT ["/piceus"]
1010
EXPOSE 80

Makefile

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ TAG_NAME := $(shell git tag -l --contains HEAD)
44
SHA := $(shell git rev-parse --short HEAD)
55
VERSION := $(if $(TAG_NAME),$(TAG_NAME),$(SHA))
66
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%I:%M:%S%p')
7+
BIN_NAME := "piceus"
78

9+
# Default build target
10+
GOOS := $(shell go env GOOS)
11+
GOARCH := $(shell go env GOARCH)
12+
DOCKER_BUILD_PLATFORMS ?= linux/amd64,linux/arm64
813
default: clean check test build
914

1015
clean:
@@ -15,7 +20,21 @@ test: clean
1520

1621
build: clean
1722
@echo Version: $(VERSION) $(BUILD_DATE)
18-
CGO_ENABLED=0 go build -ldflags '-X "main.version=${VERSION}" -X "main.commit=${SHA}" -X "main.date=${BUILD_DATE}"'
23+
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -v -ldflags '-X "main.version=${VERSION}" -X "main.commit=${SHA}" -X "main.date=${BUILD_DATE}"' -o "./dist/${GOOS}/${GOARCH}/${BIN_NAME}"
24+
25+
build-linux-arm64: export GOOS := linux
26+
build-linux-arm64: export GOARCH := arm64
27+
build-linux-arm64:
28+
make build
29+
30+
build-linux-amd64: export GOOS := linux
31+
build-linux-amd64: export GOARCH := amd64
32+
build-linux-amd64:
33+
make build
34+
35+
## Build Multi archs Docker image
36+
multi-arch-image-%: build-linux-amd64 build-linux-arm64
37+
docker buildx build $(DOCKER_BUILDX_ARGS) --progress=chain -t gcr.io/traefiklabs/$(BIN_NAME):$* --platform=$(DOCKER_BUILD_PLATFORMS) -f buildx.Dockerfile .
1938

2039
image:
2140
docker build -t gcr.io/traefiklabs/piceus:$(VERSION) .

buildx.Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM alpine
2+
3+
RUN apk --no-cache --no-progress add git ca-certificates tzdata make \
4+
&& update-ca-certificates \
5+
&& rm -rf /var/cache/apk/*
6+
7+
ARG TARGETPLATFORM
8+
COPY ./dist/$TARGETPLATFORM/piceus .
9+
10+
ENTRYPOINT ["/piceus"]
11+
EXPOSE 80

0 commit comments

Comments
 (0)