Skip to content

Commit dfc8726

Browse files
committed
build: multi-arch builds
1 parent 14a623c commit dfc8726

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

.github/dependabot.yml

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
# https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates
55
version: 2
66
updates:
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "daily"
11+
712
- package-ecosystem: "gomod"
813
directory: "/"
914
schedule:

.github/workflows/build-image.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: build-image
2+
3+
on:
4+
push:
5+
branches:
6+
- "*"
7+
tags:
8+
- "v*"
9+
10+
jobs:
11+
buildx:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
with:
16+
submodules: true
17+
18+
- uses: actions/setup-go@v2
19+
with:
20+
go-version: ^1.15
21+
22+
- uses: docker/setup-qemu-action@v1
23+
- uses: docker/setup-buildx-action@v1
24+
with:
25+
driver-opts: network=host
26+
27+
- id: prepare
28+
name: Build binaries && Prepare
29+
env:
30+
GITHUB_REF: ${{ github.sha }}
31+
GITHUB_SHA: ${{ github.ref }}
32+
# for other platforms support only need to updates
33+
TARGET_PLATFORMS: linux/amd64,linux/arm64
34+
TARGET_ARCHS: amd64 arm64
35+
run: |-
36+
make code/compilex TARGET_ARCHS="${TARGET_ARCHS}" COMPILE_TARGET=./build/_output/bin/grafana-operator
37+
38+
file build/_output/bin/*
39+
40+
export TAG=${GITHUB_SHA::7}
41+
42+
if [[ ${{ github.ref }} == "refs/tags/v"* ]]; then
43+
TAG=$(echo ${{ github.ref }} | sed -e "s/refs\/tags\///")
44+
fi
45+
46+
echo ::set-output name=target_platforms::${TARGET_PLATFORMS}
47+
echo ::set-output name=tag::${TAG}
48+
49+
- uses: docker/login-action@v1
50+
name: Login docker.io
51+
with:
52+
password: ${{ secrets.DOCKER_PASSWORD }}
53+
registry: docker.io
54+
username: ${{ secrets.DOCKER_USERNAME }}
55+
56+
- uses: docker/login-action@v1
57+
name: Login quay.io
58+
with:
59+
password: ${{ secrets.QUAY_PASSWORD }}
60+
registry: quay.io
61+
username: ${{ secrets.QUAY_USERNAME }}
62+
63+
- uses: docker/build-push-action@v2
64+
name: Build image && May Push
65+
with:
66+
file: build/Dockerfile
67+
context: .
68+
labels: |-
69+
org.opencontainers.image.source=https://github.com/${{ github.repository }}
70+
org.opencontainers.image.revision=${{ github.sha }}
71+
platforms: ${{ steps.prepare.outputs.target_platforms }}
72+
push: ${{ github.event_name != 'pull_request' }}
73+
tags: |
74+
docker.io/${{ github.repository }}:${{ steps.prepare.outputs.tag }}
75+
quay.io/integreatly/grafana-operator:${{ steps.prepare.outputs.tag }}

Makefile

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ TAG?=latest
77
PKG=github.com/integr8ly/grafana-operator
88
COMPILE_TARGET=./tmp/_output/bin/$(PROJECT)
99

10+
GOOS?=$(go env GOOS)
11+
GOARCH?=$(go env GOARCH)
12+
13+
# list for multi-arch image publishing
14+
TARGET_ARCHS ?= amd64 arm64
15+
1016
.PHONY: setup/travis
1117
setup/travis:
1218
@echo Installing Operator SDK
@@ -18,7 +24,13 @@ code/run:
1824

1925
.PHONY: code/compile
2026
code/compile:
21-
@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o=$(COMPILE_TARGET) ./cmd/manager
27+
@GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -o=$(COMPILE_TARGET)-$(GOARCH) ./cmd/manager
28+
29+
.PHONY: code/compilex
30+
code/compilex:
31+
@for arch in $(TARGET_ARCHS); do \
32+
GOOS=linux GOARCH=$${arch} $(MAKE) code/compile; \
33+
done
2234

2335
.PHONY: code/gen
2436
code/gen:

build/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ USER nobody
66

77
ADD grafonnet-lib/grafonnet/ /opt/jsonnet/grafonnet
88

9-
ADD build/_output/bin/grafana-operator /usr/local/bin/grafana-operator
9+
ARG TARGETARCH
10+
ADD build/_output/bin/grafana-operator-${TARGETARCH:-amd64} /usr/local/bin/grafana-operator

0 commit comments

Comments
 (0)