Skip to content

Commit

Permalink
Build ARM64 Docker images in 'goreleaser' (#1494)
Browse files Browse the repository at this point in the history
* Docker images use 'scratch' instead of 'ubuntu' now because Go binaries are statically linked
* Build target for 'darwin/386' has been removed as well

Signed-off-by: Jan Schlicht <jan@d2iq.com>
  • Loading branch information
Jan Schlicht committed May 7, 2020
1 parent 1e7adc9 commit 89528fb
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 54 deletions.
31 changes: 29 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ before:
- go mod download
# you may remove this if you don't need go generate
- go generate ./...
# Pulls down the latest version of the controller's parent image
- docker pull ubuntu:18.04
builds:
- id: "manager"
binary: manager
Expand All @@ -24,6 +22,10 @@ builds:
- 386
- amd64
- arm
- arm64
ignore:
- goos: darwin
goarch: 386
- id: "kubectl-kudo"
binary: kubectl-kudo
main: cmd/kubectl-kudo/main.go
Expand All @@ -36,20 +38,45 @@ builds:
- 386
- amd64
- arm
- arm64
ignore:
- goos: darwin
goarch: 386
dockers:
# always push a docker image on release for the .Tag version
- dockerfile: Dockerfile.goreleaser
binaries:
- manager
goos: linux
goarch: amd64
image_templates:
- "kudobuilder/controller:{{ .Tag }}"
# only update the docker :latest for a full release (not RC)
- dockerfile: Dockerfile.goreleaser
binaries:
- manager
goos: linux
goarch: amd64
image_templates:
- "kudobuilder/controller:latest"
skip_push: auto
# always push a docker image on release for the .Tag version
- dockerfile: Dockerfile.goreleaser
binaries:
- manager
goos: linux
goarch: arm64
image_templates:
- "kudobuilder/controller-arm64:{{ .Tag }}"
# only update the docker :latest for a full release (not RC)
- dockerfile: Dockerfile.goreleaser
binaries:
- manager
goos: linux
goarch: arm64
image_templates:
- "kudobuilder/controller-arm64:latest"
skip_push: auto
archives:
- id: kubectl-kudo-tarball
builds:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ You can build CLI locally via `make cli`. After running that command, CLI will b
#### Running new manager inside cluster
For some situations, it might make sense to test your manager inside a real cluster running in a pod (not just running the binary locally). To do that you need:
- build a docker image with the manager locally `DOCKER_IMG=nameofyourimage make docker-build`
- push the image to a remote repository `DOCKER_IMG=nameofyourimage make docker-push`
- push the built image to a remote repository
- run `kubectl kudo init --kudo-image nameofyourimage:tag`

### Testing
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.amd64 → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager \
-ldflags "${ldflags_arg}" github.com/kudobuilder/kudo/cmd/manager

# Copy the controller-manager into a thin image
FROM ubuntu:18.04
FROM scratch
WORKDIR /root/
COPY --from=builder /go/src/github.com/kudobuilder/kudo/manager .
ENTRYPOINT ["./manager"]
23 changes: 0 additions & 23 deletions Dockerfile.arm64

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:18.04
FROM scratch
WORKDIR /root/
COPY manager /root
ENTRYPOINT ["./manager"]
25 changes: 1 addition & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,30 +135,7 @@ clean: cli-clean test-clean manager-clean deploy-clean
.PHONY: docker-build
# Build the docker image for each supported platform
docker-build: generate lint
$(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 all images and manifests
docker-push: docker-push-platforms docker-push-manifests
docker build --build-arg ldflags_arg="$(LDFLAGS)" -f Dockerfile -t $(DOCKER_IMG):$(DOCKER_TAG) .

.PHONY: imports
# used to update imports on project. NOT a linter.
Expand Down
3 changes: 1 addition & 2 deletions test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ 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.amd64 ./Dockerfile
COPY Makefile go.mod go.sum ./
COPY Dockerfile Makefile go.mod go.sum ./
RUN make download
COPY config/ config/
COPY pkg/ pkg/
Expand Down

0 comments on commit 89528fb

Please sign in to comment.