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

ci: build multi arch images with buildx #336

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 37 additions & 0 deletions .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build Image

on:
push:
branches:
- 'master'
tags:
- "*"

jobs:
bake:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
buildkitd-flags: --debug
config-inline: |
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
- name: Build image
run: |
make docker
Copy link

@linki linki May 17, 2022

Choose a reason for hiding this comment

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

You could try using the build-and-push action to have it deal with all the buildx stuff. Here's an example that worked for me: https://github.com/linki/chaoskube/blob/1d44a96fd6f71d75dbcbf96f5a5a4b198913bcf1/.github/workflows/container-image.yml#L52-L59

Copy link

Choose a reason for hiding this comment

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

@linki can this be done as a separate PR? would appreciate if 0.11.0 multi-arch was published

Copy link

Choose a reason for hiding this comment

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

@tburko Yes, sure 👍

- name: Login to DockerHub
uses: docker/login-action@v1
if: ${{ startsWith(github.ref, 'refs/tags/') }}
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Pubish to Dockerhub
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
make release
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
FROM golang:1.16.0 AS BUILDER
FROM --platform=$TARGETPLATFORM golang:1.16.0 AS BUILDER

ARG TARGETPLATFORM
ARG TARGETARCH
ARG BUILDPLATFORM

WORKDIR /go/src/github.com/jtblin/kube2iam
ENV ARCH=linux
ENV CGO_ENABLED=0
COPY . ./
RUN make setup && make build

FROM alpine:3.14.3
FROM --platform=$TARGETPLATFORM alpine:3.14.3
Copy link

Choose a reason for hiding this comment

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

@rr-nick-tan I think you can remove all your changes in this file. When the image is built by buildx it should automatically pick up the correct variant for the target platform. Maybe you can give it a try?

RUN apk --no-cache add \
ca-certificates \
iptables
Expand Down
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ GIT_HASH := $$(git rev-parse --short HEAD)
GOBUILD_VERSION_ARGS := -ldflags "-s -X $(VERSION_VAR)=$(REPO_VERSION) -X $(GIT_VAR)=$(GIT_HASH) -X $(BUILD_DATE_VAR)=$(BUILD_DATE)"
# useful for other docker repos
DOCKER_REPO ?= jtblin
CPU_ARCH ?= amd64
IMAGE_NAME := $(DOCKER_REPO)/$(BINARY_NAME)-$(CPU_ARCH)
CPU_ARCH ?= linux/arm64/v8,linux/amd64
IMAGE_NAME := $(DOCKER_REPO)/$(BINARY_NAME)
MANIFEST_NAME := $(DOCKER_REPO)/$(BINARY_NAME)
ARCH ?= darwin
GOLANGCI_LINT_VERSION ?= v1.23.8
Expand Down Expand Up @@ -74,16 +74,14 @@ check-all:
travis-checks: build test-race check bench-race

docker:
docker build -t $(IMAGE_NAME):$(GIT_HASH) . $(DOCKER_BUILD_FLAGS)
docker buildx build --progress=plain --platform $(CPU_ARCH) -t $(IMAGE_NAME):$(GIT_HASH) . $(DOCKER_BUILD_FLAGS)

docker-dev: docker
docker tag $(IMAGE_NAME):$(GIT_HASH) $(IMAGE_NAME):dev
docker push $(IMAGE_NAME):dev

release: check test docker
docker push $(IMAGE_NAME):$(GIT_HASH)
docker tag $(IMAGE_NAME):$(GIT_HASH) $(IMAGE_NAME):$(REPO_VERSION)
docker push $(IMAGE_NAME):$(REPO_VERSION)
docker buildx build --push --progress=plain --platform $(CPU_ARCH) -t $(IMAGE_NAME):$(GIT_HASH) . $(DOCKER_BUILD_FLAGS)
ifeq (, $(findstring -rc, $(REPO_VERSION)))
docker tag $(IMAGE_NAME):$(GIT_HASH) $(IMAGE_NAME):latest
docker push $(IMAGE_NAME):latest
Expand Down