Skip to content

Commit e462cea

Browse files
committed
Operator Controller Release
Adds a release github action and implements goreleaser, borrowing heavily from rukpak but stripped down a bit. Signed-off-by: dtfranz <dfranz@redhat.com>
1 parent a6a8091 commit e462cea

File tree

8 files changed

+161
-38
lines changed

8 files changed

+161
-38
lines changed

.dockerignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2-
# Ignore build and test binaries.
3-
bin/
2+
# Ignore test binaries.
43
testbin/

.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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.*

.goreleaser.template.yml

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

Dockerfile

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,7 @@
1-
# Build the manager binary
2-
FROM golang:1.19 as builder
3-
ARG TARGETOS
4-
ARG TARGETARCH
1+
FROM gcr.io/distroless/static:debug-nonroot
52

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
13-
14-
# Copy the go source
15-
COPY main.go main.go
16-
COPY api/ api/
17-
COPY controllers/ controllers/
18-
COPY internal/ internal/
19-
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
26-
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
303
WORKDIR /
31-
COPY --from=builder /workspace/manager .
32-
USER 65532:65532
334

34-
ENTRYPOINT ["/manager"]
5+
COPY manager manager
6+
7+
EXPOSE 8080

Makefile

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Configuration Variables #
33
###########################
44
# Image URL to use all building/pushing image targets
5-
export IMAGE_REPO ?= quay.io/operator-framework/operator-controller
5+
export IMAGE_REPO ?= quay.io/rh_ee_dfranz/operator-controller
66
export IMAGE_TAG ?= devel
77
export GO_BUILD_TAGS ?= upstream
88
export CERT_MGR_VERSION ?= v1.9.0
@@ -95,10 +95,10 @@ kind-cluster-cleanup: kind ## Delete the kind cluster
9595

9696
.PHONY: build
9797
build: manifests generate fmt vet ## Build manager binary.
98-
go build -o bin/manager main.go
98+
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o bin/manager main.go
9999

100100
.PHONY: run
101-
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.
101+
run: build docker-build kind-cluster kind-load cert-mgr rukpak install deploy wait ## Build the operator-controller then deploy it into a new kind cluster.
102102

103103
.PHONY: wait
104104
wait:
@@ -109,7 +109,7 @@ wait:
109109
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
110110
.PHONY: docker-build
111111
docker-build: generate ## Build docker image with the operator-controller.
112-
docker build -t ${IMG} .
112+
docker build -t ${IMG} -f Dockerfile ./bin/
113113

114114
.PHONY: docker-push
115115
docker-push: ## Push docker image with the manager.
@@ -132,6 +132,24 @@ docker-buildx: test ## Build and push docker image for the manager for cross-pla
132132
- docker buildx rm project-v3-builder
133133
rm Dockerfile.cross
134134

135+
###########
136+
# Release #
137+
###########
138+
139+
##@ release:
140+
141+
export DISABLE_RELEASE_PIPELINE ?= true
142+
substitute:
143+
envsubst < .goreleaser.template.yml > .goreleaser.yml
144+
145+
release: GORELEASER_ARGS ?= --snapshot --rm-dist
146+
release: goreleaser substitute ## Run goreleaser
147+
$(GORELEASER) $(GORELEASER_ARGS)
148+
149+
quickstart: VERSION ?= $(shell git describe --abbrev=0 --tags)
150+
quickstart: generate ## Generate the installation release manifests
151+
kubectl kustomize config/default | sed "s/:latest/:$(VERSION)/g" > operator-controller.yaml
152+
135153
##@ Deployment
136154

137155
ifndef ignore-not-found
@@ -178,6 +196,7 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize
178196
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
179197
KIND ?= $(LOCALBIN)/kind
180198
GINKGO ?= $(LOCALBIN)/ginkgo
199+
GORELEASER := $(LOCALBIN)/goreleaser
181200
ENVTEST ?= $(LOCALBIN)/setup-envtest
182201

183202
## Tool Versions
@@ -194,6 +213,11 @@ ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
194213
$(GINKGO): $(LOCALBIN)
195214
test -s $(LOCALBIN)/ginkgo || GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo@v2.1.4
196215

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

config/manager/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
44
kind: Kustomization
55
images:
66
- name: controller
7-
newName: quay.io/operator-framework/operator-controller
7+
newName: quay.io/rh_ee_dfranz/operator-controller
88
newTag: devel

internal/version/version.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package version
2+
3+
// GitCommit indicates which commit the rukpak binaries were built from
4+
var GitCommit string
5+
6+
func String() string {
7+
return GitCommit
8+
}

0 commit comments

Comments
 (0)