Skip to content

Commit 1a3464d

Browse files
authored
Merge pull request #205 from hligit/multiarch-build
workflow: Build arm64 Docker images
2 parents 1227a32 + 3ee1e85 commit 1a3464d

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

.github/workflows/docker-publish.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v2
2323

24+
- name: Set up QEMU
25+
uses: docker/setup-qemu-action@v1
26+
27+
- name: Set up Docker Buildx
28+
id: buildx
29+
uses: docker/setup-buildx-action@v1
30+
2431
- name: Set short sha variable
2532
id: vars
2633
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
2734

28-
- name: Build image
29-
run: docker build . --file Dockerfile --tag $IMAGE_NAME
30-
3135
- name: Log into GitHub Container Registry
3236
# a PAT with `read:packages` and `write:packages` scopes is an Actions secret `CR_PAT`.
3337
# Doesn't support Org or Repo level PATs and no bot accounts
@@ -49,5 +53,10 @@ jobs:
4953
echo IMAGE_ID=$IMAGE_ID
5054
echo VERSION=$VERSION
5155
52-
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
53-
docker push $IMAGE_ID:$VERSION
56+
for ARCH in amd64 arm64; do
57+
docker buildx build -t $IMAGE_ID:$VERSION-$ARCH --platform=linux/${ARCH} --push .
58+
done
59+
60+
docker manifest create $IMAGE_ID:$VERSION \
61+
$(for ARCH in amd64 arm64; do echo $IMAGE_ID:$VERSION-$ARCH; done)
62+
docker manifest push $IMAGE_ID:$VERSION

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
FROM golang:1.14 as builder
1+
FROM --platform=$BUILDPLATFORM golang:1.14 as builder
2+
ARG TARGETPLATFORM
23
WORKDIR /go/src/github.com/atlassian/escalator/
3-
COPY go.mod go.sum ./
4+
COPY go.mod go.sum Makefile ./
45
COPY cmd cmd
56
COPY pkg pkg
6-
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo cmd/main.go
7+
RUN make build
78

89
FROM alpine:latest
910
RUN apk --no-cache add ca-certificates
10-
COPY --from=builder /go/src/github.com/atlassian/escalator/main .
11+
COPY --from=builder /go/src/github.com/atlassian/escalator/escalator ./main
1112
CMD [ "./main" ]

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
.PHONY: build test test-vet docker clean lint
22

33
TARGET=escalator
4-
# E.g. set this to -v (I.e. GOCMDOPTS=-v via shell) to get the go command to be verbose
5-
GOCMDOPTS?=
64
SRC_DIRS=pkg cmd
75
SOURCES=$(shell for dir in $(SRC_DIRS); do if [ -d $$dir ]; then find $$dir -type f -iname '*.go'; fi; done)
6+
ARCH=$(if $(TARGETPLATFORM),$(lastword $(subst /, ,$(TARGETPLATFORM))),amd64)
87

98
$(TARGET): $(SOURCES)
10-
go build $(GOCMDOPTS) -o $(TARGET) cmd/main.go
9+
CGO_ENABLED=0 GOARCH=$(ARCH) go build -a -installsuffix cgo -o $(TARGET) cmd/main.go
1110

1211
build: $(TARGET)
1312

@@ -18,7 +17,7 @@ test-vet:
1817
go vet ./...
1918

2019
docker: Dockerfile
21-
docker build -t atlassian/escalator .
20+
docker buildx build -t atlassian/escalator --platform linux/$(ARCH) .
2221

2322
clean:
2423
rm -f $(TARGET)

0 commit comments

Comments
 (0)