From 6d747cd266719f353ef70696f6ee0f194019e28e Mon Sep 17 00:00:00 2001 From: Michal Jura Date: Thu, 11 Apr 2024 09:16:40 +0200 Subject: [PATCH] Add release workflow --- .github/workflows/release.yaml | 58 ++++++++++++++++++++++++++++++++++ Makefile | 31 +++++++++++++++++- 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..6211808e --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,58 @@ +name: Release + +on: + push: + tags: + - 'v*' + +# GitHub settings / example values: +# +# org level vars: +# - PUBLIC_REGISTRY: docker.io +# repo level vars: +# - PUBLIC_REGISTRY_REPO: rancher +# repo level secrets: +# - PUBLIC_REGISTRY_USERNAME +# - PUBLIC_REGISTRY_PASSWORD + +permissions: + contents: read + +jobs: + publish-public: + permissions: + contents: read + id-token: write + runs-on: ubuntu-22.04 + steps: + - name: Read secrets + uses: rancher-eio/read-vault-secrets@main + with: + secrets: | + secret/data/github/repo/${{ github.repository }}/dockerhub/${{ github.repository_owner }}/credentials username | PUBLIC_REGISTRY_USERNAME ; + secret/data/github/repo/${{ github.repository }}/dockerhub/${{ github.repository_owner }}/credentials password | PUBLIC_REGISTRY_PASSWORD ; + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + registry: ${{ vars.PUBLIC_REGISTRY }} + username: ${{ env.PUBLIC_REGISTRY_USERNAME }} + password: ${{ env.PUBLIC_REGISTRY_PASSWORD }} + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.ref_name}} + - name: Build operator binary + run: | + make operator + - name: Build and push all image variations + run: | + make image-push + TAG="${TAG}-amd64" TARGET_PLATFORMS=linux/amd64 make image-push + TAG="${TAG}-arm64" TARGET_PLATFORMS=linux/arm64 make image-push + env: + TAG: ${{ github.ref_name }} + REPO: ${{ vars.PUBLIC_REGISTRY }}/${{ vars.PUBLIC_REGISTRY_REPO }} diff --git a/Makefile b/Makefile index ade3f5fa..a3073509 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,19 @@ TARGETS := $(shell ls scripts) +GIT_BRANCH?=$(shell git branch --show-current) GIT_COMMIT?=$(shell git rev-parse HEAD) GIT_COMMIT_SHORT?=$(shell git rev-parse --short HEAD) +GIT_TAG?=v0.0.0 +ifneq ($(GIT_BRANCH), main) GIT_TAG?=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0" ) +endif TAG?=${GIT_TAG}-${GIT_COMMIT_SHORT} OPERATOR_CHART?=$(shell find $(ROOT_DIR) -type f -name "rancher-aks-operator-[0-9]*.tgz" -print) CRD_CHART?=$(shell find $(ROOT_DIR) -type f -name "rancher-aks-operator-crd*.tgz" -print) CHART_VERSION?=900 # Only used in e2e to avoid downgrades from rancher -REPO?=ghcr.io/rancher/aks-operator +REPO?=docker.io/rancher/aks-operator +IMAGE = $(REPO):$(TAG) +TARGET_PLATFORMS := linux/amd64,linux/arm64 +MACHINE := rancher CLUSTER_NAME?="aks-operator-e2e" E2E_CONF_FILE ?= $(ROOT_DIR)/test/e2e/config/config.yaml @@ -114,6 +121,24 @@ charts: $(MAKE) operator-chart $(MAKE) crd-chart +buildx-machine: + @docker buildx ls | grep $(MACHINE) || \ + docker buildx create --name=$(MACHINE) --platform=$(TARGET_PLATFORMS) + +.PHONY: image-build +image-build: buildx-machine ## build (and load) the container image targeting the current platform. + docker buildx build -f package/Dockerfile \ + --builder $(MACHINE) --build-arg VERSION=$(TAG) \ + -t "$(IMAGE)" $(BUILD_ACTION) . + @echo "Built $(IMAGE)" + +.PHONY: image-push +image-push: buildx-machine ## build the container image targeting all platforms defined by TARGET_PLATFORMS and push to a registry. + docker buildx build -f package/Dockerfile \ + --builder $(MACHINE) --build-arg VERSION=$(TAG) \ + --platform=$(TARGET_PLATFORMS) -t "$(IMAGE)" --push . + @echo "Pushed $(IMAGE)" + .PHONY: setup-kind setup-kind: CLUSTER_NAME=$(CLUSTER_NAME) $(ROOT_DIR)/scripts/setup-kind-cluster.sh @@ -143,3 +168,7 @@ docker-build-e2e: --build-arg "COMMIT=${GIT_COMMIT}" \ --build-arg "COMMITDATE=${COMMITDATE}" \ -t ${REPO}:${TAG} . + +.PHOHY: delete-local-kind-cluster +delete-local-kind-cluster: ## Delete the local kind cluster + kind delete cluster --name=$(CLUSTER_NAME)