From c97c2a4b670dfcf4638c003094e9725d98443e2c Mon Sep 17 00:00:00 2001 From: Michele Mancioppi Date: Mon, 20 Feb 2023 15:08:59 +0100 Subject: [PATCH] fix(build): generate Helm repo index --- .github/workflows/build-test-release.yml | 149 ++++++++++++++++++----- CONTRIBUTING.md | 2 +- Dockerfile.controller | 2 +- Makefile | 24 +++- README.md | 2 +- VERSION | 2 +- charts/lumigo-operator/README.md | 2 +- 7 files changed, 141 insertions(+), 42 deletions(-) diff --git a/.github/workflows/build-test-release.yml b/.github/workflows/build-test-release.yml index 5ce99ad..4a8e174 100644 --- a/.github/workflows/build-test-release.yml +++ b/.github/workflows/build-test-release.yml @@ -38,7 +38,7 @@ jobs: outputs: do-release: steps.release-check.outputs.new-release - release: + validate-release-increment: if: github.ref == 'refs/heads/main' && needs.check-should-release.outputs.do-release runs-on: ubuntu-latest needs: @@ -50,6 +50,22 @@ jobs: fetch-depth: 2 # We need this commit and the previous to check validity of version change - name: Validate version change run: ./.github/workflows/scripts/validate_version_increment.sh + - name: Export version + id: export_version + run: | + echo -n "version=$(cat VERSION)" >> ${GITHUB_OUTPUT} + outputs: + version: ${{ steps.export_version.outputs.version }} + + publish-controller-ecr-image: + runs-on: ubuntu-latest + needs: + - validate-release-increment + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Setup Go uses: actions/setup-go@v3 with: @@ -57,15 +73,6 @@ jobs: - name: Install tools run: | make install-tools - - name: Set up Helm - run: | - sudo curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash - helm version --short - helm plugin install https://github.com/hypnoglow/helm-s3.git - - name: Set up yq - run: | - sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 - sudo chmod +x /usr/local/bin/yq - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 with: @@ -77,34 +84,110 @@ jobs: uses: aws-actions/amazon-ecr-login@v1 with: registry-type: public - - name: Read version - id: read_version - run: | - echo "version=$(cat VERSION)" >> ${GITHUB_OUTPUT} - echo "controller_image_repository=public.ecr.aws/lumigo/lumigo-kubernetes-operator" >> ${GITHUB_OUTPUT} - echo "proxy_image_repository=public.ecr.aws/lumigo/lumigo-kubernetes-telemetry-proxy" >> ${GITHUB_OUTPUT} - - name: Push container images to Amazon ECR + - name: Build and push container image to Amazon ECR env: - CONTROLLER_IMG: ${{ steps.read_version.outputs.controller_image_repository }}:${{ steps.read_version.outputs.version }} - PROXY_IMG: ${{ steps.read_version.outputs.proxy_image_repository }}:${{ steps.read_version.outputs.version }} + CONTROLLER_IMG: public.ecr.aws/lumigo/lumigo-kubernetes-operator:${{ needs.validate-release-increment.outputs.version }} run: | - make docker-buildx - - name: Update Helm chart defaults + make docker-buildx-manager + + publish-telemetry-proxy-ecr-image: + runs-on: ubuntu-latest + needs: + - validate-release-increment + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + - name: Install tools run: | - yq e -i '.controllerManager.manager.image.repository = "${{ steps.read_version.outputs.controller_image_repository }}"' charts/lumigo-operator/values.yaml - yq e -i '.controllerManager.manager.image.tag = "${{ steps.read_version.outputs.version }}"' charts/lumigo-operator/values.yaml - yq e -i '.controllerManager.telemetryProxy.image.repository = "${{ steps.read_version.outputs.proxy_image_repository }}"' charts/lumigo-operator/values.yaml - yq e -i '.controllerManager.telemetryProxy.image.tag = "${{ steps.read_version.outputs.version }}"' charts/lumigo-operator/values.yaml - - name: Update Helm chart metadata + make install-tools + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + - name: Login to Amazon ECR Public + id: login-ecr-public + uses: aws-actions/amazon-ecr-login@v1 + with: + registry-type: public + - name: Build and push container image to Amazon ECR + env: + PROXY_IMG: public.ecr.aws/lumigo/lumigo-kubernetes-telemetry-proxy:${{ needs.validate-release-increment.outputs.version }} run: | - yq e -i '.version = "${{ steps.read_version.outputs.version }}"' charts/lumigo-operator/Chart.yaml - yq e -i '.appVersion = "${{ steps.read_version.outputs.version }}"' charts/lumigo-operator/Chart.yaml + make docker-buildx-telemetry-proxy + + publish-helm-chart: + runs-on: ubuntu-latest + needs: + - validate-release-increment + - publish-controller-ecr-image + - publish-telemetry-proxy-ecr-image + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: | + git branch -r - name: Configure Git run: | git config user.name "$GITHUB_ACTOR" git config user.email "$GITHUB_ACTOR@users.noreply.github.com" - - name: Publish Helm chart version - uses: helm/chart-releaser-action@v1.2.1 - env: - CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - CR_RELEASE_NAME_TEMPLATE: 'v{{ .Version }}' + - name: Set up Helm + run: curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash + - name: Set up yq + run: | + sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 + sudo chmod +x /usr/local/bin/yq + - name: Update Helm chart metadata + run: | + yq e -i '.version = "${{ needs.validate-release-increment.outputs.version }}"' charts/lumigo-operator/Chart.yaml + yq e -i '.appVersion = "${{ needs.validate-release-increment.outputs.version }}"' charts/lumigo-operator/Chart.yaml + - name: Update Helm chart defaults + run: | + yq e -i '.controllerManager.manager.image.repository = "public.ecr.aws/lumigo/lumigo-kubernetes-operator"' charts/lumigo-operator/values.yaml + yq e -i '.controllerManager.manager.image.tag = "${{ needs.validate-release-increment.outputs.version }}"' charts/lumigo-operator/values.yaml + yq e -i '.controllerManager.telemetryProxy.image.repository = "public.ecr.aws/lumigo/lumigo-kubernetes-telemetry-proxy"' charts/lumigo-operator/values.yaml + yq e -i '.controllerManager.telemetryProxy.image.tag = "${{ needs.validate-release-increment.outputs.version }}"' charts/lumigo-operator/values.yaml + - name: Create release commit + id: create-release-commit + run: | + git add charts/lumigo-operator + git commit -m "v${{ needs.validate-release-increment.outputs.version }}" + + git tag "v${{ needs.validate-release-increment.outputs.version }}" $(git rev-parse HEAD) + - name: Package Helm chart + run: | + helm package charts/lumigo-operator --destination packages/ + - name: Calculate updated Helm index + id: prepare-helm-index-update + run: | + git checkout origin/gh-pages --quiet + + helm repo index packages/ --merge index.yaml --url "https://github.com/lumigo-io/lumigo-kubernetes-operator/releases/download/v${{ needs.validate-release-increment.outputs.version }}" + mv packages/index.yaml index.yaml + + git add index.yaml + + git status + + git commit -m "${{ needs.validate-release-increment.outputs.version }}" + echo "commit_sha=$(git rev-parse HEAD)" >> ${GITHUB_OUTPUT} + - name: Create Release + uses: ncipollo/release-action@v1.12.0 + with: + name: "v${{ needs.validate-release-increment.outputs.version }}" + tag: v${{ needs.validate-release-increment.outputs.version }} + artifacts: packages/* + omitBody: true + replacesArtifacts: true + - name: Update Helm index + run: | + git push origin ${{ steps.prepare-helm-index-update.outputs.commit_sha }}:gh-pages diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f5b0a08..424af2d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,7 +55,7 @@ Deploy the Lumigo operator with: ```sh make docker-build docker-push -helm install lumigo deploy/helm/templates/lumigo-operator --namespace lumigo-system --create-namespace --set "controllerManager.manager.image.repository=host.docker.internal:5000/controller" --set "controllerManager.manager.image.tag=latest" --set "controllerManager.telemetryProxy.image.repository=host.docker.internal:5000/telemetr-proxy" --set "controllerManager.telemetryProxy.image.tag=latest" +helm upgrade --install lumigo charts/lumigo-operator --namespace lumigo-system --create-namespace --set "controllerManager.manager.image.repository=host.docker.internal:5000/controller" --set "controllerManager.manager.image.tag=latest" --set "controllerManager.telemetryProxy.image.repository=host.docker.internal:5000/telemetr-proxy" --set "controllerManager.telemetryProxy.image.tag=latest" ``` ### Troubleshooting diff --git a/Dockerfile.controller b/Dockerfile.controller index 0dca2d7..6578c7d 100644 --- a/Dockerfile.controller +++ b/Dockerfile.controller @@ -1,5 +1,5 @@ # Build the manager binary -FROM --platform=${BUILDPLATFORM} golang:1.19 as builder +FROM golang:1.19 as builder ARG TARGETOS ARG TARGETARCH diff --git a/Makefile b/Makefile index 4e31e05..83802cd 100644 --- a/Makefile +++ b/Makefile @@ -110,9 +110,25 @@ docker-push: ## Push docker image with the manager. # To properly provided solutions that supports more than one platform you should use this option. PLATFORMS ?= linux/arm64,linux/amd64 #,linux/s390x,linux/ppc64le .PHONY: docker-buildx -docker-buildx: test ## Build and push docker image for the manager for cross-platform support - - docker buildx build --push --platform=$(PLATFORMS) --tag ${CONTROLLER_IMG} -f Dockerfile.controller . - - docker buildx build --push --platform=$(PLATFORMS) --tag ${PROXY_IMG} -f Dockerfile.proxy --build-arg "lumigo_otel_collector_release=$(shell cat telemetryproxy/VERSION.otelcontibcol)" . +docker-buildx: test docker-buildx-manager docker-buildx-telemetry-proxy ## Build and push docker image for the manager for cross-platform support + +.PHONY: docker-buildx-manager +docker-buildx-manager: ## Build and push docker image for the manager for cross-platform support; this target does NOT run unit tests, it is meant for CI/CD + sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile.controller > Dockerfile.controller.cross + docker buildx create --name project-v3-builder + docker buildx use project-v3-builder + docker buildx build --push --platform=$(PLATFORMS) --tag ${CONTROLLER_IMG} -f Dockerfile.controller.cross . + - docker buildx rm project-v3-builder + rm Dockerfile.controller.cross + +.PHONY: docker-buildx-telemetry-proxy +docker-buildx-telemetry-proxy: ## Build and push docker image for the manager for cross-platform support + sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile.proxy > Dockerfile.proxy.cross + docker buildx create --name project-v3-builder + docker buildx use project-v3-builder + docker buildx build --push --platform=$(PLATFORMS) --tag ${PROXY_IMG} -f Dockerfile.proxy.cross --build-arg "lumigo_otel_collector_release=$(shell cat telemetryproxy/VERSION.otelcontibcol)" . + - docker buildx rm project-v3-builder + rm Dockerfile.proxy.cross ##@ Deployment @@ -167,4 +183,4 @@ $(CONTROLLER_GEN): $(LOCALBIN) .PHONY: envtest envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. $(ENVTEST): $(LOCALBIN) - test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) $(GOCMD) install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest + test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) $(GOCMD) install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest \ No newline at end of file diff --git a/README.md b/README.md index f66ad4d..55fc4a9 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The Kubernetes operator of Lumigo provides a one-click solution to monitoring Ku Install the Lumigo operator in your Kubernets cluster with [helm](https://helm.sh/): ```sh -helm repo add lumigo https://lumigo-io.github.io/lumigo-kubernetes-operator/stable/lumigo-operator +helm repo add lumigo https://lumigo-io.github.io/lumigo-kubernetes-operator helm install lumigo lumigo/lumigo-operator --namespace lumigo-system --create-namespace ``` diff --git a/VERSION b/VERSION index 56a6051..d8263ee 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1 \ No newline at end of file +2 \ No newline at end of file diff --git a/charts/lumigo-operator/README.md b/charts/lumigo-operator/README.md index e9e57c4..07b1716 100644 --- a/charts/lumigo-operator/README.md +++ b/charts/lumigo-operator/README.md @@ -7,7 +7,7 @@ The Kubernetes operator of Lumigo provides a one-click solution to monitoring Ku Install the Lumigo operator in your Kubernets cluster with [helm](https://helm.sh/): ```sh -helm repo add lumigo https://lumigo-io.github.io/lumigo-kubernetes-operator/stable/lumigo-operator +helm repo add lumigo https://lumigo-io.github.io/lumigo-kubernetes-operator helm install lumigo lumigo/lumigo-operator --namespace lumigo-system --create-namespace ```