Skip to content

Commit eb0312c

Browse files
authored
Operator Controller Release (#133)
Adds a release github action and implements goreleaser, borrowing heavily from rukpak but stripped down a bit. Signed-off-by: dtfranz <[email protected]>
1 parent 07ae744 commit eb0312c

File tree

7 files changed

+168
-41
lines changed

7 files changed

+168
-41
lines changed

.dockerignore

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

.github/workflows/release.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- 'main'
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
branches:
12+
- main
13+
14+
jobs:
15+
goreleaser:
16+
name: goreleaser
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Check out code into the Go module directory
20+
uses: actions/checkout@v2
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Install Go
25+
uses: actions/setup-go@v3
26+
with:
27+
go-version-file: "go.mod"
28+
29+
- name: Docker Login
30+
if: ${{ github.event_name != 'pull_request' }}
31+
uses: docker/login-action@v1
32+
with:
33+
registry: quay.io
34+
username: ${{ secrets.QUAY_USERNAME }}
35+
password: ${{ secrets.QUAY_PASSWORD }}
36+
37+
- name: Set the release related variables
38+
run: |
39+
if [[ $GITHUB_REF == refs/tags/* ]]; then
40+
# Release tags.
41+
echo IMAGE_TAG="${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
42+
echo GORELEASER_ARGS="--rm-dist" >> $GITHUB_ENV
43+
echo DISABLE_RELEASE_PIPELINE=false >> $GITHUB_ENV
44+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
45+
# Branch build.
46+
echo IMAGE_TAG="$(echo "${GITHUB_REF#refs/heads/}" | sed -r 's|/+|-|g')" >> $GITHUB_ENV
47+
echo GORELEASER_ARGS="--rm-dist --skip-validate" >> $GITHUB_ENV
48+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
49+
# PR build.
50+
echo IMAGE_TAG="pr-$(echo "${GITHUB_REF}" | sed -E 's|refs/pull/([^/]+)/?.*|\1|')" >> $GITHUB_ENV
51+
else
52+
echo IMAGE_TAG="$(git describe --tags --always)" >> $GITHUB_ENV
53+
fi
54+
55+
- name: Generate the operator-controller release manifests
56+
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
57+
run: |
58+
make quickstart VERSION=${GITHUB_REF#refs/tags/}
59+
60+
- name: Run goreleaser
61+
run: make release
62+
env:
63+
GITHUB_TOKEN: ${{ github.token }}

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*.dll
66
*.so
77
*.dylib
8-
bin
8+
bin/*
99
testbin/*
1010
Dockerfile.cross
1111

@@ -15,6 +15,11 @@ Dockerfile.cross
1515
# Output of the go coverage tool, specifically when used with LiteIDE
1616
*.out
1717

18+
# Release output
19+
dist/**
20+
.goreleaser.yml
21+
operator-controller.yaml
22+
1823
# Kubernetes Generated files - skip generated files, except for vendored files
1924

2025
!vendor/**/zz_generated.*
@@ -24,3 +29,6 @@ Dockerfile.cross
2429
*.swp
2530
*.swo
2631
*~
32+
33+
# TODO dfranz remove this line and the bin folder when tools binaries are moved to their own folder
34+
!bin/.dockerignore

.goreleaser.template.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
env:
2+
- GOPROXY=https://proxy.golang.org|direct
3+
- GO111MODULE=on
4+
- CGO_ENABLED=0
5+
before:
6+
hooks:
7+
- go mod tidy
8+
- go mod download
9+
builds:
10+
- id: operator-controller
11+
main: ./
12+
binary: bin/manager
13+
tags: $GO_BUILD_TAGS
14+
goos:
15+
- linux
16+
ldflags:
17+
- -X main.Version={{ .Version }}
18+
dockers:
19+
- image_templates:
20+
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}"
21+
dockerfile: Dockerfile
22+
goos: linux
23+
docker_manifests:
24+
- name_template: "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}"
25+
image_templates:
26+
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}"
27+
checksum:
28+
name_template: 'checksums.txt'
29+
snapshot:
30+
name_template: "{{ incpatch .Version }}-next"
31+
changelog:
32+
use: github-native
33+
skip: $DISABLE_RELEASE_PIPELINE
34+
release:
35+
disable: $DISABLE_RELEASE_PIPELINE
36+
extra_files:
37+
- glob: 'operator-controller.yaml'
38+
header: |
39+
## Installation
40+
41+
```bash
42+
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/{{ .Env.CERT_MGR_VERSION }}/cert-manager.yaml
43+
kubectl wait --for=condition=Available --namespace=cert-manager deployment/cert-manager-webhook --timeout=60s
44+
kubectl apply -f https://github.com/operator-framework/rukpak/releases/latest/download/rukpak.yaml
45+
kubectl wait --for=condition=Available --namespace=rukpak-system deployment/core --timeout=60s
46+
kubectl wait --for=condition=Available --namespace=rukpak-system deployment/helm-provisioner --timeout=60s
47+
kubectl wait --for=condition=Available --namespace=rukpak-system deployment/rukpak-webhooks --timeout=60s
48+
kubectl apply -f https://github.com/operator-framework/operator-controller/releases/download/{{ .Tag }}/operator-controller.yaml
49+
kubectl wait --for=condition=Available --namespace=operator-controller-system deployment/operator-controller-controller-manager --timeout=60s
50+
```

Dockerfile

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
1-
# Build the manager binary
2-
FROM golang:1.19 as builder
3-
ARG TARGETOS
4-
ARG TARGETARCH
1+
# Note: This dockerfile does not build the binaries
2+
# required and is intended to be built only with the
3+
# 'make build' or 'make release' targets.
4+
FROM gcr.io/distroless/static:nonroot
55

6-
WORKDIR /workspace
7-
# Copy the Go Modules manifests
8-
COPY go.mod go.mod
9-
COPY go.sum go.sum
10-
# cache deps before building and copying source so that we don't need to re-download as much
11-
# and so that source changes don't invalidate our downloaded layer
12-
RUN go mod download
6+
WORKDIR /
137

14-
# Copy the go source
15-
COPY main.go main.go
16-
COPY api/ api/
17-
COPY controllers/ controllers/
18-
COPY internal/ internal/
8+
COPY manager manager
199

20-
# Build
21-
# the GOARCH has not a default value to allow the binary be built according to the host where the command
22-
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
23-
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
24-
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
25-
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
10+
EXPOSE 8080
2611

27-
# Use distroless as minimal base image to package the manager binary
28-
# Refer to https://github.com/GoogleContainerTools/distroless for more details
29-
FROM gcr.io/distroless/static:nonroot
30-
WORKDIR /
31-
COPY --from=builder /workspace/manager .
3212
USER 65532:65532
3313

34-
ENTRYPOINT ["/manager"]
14+
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export IMAGE_REPO ?= quay.io/operator-framework/operator-controller
66
export IMAGE_TAG ?= devel
77
export GO_BUILD_TAGS ?= upstream
88
export CERT_MGR_VERSION ?= v1.9.0
9+
export GORELEASER_VERSION ?= v1.15.2
910
export WAIT_TIMEOUT ?= 60s
1011
IMG?=$(IMAGE_REPO):$(IMAGE_TAG)
1112

@@ -94,8 +95,8 @@ kind-cluster-cleanup: kind ## Delete the kind cluster
9495
##@ Build
9596

9697
.PHONY: build
97-
build: manifests generate fmt vet ## Build manager binary.
98-
go build -o bin/manager main.go
98+
build: manifests generate fmt vet substitute goreleaser ## Build manager binary using goreleaser for current GOOS and GOARCH.
99+
${GORELEASER} build ${GORELEASER_ARGS} --single-target -o bin/manager
99100

100101
.PHONY: run
101102
run: docker-build kind-cluster kind-load cert-mgr rukpak install deploy wait ## Build the operator-controller then deploy it into a new kind cluster.
@@ -108,12 +109,9 @@ wait:
108109
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
109110
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
110111
.PHONY: docker-build
111-
docker-build: generate ## Build docker image with the operator-controller.
112-
docker build -t ${IMG} .
113-
114-
.PHONY: docker-push
115-
docker-push: ## Push docker image with the manager.
116-
docker push ${IMG}
112+
docker-build: export GOOS=linux
113+
docker-build: build ## Build docker image with the operator-controller.
114+
docker build -t ${IMG} -f Dockerfile ./bin/
117115

118116
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
119117
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
@@ -132,6 +130,24 @@ docker-buildx: test ## Build and push docker image for the manager for cross-pla
132130
- docker buildx rm project-v3-builder
133131
rm Dockerfile.cross
134132

133+
###########
134+
# Release #
135+
###########
136+
137+
##@ Release:
138+
export DISABLE_RELEASE_PIPELINE ?= true
139+
export GORELEASER_ARGS ?= --snapshot --rm-dist
140+
141+
substitute:
142+
envsubst < .goreleaser.template.yml > .goreleaser.yml
143+
144+
release: substitute goreleaser ## Runs goreleaser for the operator-controller. By default, this will run only as a snapshot and will not publish any artifacts unless it is run with different arguments. To override the arguments, run with "GORELEASER_ARGS=...". When run as a github action from a tag, this target will publish a full release.
145+
$(GORELEASER) $(GORELEASER_ARGS)
146+
147+
quickstart: VERSION ?= $(shell git describe --abbrev=0 --tags)
148+
quickstart: kustomize generate ## Generate the installation release manifests
149+
kubectl kustomize config/default | sed "s/:devel/:$(VERSION)/g" > operator-controller.yaml
150+
135151
##@ Deployment
136152

137153
ifndef ignore-not-found
@@ -178,6 +194,7 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize
178194
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
179195
KIND ?= $(LOCALBIN)/kind
180196
GINKGO ?= $(LOCALBIN)/ginkgo
197+
GORELEASER := $(LOCALBIN)/goreleaser
181198
ENVTEST ?= $(LOCALBIN)/setup-envtest
182199

183200
## Tool Versions
@@ -194,6 +211,11 @@ ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
194211
$(GINKGO): $(LOCALBIN)
195212
test -s $(LOCALBIN)/ginkgo || GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/[email protected]
196213

214+
.PHONY: goreleaser
215+
goreleaser: $(GORELEASER) ## Builds a local copy of goreleaser
216+
$(GORELEASER): $(LOCALBIN)
217+
test -s $(LOCALBIN)/goreleaser || GOBIN=$(LOCALBIN) go install github.com/goreleaser/goreleaser@${GORELEASER_VERSION}
218+
197219
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
198220
.PHONY: kustomize
199221
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.

bin/.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore tools binaries
3+
# TODO dfranz: We don't need this file anymore once we move the tool binaries out.
4+
controller-gen
5+
ginkgo
6+
goreleaser
7+
kind
8+
kustomize

0 commit comments

Comments
 (0)