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

Multi-Arch Docker Image Releases #214

Merged
merged 4 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
27 changes: 27 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Docker Releases

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/) which KUTTL provides additional test features. The following architectures are needed to support scorecard:

* linux/amd64
* linux/arm64
* linux/ppc64le
* linux/s390x

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 it's pull request.

In addition to using `buildx` there are two more requirements to make this work:

1. The base image must support all the architectures desired. For this reason we now use `registry.access.redhat.com/ubi8/ubi-minimal`.
1. The go libraries must support the architectures.

## Building and Pushing Multi-Arch Docker Image

For a detailed understanding, please read the [buildx build documentation](https://docs.docker.com/engine/reference/commandline/buildx_build/).
You will need to `enable` docker CLI experimental features for this to work.

To build and push manually the following is necessary: `make docker-release`

This will result in a command similar to the following with the version tag replaced with the current version:
`docker buildx build . -t kudobuilder/kuttl:v0.6.1 --platform linux/amd64,linux/arm64,linux/ppc64le --push`

Updates for platform builds are maintained in [hack/docker-release.sh](hack/docker-release.sh).
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ RUN go get -d -v ./...
RUN make cli

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

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

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

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

Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ clean: cli-clean ## Cleans CLI and kind logs
rm -rf kind-logs-*

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

.PHONY: docker-release
# build and push a multi-arch docker image
docker-release: ## Build and push multi-arch docker images
./hack/docker-release.sh


# Install CLI
cli-install: ## Installs kubectl-kuttl to GOBIN
go install -ldflags "${LDFLAGS}" ./cmd/kubectl-kuttl
Expand Down
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ The release process is:
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`
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`.

### Docker Release

The docker release is accomplished by `make docker-release`. Details on what is required are provided in [Docker.md](DOCKER.md).

### Cutting a Release Branch

Expand Down
28 changes: 28 additions & 0 deletions hack/docker-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

#####
# Used to produce a multi-arch docker image and push it onto docker hub
# This requires the use of the buildx experimental feature in the later version of docker
#####

set -o nounset
set -o pipefail
# intentionally not setting 'set -o errexit' because we want to print custom error messages

GIT_VERSION="$(git describe --abbrev=0 --tags | cut -b 2-)"

echo "Releasing for version: $GIT_VERSION"

# run buildx ls to check that buildx is possible on this platform
docker buildx ls > /dev/null 2>&1
RETVAL=$?
if [[ ${RETVAL} != 0 ]]; then
echo "Invoking 'docker buildx ls' ends with non-zero exit code."
echo "Updated docker with experimental options enabled is required."
exit 1
fi

docker buildx build . -t "kudobuilder/kuttl:v$GIT_VERSION" --platform linux/amd64,linux/arm64,linux/ppc64le --push

echo "docker build and push was successful! ヽ(•‿•)ノ"
Copy link
Member

Choose a reason for hiding this comment

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

Well, we have no idea whether it was, because we don't check docker buildx exit code 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

ha... thank you sir!

exit 0
Copy link
Member

Choose a reason for hiding this comment

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

This line is not really needed with set +e