Skip to content

Commit

Permalink
Add ARM64 Support (#1488)
Browse files Browse the repository at this point in the history
* Increase golangci-lint timeout from 1m to 3m

I found that on lower powered ARM machines when trying to build
Kudo a longer timeout was needed to complete.

* Introduce ARM64 docker build file

* Add multi-platform build and push support to Makefile

Signed-off-by: Shane Utt <shaneutt@linux.com>
  • Loading branch information
shaneutt committed May 5, 2020
1 parent 1d1a9c1 commit 63c653a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
File renamed without changes.
23 changes: 23 additions & 0 deletions Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Build the manager binary
FROM golang:1.14 as builder

# Setting arguments
ARG ldflags_arg

# Copy in the go src
WORKDIR /go/src/github.com/kudobuilder/kudo
COPY pkg/ pkg/
COPY cmd/ cmd/
COPY go.mod go.mod
COPY go.sum go.sum
ENV GO111MODULE on

# Build with ldflags set
RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -o manager \
-ldflags "${ldflags_arg}" github.com/kudobuilder/kudo/cmd/manager

# Copy the controller-manager into a thin image
FROM arm64v8/ubuntu:18.04
WORKDIR /root/
COPY --from=builder /go/src/github.com/kudobuilder/kudo/manager .
ENTRYPOINT ["./manager"]
35 changes: 25 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ BUILD_DATE := $(shell date -u -d "@$SOURCE_DATE_EPOCH" "+${DATE_FMT}" 2>/dev/nul
LDFLAGS := -X ${GIT_VERSION_PATH}=${GIT_VERSION} -X ${GIT_COMMIT_PATH}=${GIT_COMMIT} -X ${BUILD_DATE_PATH}=${BUILD_DATE}
ENABLE_WEBHOOKS ?= false
GOLANGCI_LINT_VER = "1.23.8"
SUPPORTED_PLATFORMS = amd64 arm64

export GO111MODULE=on

Expand Down Expand Up @@ -51,7 +52,7 @@ lint:
ifneq (${GOLANGCI_LINT_VER}, "$(shell golangci-lint --version 2>/dev/null | cut -b 27-32)")
./hack/install-golangcilint.sh
endif
golangci-lint run
golangci-lint --timeout 3m run

.PHONY: download
download:
Expand Down Expand Up @@ -132,18 +133,32 @@ cli-install:
clean: cli-clean test-clean manager-clean deploy-clean

.PHONY: docker-build
# Build the docker image
# Build the docker image for each supported platform
docker-build: generate lint
docker build --build-arg ldflags_arg="${LDFLAGS}" . -t ${DOCKER_IMG}:${DOCKER_TAG}
docker tag ${DOCKER_IMG}:${DOCKER_TAG} ${DOCKER_IMG}:v${GIT_VERSION}
docker tag ${DOCKER_IMG}:${DOCKER_TAG} ${DOCKER_IMG}:latest
$(foreach arch,$(SUPPORTED_PLATFORMS),docker build --build-arg ldflags_arg="$(LDFLAGS)" -f Dockerfile.$(arch) -t $(DOCKER_IMG)-$(arch):$(DOCKER_TAG) .;)
$(foreach arch,$(SUPPORTED_PLATFORMS),docker tag $(DOCKER_IMG)-$(arch):$(DOCKER_TAG) $(DOCKER_IMG)-$(arch):v$(GIT_VERSION);)
$(foreach arch,$(SUPPORTED_PLATFORMS),docker tag $(DOCKER_IMG)-$(arch):$(DOCKER_TAG) $(DOCKER_IMG)-$(arch):latest;)

.PHONY: docker-push-all-platforms
# Push the platform specific images for each supported arch
docker-push-platforms:
$(foreach arch,$(SUPPORTED_PLATFORMS),docker push $(DOCKER_IMG)-$(arch):$(DOCKER_TAG);)
$(foreach arch,$(SUPPORTED_PLATFORMS),docker push $(DOCKER_IMG)-$(arch):v$(GIT_VERSION);)
$(foreach arch,$(SUPPORTED_PLATFORMS),docker push $(DOCKER_IMG)-$(arch):latest;)

.PHONY: docker-push-manifest
# Push the multi-arch image manifest
docker-push-manifests:
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create --amend $(DOCKER_IMG):$(DOCKER_TAG) $(foreach arch,$(SUPPORTED_PLATFORMS),$(DOCKER_IMG)-$(arch):$(DOCKER_TAG))
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create --amend $(DOCKER_IMG):v$(GIT_VERSION) $(foreach arch,$(SUPPORTED_PLATFORMS),$(DOCKER_IMG)-$(arch):v$(GIT_VERSION))
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create --amend $(DOCKER_IMG):latest $(foreach arch,$(SUPPORTED_PLATFORMS),$(DOCKER_IMG)-$(arch):latest)
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(DOCKER_IMG):$(DOCKER_TAG)
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(DOCKER_IMG):v$(GIT_VERSION)
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(DOCKER_IMG):latest

.PHONY: docker-push
# Push the docker image
docker-push:
docker push ${DOCKER_IMG}:${DOCKER_TAG}
docker push ${DOCKER_IMG}:${GIT_VERSION}
docker push ${DOCKER_IMG}:latest
# Push all images and manifests
docker-push: docker-push-platforms docker-push-manifests

.PHONY: imports
# used to update imports on project. NOT a linter.
Expand Down
3 changes: 2 additions & 1 deletion test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ RUN apt-get update && apt-get install -y \
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && \
apt-get update && apt-get install -y docker-ce-cli

COPY Dockerfile Makefile go.mod go.sum ./
COPY Dockerfile.amd64 ./Dockerfile
COPY Makefile go.mod go.sum ./
RUN make download
COPY config/ config/
COPY pkg/ pkg/
Expand Down

0 comments on commit 63c653a

Please sign in to comment.