Skip to content

Commit b2384c5

Browse files
authored
Merge pull request #223 from j-fuentes/multiarch
Move to Github actions and add support for arm
2 parents ae78751 + d836c1f commit b2384c5

File tree

6 files changed

+232
-62
lines changed

6 files changed

+232
-62
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# if changing this name, also update promotion.yaml
2+
name: release-master
3+
4+
on:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
golint:
11+
name: vet fmt and lint
12+
runs-on: ubuntu-20.04
13+
container: golang:1.13.7
14+
steps:
15+
- uses: actions/[email protected]
16+
- name: Install golint
17+
run: go get -u golang.org/x/lint/golint
18+
- run: make lint
19+
shell: bash
20+
gotest:
21+
name: go test
22+
runs-on: ubuntu-20.04
23+
container: golang:1.13.7
24+
steps:
25+
- uses: actions/[email protected]
26+
- run: make test
27+
docker_build:
28+
name: docker_build
29+
runs-on: ubuntu-20.04
30+
container:
31+
image: docker:20.10.5
32+
options: -t
33+
# Setting up dind service container
34+
services:
35+
docker:
36+
image: docker:20.10.5-dind
37+
env:
38+
DOCKER_DRIVER: overlay
39+
DOCKER_HOST: tcp://localhost:2375
40+
steps:
41+
- name: Install Tools
42+
run: apk add --update make git jq rsync curl
43+
- uses: actions/[email protected]
44+
- name: Set up QEMU
45+
uses: docker/setup-qemu-action@v1
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v1
48+
- name: Login to registry
49+
uses: docker/login-action@v1
50+
with:
51+
registry: quay.io
52+
username: ${{ secrets.QUAY_USER }}
53+
password: ${{ secrets.QUAY_PASSWORD }}
54+
- name: Build and push
55+
run: make push-docker-image
56+
- name: Tag
57+
run: make create-docker-image-tag NEW_TAG=canary

.github/workflows/release-tag.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# if changing this name, also update promotion.yaml
2+
name: release-tag
3+
4+
on:
5+
push:
6+
tags:
7+
- v*
8+
9+
jobs:
10+
docker_tag:
11+
name: docker_build
12+
runs-on: ubuntu-20.04
13+
container:
14+
image: docker:20.10.5
15+
options: -t
16+
# Setting up dind service container
17+
services:
18+
docker:
19+
image: docker:20.10.5-dind
20+
env:
21+
DOCKER_DRIVER: overlay
22+
DOCKER_HOST: tcp://localhost:2375
23+
steps:
24+
- name: Install Tools
25+
run: apk add --update make git jq rsync curl
26+
- uses: actions/[email protected]
27+
- name: Capture tag in env
28+
run: echo "TAG_LABEL=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v1
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v1
33+
- name: Login to registry
34+
uses: docker/login-action@v1
35+
with:
36+
registry: quay.io
37+
username: ${{ secrets.QUAY_USER }}
38+
password: ${{ secrets.QUAY_PASSWORD }}
39+
- name: Tag latest
40+
run: make create-docker-image-tag NEW_TAG=latest
41+
- name: Tag with git tag
42+
run: make create-docker-image-tag NEW_TAG=${{ env.TAG_LEVEL }}

.github/workflows/test.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# if changing this name, also update promotion.yaml
2+
name: test
3+
4+
on:
5+
push:
6+
branches-ignore:
7+
- master
8+
pull_request:
9+
branches:
10+
- "*"
11+
12+
jobs:
13+
golint:
14+
name: vet fmt and lint
15+
runs-on: ubuntu-20.04
16+
container: golang:1.13.7
17+
steps:
18+
- uses: actions/[email protected]
19+
- name: Install golint
20+
run: go get -u golang.org/x/lint/golint
21+
- run: make lint
22+
shell: bash
23+
gotest:
24+
name: go test
25+
runs-on: ubuntu-20.04
26+
container: golang:1.13.7
27+
steps:
28+
- uses: actions/[email protected]
29+
- run: make test
30+
docker_build:
31+
name: docker_build
32+
runs-on: ubuntu-20.04
33+
container:
34+
image: docker:20.10.5
35+
options: -t
36+
# Setting up dind service container
37+
services:
38+
docker:
39+
image: docker:20.10.5-dind
40+
env:
41+
DOCKER_DRIVER: overlay
42+
DOCKER_HOST: tcp://localhost:2375
43+
steps:
44+
- name: Install Tools
45+
run: apk add --update make git jq rsync curl
46+
- uses: actions/[email protected]
47+
- name: Set up QEMU
48+
uses: docker/setup-qemu-action@v1
49+
- name: Set up Docker Buildx
50+
uses: docker/setup-buildx-action@v1
51+
- name: Build images
52+
run: make build-docker-image

Dockerfile

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
1-
# STAGE 1
2-
FROM golang:1.13.4 as builder
3-
4-
WORKDIR /go/github.com/jetstack/preflight
5-
6-
# Run a dependency resolve with just the go mod files present for
7-
# better caching
8-
COPY ./go.mod .
9-
COPY ./go.sum .
10-
11-
RUN go mod download
12-
13-
## Bring in everything else and build an amd64 image
14-
COPY . .
15-
16-
ARG oauth_client_id
17-
ARG oauth_client_secret
18-
ARG oauth_auth_server_domain
1+
FROM gcr.io/distroless/base:nonroot
192

20-
RUN make install \
21-
OAUTH_CLIENT_ID=${oauth_client_id} \
22-
OAUTH_CLIENT_SECRET=${oauth_client_secret} \
23-
OAUTH_AUTH_SERVER_DOMAIN=${oauth_auth_server_domain}
3+
# TARGETPLATFORM comes from the buildx context and it will be something like `linux/arm64/v8` or `linux/amd64`.
4+
# Ref: https://docs.docker.com/buildx/working-with-buildx/
5+
ARG TARGETPLATFORM
246

25-
# STAGE 2
26-
# Use a distroless nonroot base image for just our executable
27-
FROM gcr.io/distroless/base:nonroot
28-
COPY --from=builder /go/bin/preflight /bin/preflight
7+
COPY ./builds/${TARGETPLATFORM}/preflight /bin/preflight
298
# load in an example config file
309
ADD ./agent.yaml /etc/preflight/agent.yaml
3110
ENTRYPOINT ["preflight"]

Makefile

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ GOVERSION:=$(shell go version | awk '{print $$3 " " $$4}')
77
GOOS:=$(shell go env GOOS)
88
GOARCH:=$(shell go env GOARCH)
99

10+
BIN_NAME:=preflight
11+
1012
DOCKER_IMAGE?=quay.io/jetstack/preflight
11-
DOCKER_IMAGE_TAG?=$(DOCKER_IMAGE):$(VERSION)
13+
DOCKER_IMAGE_TAG?=$(DOCKER_IMAGE):$(COMMIT)
14+
15+
# BUILD_IN decides if the binaries will be built in `docker` or in the `host`.
16+
BUILD_IN?=docker
1217

1318
# OAuth2 config for the agent to work with platform.jetstack.io
1419
OAUTH_CLIENT_ID?=k3TrDbfLhCgnpAbOiiT2kIE1AbovKzjo
@@ -52,57 +57,69 @@ vet:
5257
lint: vet
5358
cd $(ROOT_DIR) && golint
5459

55-
.PHONY: ./builds/preflight-$(GOOS)-$(GOARCH)
56-
./builds/preflight-$(GOOS)-$(GOARCH):
57-
GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO_BUILD) -o ./builds/preflight-$(GOOS)-$(GOARCH) .
58-
59-
build-all-platforms:
60-
$(MAKE) GOOS=linux GOARCH=amd64 ./builds/preflight-linux-amd64
61-
$(MAKE) GOOS=darwin GOARCH=amd64 ./builds/preflight-darwin-amd64
62-
$(MAKE) GOOS=windows GOARCH=amd64 ./builds/preflight-windows-amd64
6360

64-
# Bundles
65-
66-
./bundles/preflight-bundle-$(GOOS)-$(GOARCH).tgz: ./builds/preflight-$(GOOS)-$(GOARCH)
67-
cd $(ROOT_DIR) && \
68-
mkdir -p ./bundles && \
69-
tar --transform "s/builds\/preflight-$(GOOS)-$(GOARCH)/preflight/" -rvf $@.tmp $< && \
70-
gzip < $@.tmp > $@ && \
71-
rm $@.tmp
72-
73-
bundle-all-platforms:
74-
$(MAKE) GOOS=linux GOARCH=amd64 ./bundles/preflight-bundle-linux-amd64.tgz
75-
$(MAKE) GOOS=darwin GOARCH=amd64 ./bundles/preflight-bundle-darwin-amd64.tgz
76-
$(MAKE) GOOS=windows GOARCH=amd64 ./bundles/preflight-bundle-windows-amd64.tgz
61+
.PHONY: ./builds/$(GOOS)/$(GOARCH)/$(BIN_NAME)
62+
./builds/$(GOOS)/$(GOARCH)/$(BIN_NAME):
63+
GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO_BUILD) -o ./builds/$(GOOS)/$(GOARCH)/$(BIN_NAME) .
64+
.PHONY: ./builds/$(GOOS)/$(GOARCH)/v$(GOARM)/$(BIN_NAME)
65+
./builds/$(GOOS)/$(GOARCH)/v$(GOARM)/$(BIN_NAME):
66+
GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) $(GO_BUILD) -o ./builds/$(GOOS)/$(GOARCH)/v$(GOARM)/$(BIN_NAME) .
67+
68+
build-all-platforms: build-all-platforms-in-$(BUILD_IN)
69+
70+
build-all-platforms-in-host:
71+
$(MAKE) GOOS=linux GOARCH=amd64 ./builds/linux/amd64/$(BIN_NAME)
72+
$(MAKE) GOOS=linux GOARCH=arm64 ./builds/linux/arm64/$(BIN_NAME)
73+
$(MAKE) GOOS=linux GOARCH=arm GOARM=7 ./builds/linux/arm/v7/$(BIN_NAME)
74+
$(MAKE) GOOS=darwin GOARCH=amd64 ./builds/darwin/amd64/$(BIN_NAME)
75+
$(MAKE) GOOS=windows GOARCH=amd64 ./builds/windows/amd64/$(BIN_NAME)
76+
77+
build-all-platforms-in-docker:
78+
rm -rf ./builds
79+
docker build --rm -t preflight-bin -f ./builder.dockerfile \
80+
--build-arg oauth_client_id=$(OAUTH_CLIENT_ID) \
81+
--build-arg oauth_client_secret=$(OAUTH_CLIENT_SECRET) \
82+
--build-arg oauth_auth_server_domain=$(OAUTH_AUTH_SERVER_DOMAIN) \
83+
.
84+
docker create --rm --name=preflight-bin-container preflight-bin
85+
docker cp preflight-bin-container:/go/github.com/jetstack/preflight/builds ./builds
86+
docker rm preflight-bin-container
87+
docker rmi preflight-bin
7788

7889
# Docker image
79-
80-
build-docker-image:
81-
docker build --tag $(DOCKER_IMAGE_TAG) \
82-
--build-arg oauth_client_id=$(OAUTH_CLIENT_ID) \
83-
--build-arg oauth_client_secret=$(OAUTH_CLIENT_SECRET) \
84-
--build-arg oauth_auth_server_domain=$(OAUTH_AUTH_SERVER_DOMAIN) \
90+
PLATFORMS?=linux/arm/v7,linux/arm64/v8,linux/amd64
91+
BUILDX_EXTRA_ARGS?=
92+
93+
push_buildx_args=--push $(BUILDX_EXTRA_ARGS)
94+
push-canary_buildx_args=--tag $(DOCKER_IMAGE):canary --push $(BUILDX_EXTRA_ARGS)
95+
build_buildx_args=$(BUILDX_EXTRA_ARGS)
96+
97+
.PHONY: _docker-%
98+
_docker-%: build-all-platforms
99+
docker buildx build --platform $(PLATFORMS) \
100+
--tag $(DOCKER_IMAGE_TAG) \
101+
$($*_buildx_args) \
85102
.
86103

87-
push-docker-image:
88-
docker tag $(DOCKER_IMAGE_TAG) $(DOCKER_IMAGE):latest
89-
docker push $(DOCKER_IMAGE_TAG)
90-
docker push $(DOCKER_IMAGE):latest
104+
build-docker-image: _docker-build
105+
push-docker-image: _docker-push
91106

92-
push-docker-image-canary:
93-
docker tag $(DOCKER_IMAGE_TAG) $(DOCKER_IMAGE):canary
94-
docker push $(DOCKER_IMAGE_TAG)
95-
docker push $(DOCKER_IMAGE):canary
107+
NEW_TAG?=latest
108+
create-docker-image-tag:
109+
docker buildx imagetools create $(DOCKER_IMAGE):$(COMMIT) --tag $(DOCKER_IMAGE):$(NEW_TAG)
96110

97111
# CI
98112

99113
export PATH:=$(GOPATH)/bin:$(PATH)
100114

101115
ci-deps:
116+
echo "ci-deps is going to be disabled. We are adopting Github actions"
102117
go install golang.org/x/lint/golint
103118

104119
ci-test: ci-deps test lint
105120

106121
ci-build: ci-test build build-docker-image build-all-platforms bundle-all-platforms push-docker-image-canary
122+
echo "ci-build is going to be disabled. We are adopting Github actions"
107123

108124
ci-publish: ci-build push-docker-image
125+
echo "ci-publish is going to be disabled. We are adopting Github actions"

builder.dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM golang:1.13.4 as builder
2+
3+
WORKDIR /go/github.com/jetstack/preflight
4+
5+
# Run a dependency resolve with just the go mod files present for
6+
# better caching
7+
COPY ./go.mod .
8+
COPY ./go.sum .
9+
10+
RUN go mod download
11+
12+
## Bring in everything else
13+
COPY . .
14+
15+
ARG oauth_client_id
16+
ARG oauth_client_secret
17+
ARG oauth_auth_server_domain
18+
19+
RUN make build-all-platforms \
20+
BUILD_IN=host \
21+
OAUTH_CLIENT_ID=${oauth_client_id} \
22+
OAUTH_CLIENT_SECRET=${oauth_client_secret} \
23+
OAUTH_AUTH_SERVER_DOMAIN=${oauth_auth_server_domain}

0 commit comments

Comments
 (0)