Skip to content

Commit

Permalink
Merge pull request #123 from grzpiotrowski/add-release-workflow
Browse files Browse the repository at this point in the history
Add release workflow
  • Loading branch information
guicassolato authored Jul 28, 2023
2 parents 254b656 + 1a5f562 commit d07e246
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 41 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Set default authorino image
run: |
echo "DEFAULT_AUTHORINO_IMAGE=$(cat authorino_image || echo ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/authorino:latest)" >> $GITHUB_ENV
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
Expand All @@ -56,7 +59,8 @@ jobs:
tags: ${{ env.IMG_TAGS }}
platforms: linux/amd64,linux/arm64
build-args: |
version=${{ env.VERSION }}
VERSION=${{ env.VERSION }}
DEFAULT_AUTHORINO_IMAGE=${{ env.DEFAULT_AUTHORINO_IMAGE }}
containerfiles: |
./Dockerfile
- name: Push Image
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release operator

on:
workflow_dispatch:
inputs:
gitRef:
description: Commit SHA or branch name
required: true
operatorVersion:
description: Operator version
required: true
authorinoVersion:
description: Authorino version
required: true
default: latest
prerelease:
description: Is the release a prerelease
required: false
type: boolean

jobs:
build:
name: Release operator
runs-on: ubuntu-20.04
steps:
- name: Install gettext-base
run: |
sudo apt-get update
sudo apt-get install -y gettext-base
- name: Set up Go 1.19.x
uses: actions/setup-go@v2
with:
go-version: 1.19.x
id: go
- name: Checkout code at git ref
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.gitRef }}
- name: Create release branch
if: ${{ !startsWith(github.event.inputs.gitRef, 'release-v') }}
run: |
git checkout -b release-v${{ github.event.inputs.operatorVersion }}
- name: Prepare release
run: VERSION=${{ github.event.inputs.operatorVersion }} AUTHORINO_VERSION=${{ github.event.inputs.authorinoVersion }} make prepare-release
- name: Commit and push
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "Prepared release v${{ github.event.inputs.operatorVersion }}" -a
git push origin release-v${{ github.event.inputs.operatorVersion }}
- name: Create release
uses: softprops/action-gh-release@v1
with:
name: v${{ github.event.inputs.operatorVersion }}
tag_name: v${{ github.event.inputs.operatorVersion }}
body: "**This release enables installations of Authorino v${{ github.event.inputs.authorinoVersion }}**"
generate_release_notes: true
target_commitish: release-v${{ github.event.inputs.operatorVersion }}
prerelease: ${{ github.event.inputs.prerelease }}
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/

ARG version=latest
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -ldflags "-X main.version=${version}" -o manager main.go
ARG VERSION=latest
ARG DEFAULT_AUTHORINO_IMAGE=quay.io/kuadrant/authorino:latest
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -ldflags "-X main.version=${VERSION} -X github.com/kuadrant/authorino-operator/controllers.DefaultAuthorinoImage=${DEFAULT_AUTHORINO_IMAGE}" -o manager main.go

# Use Red Hat minimal base image to package the binary
# https://catalog.redhat.com/software/containers/ubi9-minimal
Expand Down
96 changes: 63 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,56 @@ else
AUTHORINO_BRANCH = v$(AUTHORINO_VERSION)
endif

AUTHORINO_IMAGE_FILE ?= authorino_image
DEFAULT_AUTHORINO_IMAGE ?= $(shell cat $(AUTHORINO_IMAGE_FILE) || echo $(DEFAULT_REGISTRY)/$(DEFAULT_ORG)/authorino:latest)

all: build

##@ General

help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)


##@ Tools

OPERATOR_SDK = $(shell pwd)/bin/operator-sdk
OPERATOR_SDK_VERSION = v1.22.0
operator-sdk: ## Download operator-sdk locally if necessary.
./utils/install-operator-sdk.sh $(OPERATOR_SDK) $(OPERATOR_SDK_VERSION)

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])

YQ = $(shell pwd)/bin/yq
$(YQ):
$(call go-get-tool,$(YQ),github.com/mikefarah/yq/v4@latest)

.PHONY: yq
yq: $(YQ) ## Download yq locally if necessary.

.PHONY: opm
OPM = ./bin/opm
opm: ## Download opm locally if necessary.
ifeq (,$(wildcard $(OPM)))
ifeq (,$(shell which opm 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPM)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM) ;\
}
else
OPM = $(shell which opm)
endif
endif

##@ Development

manifests: controller-gen kustomize authorino-manifests ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
Expand Down Expand Up @@ -119,18 +162,18 @@ endif
# Run the tests
test: manifests generate fmt vet setup-envtest
echo $(SETUP_ENVTEST)
KUBEBUILDER_ASSETS='$(strip $(shell $(SETUP_ENVTEST) --arch=amd64 use -p path 1.22.x))' go test ./... -coverprofile cover.out
KUBEBUILDER_ASSETS='$(strip $(shell $(SETUP_ENVTEST) --arch=amd64 use -p path 1.22.x))' go test -ldflags="-X github.com/kuadrant/authorino-operator/controllers.DefaultAuthorinoImage=$(DEFAULT_AUTHORINO_IMAGE)" ./... -coverprofile cover.out

##@ Build

build: generate fmt vet ## Build manager binary.
go build -ldflags "-X main.version=$(VERSION)" -o bin/manager main.go
go build -ldflags "-X main.version=$(VERSION) -X github.com/kuadrant/authorino-operator/controllers.DefaultAuthorinoImage=$(DEFAULT_AUTHORINO_IMAGE)" -o bin/manager main.go

run: manifests generate fmt vet ## Run a controller from your host.
go run -ldflags "-X main.version=$(VERSION)" ./main.go
go run -ldflags "-X main.version=$(VERSION) -X github.com/kuadrant/authorino-operator/controllers.DefaultAuthorinoImage=$(DEFAULT_AUTHORINO_IMAGE)" ./main.go

docker-build: ## Build docker image with the manager.
docker build --build-arg version=$(VERSION) -t $(OPERATOR_IMAGE) .
docker build --build-arg VERSION=$(VERSION) --build-arg DEFAULT_AUTHORINO_IMAGE=$(DEFAULT_AUTHORINO_IMAGE) -t $(OPERATOR_IMAGE) .

docker-push: ## Push docker image with the manager.
docker push ${OPERATOR_IMAGE}
Expand All @@ -155,14 +198,6 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
install-authorino: ## install RBAC and CRD for authorino
$(KUSTOMIZE) build config/authorino | kubectl apply -f -

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])

# go-get-tool will 'go install' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
Expand All @@ -187,11 +222,6 @@ deploy-manifest:
# clean up
cd $(PROJECT_DIR)/config/manager && $(KUSTOMIZE) edit set image controller=${DEFAULT_OPERATOR_IMAGE}

OPERATOR_SDK = $(shell pwd)/bin/operator-sdk
OPERATOR_SDK_VERSION = v1.22.0
operator-sdk: ## Download operator-sdk locally if necessary.
./utils/install-operator-sdk.sh $(OPERATOR_SDK) $(OPERATOR_SDK_VERSION)

.PHONY: bundle
bundle: export IMAGE_TAG := $(IMAGE_TAG)
bundle: export BUNDLE_VERSION := $(BUNDLE_VERSION)
Expand All @@ -214,22 +244,22 @@ bundle-build: ## Build the bundle image.
bundle-push: ## Push the bundle image.
$(MAKE) docker-push OPERATOR_IMAGE=$(BUNDLE_IMG)

.PHONY: opm
OPM = ./bin/opm
opm: ## Download opm locally if necessary.
ifeq (,$(wildcard $(OPM)))
ifeq (,$(shell which opm 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPM)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM) ;\
}
else
OPM = $(shell which opm)
endif
endif
.PHONY: fix-csv-replaces
fix-csv-replaces: $(YQ)
$(eval REPLACES_VERSION=$(shell curl -sSL -H "Accept: application/vnd.github+json" \
https://api.github.com/repos/Kuadrant/authorino-operator/releases/latest | \
jq -r '.name'))
V="authorino-operator.$(REPLACES_VERSION)" $(YQ) eval '.spec.replaces = strenv(V)' -i bundle/manifests/authorino-operator.clusterserviceversion.yaml

.PHONY: prepare-release
prepare-release:
$(MAKE) manifests bundle VERSION=$(VERSION) AUTHORINO_VERSION=$(AUTHORINO_VERSION)
@if [ "$(AUTHORINO_VERSION)" = "latest" ]; then\
[ -e "$(AUTHORINO_IMAGE_FILE)" ] && rm $(AUTHORINO_IMAGE_FILE); \
else \
echo quay.io/kuadrant/authorino:v$(AUTHORINO_VERSION) > $(AUTHORINO_IMAGE_FILE); \
fi
$(MAKE) fix-csv-replaces

# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
# These images MUST exist in a registry and be pull-able.
Expand Down
2 changes: 1 addition & 1 deletion controllers/authorino_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (r *AuthorinoReconciler) buildAuthorinoDeployment(authorino *api.Authorino)
var saName = authorino.Name + "-authorino"

if authorino.Spec.Image == "" {
authorino.Spec.Image = defaultAuthorinoImage
authorino.Spec.Image = DefaultAuthorinoImage
}

var volumes []k8score.Volume
Expand Down
4 changes: 2 additions & 2 deletions controllers/authorino_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ var _ = Describe("Authorino controller", func() {
}, testTimeout, testInterval).Should(BeTrue())

replicas := int32(testAuthorinoReplicas)
image := defaultAuthorinoImage
image := DefaultAuthorinoImage
existContainer := false

Expect(deployment.Spec.Replicas).Should(Equal(&replicas))
Expand Down Expand Up @@ -238,7 +238,7 @@ func newExtServerConfigMap() *k8score.ConfigMap {

func newFullAuthorinoInstance() *api.Authorino {
name := "a" + string(uuid.NewUUID())
image := defaultAuthorinoImage
image := DefaultAuthorinoImage
replicas := int32(testAuthorinoReplicas)
tslEnable := true
tlsDisabled := false
Expand Down
4 changes: 3 additions & 1 deletion controllers/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const (
flagMaxHttpRequestBodySize string = "max-http-request-body-size"

// defaults
defaultAuthorinoImage string = "quay.io/kuadrant/authorino:latest"
defaultTlsCertPath string = "/etc/ssl/certs/tls.crt"
defaultTlsCertKeyPath string = "/etc/ssl/private/tls.key"
defaultOidcTlsCertPath string = "/etc/ssl/certs/oidc.crt"
Expand Down Expand Up @@ -89,3 +88,6 @@ const (
statusUnableToUpdateDeployment = "UnableToUpdateDeployment"
statusDeploymentNotReady = "DeploymentNotReady"
)

// ldflags
var DefaultAuthorinoImage string
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

setupLog.Info("botting up authorino operator", "version", version)
setupLog.Info("botting up authorino operator", "version", version, "default authorino image", controllers.DefaultAuthorinoImage)

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Expand Down

0 comments on commit d07e246

Please sign in to comment.