Skip to content

Commit a390f86

Browse files
committed
setup multi-arch builds with goreleaser
Signed-off-by: Joe Lanford <[email protected]>
1 parent 78f27b3 commit a390f86

File tree

8 files changed

+327
-54
lines changed

8 files changed

+327
-54
lines changed

.github/workflows/goreleaser.yaml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: goreleaser
2+
on:
3+
push:
4+
branches:
5+
- 'master'
6+
tags:
7+
- 'v[0-9]+.[0-9]+.[0-9]+'
8+
pull_request: {}
9+
defaults:
10+
run:
11+
shell: bash
12+
jobs:
13+
goreleaser:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
with:
18+
# GoReleaser requires fetch-depth: 0 for
19+
# changelog generation to work correctly.
20+
fetch-depth: 0
21+
22+
- uses: actions/setup-go@v2
23+
with:
24+
go-version: '~1.16'
25+
26+
- name: "Download osxcross cross-compiler for macOS builds"
27+
run: |
28+
git clone https://github.com/tpoechtrager/osxcross /tmp/osxcross
29+
cd /tmp/osxcross
30+
wget -P tarballs '<REPLACE_ME_WITH_SECRET_PATH_TO_MACOS_SDK>'
31+
echo "/tmp/osxcross/target/bin" >> $GITHUB_PATH
32+
33+
- name: "Cache the osxcross + tarball build output"
34+
id: cache-osxcross
35+
uses: actions/cache@v2
36+
with:
37+
path: /tmp/osxcross/target
38+
key: ${{ runner.os }}-osxcross-${{ hashFiles('/tmp/osxcross/**/*') }}
39+
restore-keys: |
40+
${{ runner.os }}-osxcross-
41+
42+
- name: "Build osxcross"
43+
if: steps.cache-osxcross.outputs.cache-hit != 'true'
44+
run: |
45+
cd /tmp/osxcross
46+
sudo ./tools/get_dependencies.sh
47+
UNATTENDED=1 ./build.sh
48+
49+
- name: "Install linux cross-compilers"
50+
run: sudo apt-get install -y gcc-aarch64-linux-gnu gcc-s390x-linux-gnu gcc-powerpc64le-linux-gnu gcc-mingw-w64-x86-64
51+
52+
- name: "Install yq"
53+
run: |
54+
sudo wget https://github.com/mikefarah/yq/releases/download/v4.10.0/yq_linux_amd64 -O /usr/local/bin/yq
55+
sudo chmod +x /usr/local/bin/yq
56+
57+
- name: "Disable image pushes for pull requests"
58+
if: github.event_name == 'pull_request'
59+
run: |
60+
yq eval '.dockers[].skip_push=true' -i .goreleaser.yaml
61+
yq eval '.docker_manifests[].skip_push=true' -i .goreleaser.yaml
62+
63+
- name: "Disable the Github release upload for non-tag builds"
64+
if: startsWith(github.ref, 'refs/tags') != true
65+
run: |
66+
yq eval '.release.disable=true' -i .goreleaser.yaml
67+
68+
- name: "Set the image tag"
69+
run: |
70+
if [[ $GITHUB_REF == refs/tags/* ]]; then
71+
# Release tags.
72+
echo IMAGE_TAG="${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
73+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
74+
# Branch build.
75+
echo IMAGE_TAG="$(echo "${GITHUB_REF#refs/heads/}" | sed -r 's|/+|-|g')" >> $GITHUB_ENV
76+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
77+
# PR build.
78+
echo IMAGE_TAG="pr-$(echo "${GITHUB_REF}" | sed -E 's|refs/pull/([^/]+)/?.*|\1|')" >> $GITHUB_ENV
79+
else
80+
echo IMAGE_TAG="$(git describe --tags --always)" >> $GITHUB_ENV
81+
fi
82+
83+
- name: "Login to Quay"
84+
if: github.event_name != 'pull_request'
85+
uses: docker/login-action@v1
86+
with:
87+
username: ${{ secrets.QUAY_USERNAME }}
88+
password: ${{ secrets.QUAY_PASSWORD }}
89+
registry: quay.io
90+
91+
92+
- name: "Run GoReleaser"
93+
run: make release
94+
env:
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
RELEASE_ARGS: release --rm-dist ${{ !startsWith(github.ref, 'refs/tags') && '--skip-validate' || '' }}

.github/workflows/release.yaml

Lines changed: 0 additions & 48 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ tags
181181
# Build results
182182
[Dd]ebug/
183183
[Dd]ebugPublic/
184-
[Rr]elease/
185-
[Rr]eleases/
186184
x64/
187185
x86/
188186
bld/

.goreleaser.yaml

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
builds:
2+
- id: linux-amd64
3+
main: ./cmd/opm
4+
binary: opm
5+
goos:
6+
- linux
7+
goarch:
8+
- amd64
9+
env:
10+
- CC=gcc
11+
mod_timestamp: "{{ .CommitTimestamp }}"
12+
flags: &build-flags
13+
- -tags=json1
14+
asmflags: &build-asmflags
15+
- all=-trimpath={{ .Env.PWD }}
16+
gcflags: &build-gcflags
17+
- all=-trimpath={{ .Env.PWD }}
18+
ldflags: &build-ldflags
19+
- -s -w
20+
- -X {{ .Env.PKG }}/cmd/opm/version.gitCommit={{ .Env.GIT_COMMIT }}
21+
- -X {{ .Env.PKG }}/cmd/opm/version.opmVersion={{ .Env.OPM_VERSION }}
22+
- -X {{ .Env.PKG }}/cmd/opm/version.buildDate={{ .Env.BUILD_DATE }}
23+
- id: linux-arm64
24+
main: ./cmd/opm
25+
binary: opm
26+
goos:
27+
- linux
28+
goarch:
29+
- arm64
30+
env:
31+
- CC=aarch64-linux-gnu-gcc
32+
mod_timestamp: "{{ .CommitTimestamp }}"
33+
flags: *build-flags
34+
asmflags: *build-asmflags
35+
gcflags: *build-gcflags
36+
ldflags: *build-ldflags
37+
- id: linux-ppc64le
38+
main: ./cmd/opm
39+
binary: opm
40+
goos:
41+
- linux
42+
goarch:
43+
- ppc64le
44+
env:
45+
- CC=powerpc64le-linux-gnu-gcc
46+
mod_timestamp: "{{ .CommitTimestamp }}"
47+
flags: *build-flags
48+
asmflags: *build-asmflags
49+
gcflags: *build-gcflags
50+
ldflags: *build-ldflags
51+
- id: linux-s390x
52+
main: ./cmd/opm
53+
binary: opm
54+
goos:
55+
- linux
56+
goarch:
57+
- s390x
58+
env:
59+
- CC=s390x-linux-gnu-gcc
60+
mod_timestamp: "{{ .CommitTimestamp }}"
61+
flags: *build-flags
62+
asmflags: *build-asmflags
63+
gcflags: *build-gcflags
64+
ldflags: *build-ldflags
65+
- id: windows-amd64
66+
main: ./cmd/opm
67+
binary: opm
68+
goos:
69+
- windows
70+
goarch:
71+
- amd64
72+
env:
73+
- CC=x86_64-w64-mingw32-gcc-posix
74+
mod_timestamp: "{{ .CommitTimestamp }}"
75+
flags: *build-flags
76+
asmflags: *build-asmflags
77+
gcflags: *build-gcflags
78+
ldflags: *build-ldflags
79+
- id: darwin-amd64
80+
main: ./cmd/opm
81+
binary: opm
82+
goos:
83+
- darwin
84+
goarch:
85+
- amd64
86+
env:
87+
- CC=o64-clang
88+
mod_timestamp: "{{ .CommitTimestamp }}"
89+
flags: *build-flags
90+
asmflags: *build-asmflags
91+
gcflags: *build-gcflags
92+
ldflags: *build-ldflags
93+
- id: darwin-arm64
94+
main: ./cmd/opm
95+
binary: opm
96+
goos:
97+
- darwin
98+
goarch:
99+
- arm64
100+
env:
101+
- CC=oa64e-clang
102+
mod_timestamp: "{{ .CommitTimestamp }}"
103+
flags: *build-flags
104+
asmflags: *build-asmflags
105+
gcflags: *build-gcflags
106+
ldflags: *build-ldflags
107+
archives:
108+
- id: opm
109+
builds:
110+
- linux-amd64
111+
- linux-arm64
112+
- linux-ppc64le
113+
- linux-s390x
114+
- windows-amd64
115+
- darwin-amd64
116+
- darwin-arm64
117+
name_template: "{{ .Binary }}_{{ .Env.OPM_VERSION }}_{{ .Os }}_{{ .Arch }}"
118+
format: binary
119+
dockers:
120+
- image_templates:
121+
- "{{ .Env.OPM_IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-amd64"
122+
ids: ["linux-amd64"]
123+
goos: linux
124+
goarch: amd64
125+
dockerfile: release/goreleaser.opm.Dockerfile
126+
extra_files: ["nsswitch.conf"]
127+
use: buildx
128+
build_flag_templates:
129+
- --platform=linux/amd64
130+
- image_templates:
131+
- "{{ .Env.OPM_IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-arm64"
132+
ids: ["linux-arm64"]
133+
goos: linux
134+
goarch: arm64
135+
dockerfile: release/goreleaser.opm.Dockerfile
136+
extra_files: ["nsswitch.conf"]
137+
use: buildx
138+
build_flag_templates:
139+
- --platform=linux/arm64
140+
- image_templates:
141+
- "{{ .Env.OPM_IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-ppc64le"
142+
ids: ["linux-ppc64le"]
143+
goos: linux
144+
goarch: ppc64le
145+
dockerfile: release/goreleaser.opm.Dockerfile
146+
extra_files: ["nsswitch.conf"]
147+
use: buildx
148+
build_flag_templates:
149+
- --platform=linux/ppc64le
150+
- image_templates:
151+
- "{{ .Env.OPM_IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-s390x"
152+
ids: ["linux-s390x"]
153+
goos: linux
154+
goarch: s390x
155+
dockerfile: release/goreleaser.opm.Dockerfile
156+
extra_files: ["nsswitch.conf"]
157+
use: buildx
158+
build_flag_templates:
159+
- --platform=linux/s390x
160+
docker_manifests:
161+
- name_template: "{{ .Env.OPM_IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}"
162+
image_templates:
163+
- "{{ .Env.OPM_IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-amd64"
164+
- "{{ .Env.OPM_IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-arm64"
165+
- "{{ .Env.OPM_IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-ppc64le"
166+
- "{{ .Env.OPM_IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-s390x"
167+
checksum:
168+
name_template: 'checksums.txt'
169+
snapshot:
170+
name_template: "{{ .Env.OPM_VERSION }}"
171+
release:
172+
name_template: "{{ .Env.OPM_VERSION }}"
173+
draft: true

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ GO := GOFLAGS="-mod=vendor" go
22
CMDS := $(addprefix bin/, $(shell ls ./cmd | grep -v opm))
33
OPM := $(addprefix bin/, opm)
44
SPECIFIC_UNIT_TEST := $(if $(TEST),-run $(TEST),)
5-
PKG := github.com/operator-framework/operator-registry
6-
GIT_COMMIT := $(or $(SOURCE_GIT_COMMIT),$(shell git rev-parse --short HEAD))
7-
OPM_VERSION := $(or $(SOURCE_GIT_TAG),$(shell git describe --always --tags HEAD))
8-
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
5+
export PKG := github.com/operator-framework/operator-registry
6+
export GIT_COMMIT := $(or $(SOURCE_GIT_COMMIT),$(shell git rev-parse --short HEAD))
7+
export OPM_VERSION := $(or $(SOURCE_GIT_TAG),$(shell git describe --always --tags HEAD))
8+
export BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
99

1010
# define characters
1111
null :=
@@ -114,3 +114,11 @@ clean:
114114
.PHONY: e2e
115115
e2e:
116116
$(GO) run github.com/onsi/ginkgo/ginkgo --v --randomizeAllSpecs --randomizeSuites --race $(if $(TEST),-focus '$(TEST)') $(TAGS) ./test/e2e -- $(if $(SKIPTLS),-skip-tls true)
117+
118+
119+
.PHONY: release
120+
export OPM_IMAGE_REPO ?= quay.io/operator-framework/opm
121+
export IMAGE_TAG ?= $(OPM_VERSION)
122+
release: RELEASE_ARGS?=release --rm-dist --snapshot
123+
release:
124+
./scripts/fetch goreleaser 0.173.2 && ./bin/goreleaser $(RELEASE_ARGS)

release/goreleaser.opm.Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# NOTE: This Dockerfile is used in conjuction with GoReleaser to
2+
# build opm images. See the configurations in .goreleaser.yaml
3+
# and .github/workflows/release.yaml.
4+
5+
FROM --platform=$BUILDPLATFORM ghcr.io/grpc-ecosystem/grpc-health-probe:v0.4.4 as grpc_health_probe
6+
FROM gcr.io/distroless/base:debug
7+
COPY --from=grpc_health_probe /grpc_health_probe /bin/grpc_health_probe
8+
COPY ["nsswitch.conf", "/etc/nsswitch.conf"]
9+
COPY opm /bin/opm
10+
ENTRYPOINT ["/bin/opm"]

scripts/fetch

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
ROOT="$( git rev-parse --show-toplevel )"
4+
5+
fetch() {
6+
local tool=$1; shift
7+
local ver=$1; shift
8+
9+
local ver_cmd=""
10+
local tool_fetch_cmd=""
11+
case "$tool" in
12+
"golangci-lint")
13+
ver_cmd="${ROOT}/bin/golangci-lint --version 2>/dev/null | cut -d\" \" -f4"
14+
fetch_cmd="curl -sSfL \"https://raw.githubusercontent.com/golangci/golangci-lint/v${ver}/install.sh\" | sh -s -- -b \"${ROOT}/bin\" \"v${ver}\""
15+
;;
16+
"goreleaser")
17+
ver_cmd="${ROOT}/bin/goreleaser --version 2>/dev/null | grep 'goreleaser version' | cut -d' ' -f3"
18+
fetch_cmd="curl -sSfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh -s -- -b \"${ROOT}/bin\" -d \"v${ver}\""
19+
;;
20+
*)
21+
echo "unknown tool $tool"
22+
return 1
23+
;;
24+
esac
25+
26+
if [[ "${ver}" != "$(eval ${ver_cmd})" ]]; then
27+
echo "${tool} missing or not version '${ver}', downloading..."
28+
eval ${fetch_cmd}
29+
fi
30+
}
31+
fetch $@

0 commit comments

Comments
 (0)