Skip to content

Commit

Permalink
Merge pull request #267 from AbsaOSS/multiarch
Browse files Browse the repository at this point in the history
Enable docker multiarch build
  • Loading branch information
k0da authored Feb 4, 2021
2 parents 8ac5578 + 119e3c3 commit 62ac00a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ jobs:
run: |
export PATH=~/go/bin:$PATH
docker login -u "${DOCKER_USER}" -p "${DOCKER_PASSWORD}"
make docker-build
make docker-push
make docker-build-multi
make docker-push-multi
make docker-manifest
- uses: dave-mcconnell/helm-gh-pages-microservices@master
with:
access-token: ${{ secrets.CR_TOKEN }}
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
FROM golang:1.15 as builder

WORKDIR /workspace
ARG GOARCH=amd64

# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
Expand All @@ -15,7 +17,7 @@ COPY api/ api/
COPY controllers/ controllers/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
RUN CGO_ENABLED=0 GOARCH=${GOARCH} GOOS=linux GO111MODULE=on go build -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
35 changes: 33 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,38 @@ dns-tools: ## Run temporary dnstools pod for debugging DNS issues
dns-smoke-test:
kubectl -n k8gb run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools --command -- /usr/bin/dig @k8gb-coredns roundrobin.cloud.example.com

# build docker images for multiple architectures
# useful for CI
.PHONY: docker-build-multi
docker-build-multi: test
$(call docker-build-arch,amd64)
$(call docker-build-arch,arm64)

# push docker for multiple architectures
.PHONY: docker-push-multi
docker-push-multi:
$(call docker-push-arch,amd64)
$(call docker-push-arch,arm64)

# create and push docker manifest
.PHONY: docker-manifest
docker-manifest: docker-push-multi
docker manifest create ${IMG} \
${IMG}-amd64 \
${IMG}-arm64
docker manifest annotate ${IMG} ${IMG}-arm64 \
--os linux --arch arm64
docker manifest push ${IMG}

# build the docker image
.PHONY: docker-build
docker-build: test
docker build . -t $(IMG)
$(call docker-build-arch,amd64)

# push the docker image
.PHONY: docker-push
docker-push:
docker push $(IMG)
$(call docker-push-arch,amd64)

# build and push the docker image exclusively for testing using commit hash
.PHONY: docker-test-build-push
Expand Down Expand Up @@ -412,6 +435,14 @@ define install-kustomize
$(eval KUSTOMIZE_PATH = $(GOBIN)/kustomize)
endef

define docker-build-arch
docker build --build-arg GOARCH=${1} . -t ${IMG}-${1}
endef

define docker-push-arch
docker push ${IMG}-${1}
endef

define docker-test-build-push
docker build . -t k8gb:$(COMMIT_HASH)
docker tag k8gb:$(COMMIT_HASH) $(REPO):v$(COMMIT_HASH)
Expand Down

0 comments on commit 62ac00a

Please sign in to comment.