Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.

Commit 619e3fa

Browse files
kensipeporridge
andauthoredSep 29, 2020
Multi-Arch Docker Image Releases (kudobuilder#214)
Co-authored-by: Marcin Owsiany <mowsiany@D2iQ.com> Signed-off-by: Ken Sipe <kensipe@gmail.com>
1 parent fc28616 commit 619e3fa

File tree

5 files changed

+78
-8
lines changed

5 files changed

+78
-8
lines changed
 

‎DOCKER.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Docker Releases
2+
3+
There is strong interest in the community to support a number of architectures with docker images. One driver is [Operator SDK scorecard](https://sdk.operatorframework.io/docs/advanced-topics/scorecard/scorecard/) for which KUTTL provides additional test features. The following architectures are needed to support scorecard:
4+
5+
* linux/amd64
6+
* linux/arm64
7+
* linux/ppc64le
8+
* linux/s390x
9+
10+
In order to support this, we are using the new and experimental docker [buildx](https://docs.docker.com/engine/reference/commandline/buildx/). This allows for building and pushing of several architectures to the same docker repository allowing for the client platform to determine preferred architecture for its pull request.
11+
12+
In addition to using `buildx` there are two more requirements to make this work:
13+
14+
1. The base image must support all the architectures desired. For this reason we now use `registry.access.redhat.com/ubi8/ubi-minimal`.
15+
1. The go libraries must support the architectures.
16+
17+
## Building and Pushing Multi-Arch Docker Image
18+
19+
For a detailed understanding, please read the [buildx build documentation](https://docs.docker.com/engine/reference/commandline/buildx_build/).
20+
You will need to `enable` docker CLI experimental features for this to work.
21+
22+
To build and push manually the following is necessary: `make docker-release`
23+
24+
This will result in a command similar to the following with the version tag replaced with the current version:
25+
`docker buildx build . -t kudobuilder/kuttl:v0.6.1 --platform linux/amd64,linux/arm64,linux/ppc64le --push`
26+
27+
Updates for platform builds are maintained in [hack/docker-release.sh](hack/docker-release.sh).

‎Dockerfile

+7-6
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ RUN go get -d -v ./...
2525
RUN make cli
2626

2727
# release image with kubectl + kuttl
28-
FROM debian:buster
28+
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
2929

30-
RUN apt-get update && apt-get install -y curl wget gnupg2 apt-transport-https vim
31-
RUN curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
30+
RUN microdnf install vim
31+
RUN echo 'alias vi=vim' >> ~/.bashrc
3232

33-
RUN echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list
34-
RUN apt-get update
35-
RUN apt-get install -y kubectl
33+
# kube 1.18
34+
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl
35+
RUN chmod +x ./kubectl
36+
RUN mv ./kubectl /usr/local/bin/kubectl
3637

3738
COPY --from=builder /go/src/kuttl/bin/kubectl-kuttl /usr/bin/kubectl-kuttl
3839

‎Makefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,16 @@ clean: cli-clean ## Cleans CLI and kind logs
6060
rm -rf kind-logs-*
6161

6262
.PHONY: docker
63-
# build docker image
64-
docker: ## Builds docker image
63+
# build a local docker image (specific to the local platform only)
64+
docker: ## Builds docker image for architecture of the local env
6565
docker build . -t kuttl
6666

67+
.PHONY: docker-release
68+
# build and push a multi-arch docker image
69+
docker-release: ## Build and push multi-arch docker images
70+
./hack/docker-release.sh
71+
72+
6773
# Install CLI
6874
cli-install: ## Installs kubectl-kuttl to GOBIN
6975
go install -ldflags "${LDFLAGS}" ./cmd/kubectl-kuttl

‎RELEASE.md

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ The release process is:
7171
It is possible outside of the standard release process to build a "snapshot" release using the following command: `goreleaser release --skip-publish --snapshot --rm-dist`
7272
This process will create a `dist` folder with all the build artifacts. The changelog is not created unless a full release is executed. If you are looking to get a "similar" changelog, install [github-release-notes](https://github.com/buchanae/github-release-notes) and execute `github-release-notes -org kudobuilder -repo kuttl -since-latest-release`.
7373

74+
### Docker Release
75+
76+
The docker release is accomplished by `make docker-release`. Details on what is required are provided in [Docker.md](DOCKER.md).
7477

7578
### Cutting a Release Branch
7679

‎hack/docker-release.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
#####
4+
# Used to produce a multi-arch docker image and push it onto docker hub
5+
# This requires the use of the buildx experimental feature in the later version of docker
6+
#####
7+
8+
set -o nounset
9+
set -o pipefail
10+
# intentionally not setting 'set -o errexit' because we want to print custom error messages
11+
12+
GIT_VERSION="$(git describe --abbrev=0 --tags | cut -b 2-)"
13+
14+
echo "Releasing for version: $GIT_VERSION"
15+
16+
# run buildx ls to check that buildx is possible on this platform
17+
docker buildx ls > /dev/null 2>&1
18+
RETVAL=$?
19+
if [[ ${RETVAL} != 0 ]]; then
20+
echo "Invoking 'docker buildx ls' ends with non-zero exit code. (✖╭╮✖)"
21+
echo "Updated docker with experimental options enabled is required."
22+
exit 1
23+
fi
24+
25+
docker buildx build . -t "kudobuilder/kuttl:v$GIT_VERSION" --platform linux/amd64,linux/arm64,linux/ppc64le --push
26+
27+
RETVAL=$?
28+
if [[ ${RETVAL} != 0 ]]; then
29+
echo "Invoking 'docker buildx build' ends with non-zero exit code. (╯°□°)╯ ┻━┻"
30+
exit 1
31+
fi
32+
33+
echo "docker build and push was successful! ヽ(•‿•)ノ"

0 commit comments

Comments
 (0)