Skip to content

Commit

Permalink
Build multi-arch docker images (#944)
Browse files Browse the repository at this point in the history
* Allow building docker image with different platform

This allow to build the correct image when host plateform is not amd64.
Related doc : https://docs.docker.com/build/building/multi-platform/

* Update docker-image GHA workflow to build multi-arch docker images

* Add bits of documentation about multi-platform images

---------

Co-authored-by: Alessandro De Maria <ademaria@isomorphiclabs.com>
Co-authored-by: Ricardo Amaro <ricardo.amaro@gmail.com>
  • Loading branch information
3 people committed Mar 2, 2023
1 parent 18f3517 commit 5406935
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Setup QEMU and Buildx to build multi-platform image
# This was inspired by this example : https://docs.docker.com/build/ci/github-actions/examples/#multi-platform-images
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build PR/versioned tags
if: github.ref != 'refs/heads/master'
uses: docker/build-push-action@v2
with:
tags: kapicorp/kapitan:${{ format('{0}', env.REF_NAME ) }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }} # push image only on non-pull_requests
file: Dockerfile
# TODO push and tag as latest if release (and not RC)
Expand All @@ -53,6 +61,7 @@ jobs:
if: github.ref == 'refs/heads/master'
with:
tags: kapicorp/kapitan:${{ format('{0}', env.REF_NAME ) }},kapicorp/kapitan:latest
platforms: linux/amd64,linux/arm64
file: Dockerfile
- name: Test Dockerfile in current ref
run: |
Expand All @@ -63,4 +72,5 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
with:
tags: kapicorp/kapitan:${{ format('{0}', env.MAJOR_VERSION ) }}
platforms: linux/amd64,linux/arm64
file: Dockerfile
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Build the virtualenv for Kapitan
FROM python:3.7-slim AS python-builder

ARG TARGETARCH

RUN mkdir /kapitan
WORKDIR /kapitan

Expand All @@ -18,7 +20,7 @@ RUN apt-get update \
build-essential

# Install Go (for go-jsonnet)
RUN curl -fsSL -o go.tar.gz https://go.dev/dl/go1.17.3.linux-amd64.tar.gz \
RUN curl -fsSL -o go.tar.gz https://go.dev/dl/go1.17.3.linux-${TARGETARCH}.tar.gz \
&& tar -C /usr/local -xzf go.tar.gz \
&& rm go.tar.gz

Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Releases](https://img.shields.io/github/release/kapicorp/kapitan.svg)](https://github.com/kapicorp/kapitan/releases)
[![Docker Image Size](https://img.shields.io/docker/image-size/kapicorp/kapitan/latest.svg)](https://hub.docker.com/r/kapicorp/kapitan)

<img src="docs/images/kapitan_logo.png" width="25">
<img src="docs/images/kapitan_logo.png" width="25">


**`Kapitan`** aims to be your *one-stop tool* to help you manage the ever growing complexity of your configurations.
Expand Down Expand Up @@ -53,6 +53,14 @@ System-wide (not recommended):
sudo pip3 install --upgrade kapitan
```

## Build Kapitan

### Docker

To build a docker image for the architecture of your machine, run `docker build . -t you-kapitan-image`, and to build for a specific platform, add `--platform linux/arm64`.

To build a multi-platform image (as the CI does), follow [the docker multi-platform documentation](https://docs.docker.com/build/building/multi-platform/).

## Related projects

* [Tesoro](https://github.com/kapicorp/tesoro) - Kubernetes Admission Controller for Kapitan Secrets
Expand Down

0 comments on commit 5406935

Please sign in to comment.