From 208368baf5e9efc85444cb2b2d73af0e33d351a3 Mon Sep 17 00:00:00 2001 From: zhanghongtong Date: Wed, 12 Jan 2022 16:14:41 +0800 Subject: [PATCH] ci: update deployment steps Signed-off-by: zhanghongtong --- .github/workflows/cts.yaml | 13 ++++++------- .github/workflows/{build.yml => release.yml} | 11 +++++++++-- .github/workflows/test.yaml | 13 ++++++------- Makefile | 2 +- config/manager/kustomization.yaml | 2 +- config/samples/operator/controller.yaml | 2 +- get-version | 11 +++++++++++ 7 files changed, 35 insertions(+), 19 deletions(-) rename .github/workflows/{build.yml => release.yml} (75%) create mode 100755 get-version diff --git a/.github/workflows/cts.yaml b/.github/workflows/cts.yaml index a7a595b03..a99a6c121 100644 --- a/.github/workflows/cts.yaml +++ b/.github/workflows/cts.yaml @@ -67,14 +67,13 @@ jobs: with: go-version: '1.17.3' - name: Build image - run: eval $(minikube docker-env) && docker build -t emqx/emqx-operator-controller:$(git describe --tags) . + env: + IMG: "emqx/emqx-operator-controller:${{ github.sha }}" + run: eval $(minikube docker-env) && docker build -t $IMG . - name: Deploy controller - run: | - make deploy - if ! git diff --quiet; then - echo "Need run make deploy" - exit 1 - fi + env: + IMG: "emqx/emqx-operator-controller:${{ github.sha }}" + run: make deploy - name: Check operator timeout-minutes: 15 run: | diff --git a/.github/workflows/build.yml b/.github/workflows/release.yml similarity index 75% rename from .github/workflows/build.yml rename to .github/workflows/release.yml index 4a5702e88..411c0f6ae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Build emqx operator +name: Release emqx operator on: push: @@ -6,10 +6,17 @@ on: - "*" jobs: - docker: + release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: check image tag for yaml + run: | + tag=$(cat config/samples/operator/controller.yaml | egrep "image:[[:space:]]emqx/emqx-operator-controller" | sed -r 's|image:[[:space:]]emqx/emqx-operator-controller:(.*)|\1|g' | tr -d '[:space:]') + if [ "$tag" != "${GITHUB_REF##*/}" ]; then + echo "Need update image tag for config/samples/operator/controller.yaml" + exit 1 + fi - uses: docker/setup-qemu-action@v1 - uses: docker/setup-buildx-action@v1 - uses: docker/metadata-action@v3 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2aeaf29b3..08302d656 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -68,14 +68,13 @@ jobs: with: go-version: '1.17.3' - name: Build image - run: eval $(minikube docker-env) && docker build -t emqx/emqx-operator-controller:$(git describe --tags) . + env: + IMG: "emqx/emqx-operator-controller:${{ github.sha }}" + run: eval $(minikube docker-env) && docker build -t $IMG . - name: Deploy controller - run: | - make deploy - if ! git diff --quiet; then - echo "Need run make deploy" - exit 1 - fi + env: + IMG: "emqx/emqx-operator-controller:${{ github.sha }}" + run: make deploy - name: Check operator timeout-minutes: 10 run: | diff --git a/Makefile b/Makefile index f4bd37090..6ae2d8c96 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Image URL to use all building/pushing image targets -IMG ?= emqx/emqx-operator-controller:$(shell git describe --tags) +IMG ?= emqx/emqx-operator-controller:$(shell ./get-version) # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) #CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false" CRD_OPTIONS ?= "crd" diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index db2a001fe..a2816961b 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -13,4 +13,4 @@ kind: Kustomization images: - name: controller newName: emqx/emqx-operator-controller - newTag: 1.0.0-40-g63013f1 + newTag: 7549fa9 diff --git a/config/samples/operator/controller.yaml b/config/samples/operator/controller.yaml index c6468f54f..bf780f132 100644 --- a/config/samples/operator/controller.yaml +++ b/config/samples/operator/controller.yaml @@ -7902,7 +7902,7 @@ spec: - --leader-elect command: - /manager - image: emqx/emqx-operator-controller:1.0.0-40-g63013f1 + image: emqx/emqx-operator-controller:7549fa9 livenessProbe: httpGet: path: /healthz diff --git a/get-version b/get-version new file mode 100755 index 000000000..68e689815 --- /dev/null +++ b/get-version @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ensure dir +cd -P -- "$(dirname -- "$0")" + +if [ "$(git describe --tag | egrep "^[0-9]+\.[0-9]+\.[0-9]$")" != "" ]; then + git describe --tag +else + git rev-parse --short HEAD +fi \ No newline at end of file