Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arm64 docker builds #348

Merged
merged 3 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ FROM golang:1.13-alpine AS build
WORKDIR /go/src/github.com/segmentio/chamber
COPY . .

ARG TARGETARCH
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a default arg of buildkit-based builds

ARG VERSION
RUN test -n "${VERSION}"

RUN apk add -U make ca-certificates
RUN make linux VERSION=${VERSION}
RUN make linux VERSION=${VERSION} TARGETARCH=${TARGETARCH}

FROM scratch AS run

Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ ifndef VERSION
VERSION := $(shell git describe --tags --always --dirty="-dev")
endif

ifndef TARGETARCH
TARGETARCH := $(shell arch)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An issue we might have here is that OS X reports arm64 but linux reports aarch64 when running this command on the same machine and arch.

since *nix varieties cannot agree here i think we need to make sure this is going to output exactly what we expect it to.

endif

VERSION_NO_V := $(shell echo "$(VERSION)" | sed 's/^v//')
VERSION_MAJOR_MINOR_PATCH := $(shell echo "$(VERSION)" | sed 's/^v\([0-9]*.[0-9]*.[0-9]*\).*/\1/')
VERSION_MAJOR_MINOR := $(shell echo "$(VERSION)" | sed 's/^v\([0-9]*.[0-9]*\).*/\1/')
Expand Down Expand Up @@ -37,13 +41,13 @@ dist/chamber-$(VERSION)-darwin-amd64: | dist/
dist/chamber-$(VERSION)-darwin-arm64: | dist/
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -trimpath $(LDFLAGS) -o $@

linux: dist/chamber-$(VERSION)-linux-amd64
linux: dist/chamber-$(VERSION)-linux-$(TARGETARCH)
cp $^ chamber

dist/chamber-$(VERSION)-linux-amd64: | dist/
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath $(LDFLAGS) -o $@

dist/chamber-$(VERSION)-linux-arm64: | dist/
dist/chamber-$(VERSION)-linux-arm64 dist/chamber-$(VERSION)-linux-aarch64: | dist/
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -trimpath $(LDFLAGS) -o $@

dist/chamber-$(VERSION)-windows-amd64.exe: | dist/
Expand Down
8 changes: 3 additions & 5 deletions Makefile.release
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ ifneq (,$(findstring -,$(VERSION)))
endif

publish-dockerhub:
docker build \
docker buildx build \
-t segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_MAJOR_MINOR_PATCH) \
-t segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_MAJOR_MINOR) \
-t segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_MAJOR) \
-t segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_NO_V) \
--build-arg VERSION=$(VERSION) \
--platform linux/amd64,linux/arm64 \
--push \
.
docker push segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_MAJOR_MINOR_PATCH)
docker push segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_MAJOR_MINOR)
docker push segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_MAJOR)
docker push segment/chamber:$(DOCKERHUB_TAG_PREFIX)$(VERSION_NO_V)

dist: dist/chamber-$(VERSION)-darwin-amd64 dist/chamber-$(VERSION)-darwin-arm64 dist/chamber-$(VERSION)-linux-amd64 dist/chamber-$(VERSION)-linux-arm64 dist/chamber-$(VERSION)-windows-amd64.exe dist/chamber_$(VERSION)_amd64.deb dist/chamber_$(VERSION)_amd64.rpm dist/chamber-$(VERSION).sha256sums

Expand Down