Skip to content

Commit

Permalink
ci: build multi arch images with buildx
Browse files Browse the repository at this point in the history
  • Loading branch information
rr-nick-tan committed Mar 7, 2022
1 parent 23686dd commit 319e1e3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
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
- 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
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

0 comments on commit 319e1e3

Please sign in to comment.