From 1634c460969d13f74c87e15c44c29f491e571678 Mon Sep 17 00:00:00 2001 From: Bougou Date: Fri, 30 Aug 2024 10:46:05 +0800 Subject: [PATCH] chore: add github action to release chart --- .github/workflows/build_and_push.yaml | 50 -------------- .github/workflows/release-charts.yaml | 35 ++++++++++ .github/workflows/release.yaml | 66 ++++++++++++++++--- README.md | 4 +- .../alertmanager-webhook-adapter/Chart.yaml | 4 +- .../templates/deployment.yaml | 4 +- .../alertmanager-webhook-adapter/values.yaml | 6 +- 7 files changed, 105 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/build_and_push.yaml create mode 100644 .github/workflows/release-charts.yaml diff --git a/.github/workflows/build_and_push.yaml b/.github/workflows/build_and_push.yaml deleted file mode 100644 index 780e956..0000000 --- a/.github/workflows/build_and_push.yaml +++ /dev/null @@ -1,50 +0,0 @@ ---- -name: Tagged Docker Release CI - -on: - push: - branches: - - "main" - tags: - - "v*" - -jobs: - - build_and_push: - runs-on: ubuntu-latest - - steps: - - uses: AutoModality/action-clean@v1 - - uses: actions/checkout@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - name: Docker Login - uses: docker/login-action@v1.10.0 - with: - # registry: ${{ secrets.DOCKERHUB_ADDR }} - username: ${{ secrets.DOCKERHUB_USER }} - password: ${{ secrets.DOCKERHUB_PASS }} - - name: Prepare short tag - id: prepare_short_tag - run: | - SHORT_TAG=`git describe --abbrev=5 --dirty --tags --always` - echo "::set-output name=image_short_tag::$SHORT_TAG" - echo "::notice title=Build Image Short Tag::$SHORT_TAG" - - name: Prepare tag - id: prepare_tag - run: | - TIME_TAG=`TZ=Zero date +"%y%m%d%H%M%S"` - COMMIT_TAG=`echo $GITHUB_SHA | cut -c 1-7` - TAG="$TIME_TAG-$COMMIT_TAG" - echo "::set-output name=image_tag::$TAG" - echo "::notice title=Build Image Tag::$TAG" - - name: Build and push - uses: docker/build-push-action@v2 - with: - push: true - context: . - platforms: linux/amd64,linux/arm64 - tags: | - bougou/alertmanager-webhook-adapter:latest - bougou/alertmanager-webhook-adapter:${{ steps.prepare_tag.outputs.image_tag }} - bougou/alertmanager-webhook-adapter:${{ steps.prepare_short_tag.outputs.image_short_tag }} diff --git a/.github/workflows/release-charts.yaml b/.github/workflows/release-charts.yaml new file mode 100644 index 0000000..4588716 --- /dev/null +++ b/.github/workflows/release-charts.yaml @@ -0,0 +1,35 @@ +--- +name: Release Charts + +on: + push: + branches: + - "main" + +jobs: + + chart-release: + name: chart release + runs-on: ubuntu-latest + + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: install Helm + uses: azure/setup-helm@v4 + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + + - name: run chart-releaser + uses: helm/chart-releaser-action@v1.6.0 + with: + charts_dir: deploy/charts/alertmanager-webhook-adapter + skip_packaging: false + skip_existing: false + skip_upload: false + mask_as_latest: false + pages_branch: gh-pages + packages_with_index: true + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4886108..65a81a5 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,31 +1,81 @@ --- -# Release files to GitHub Releases - -name: Tagged Binary Release CI +name: Release on: push: + branches: + - "main" tags: - "v*" jobs: - tagged-release: - name: Tagged Release + docker-release: + name: docker release runs-on: ubuntu-latest + steps: + - uses: AutoModality/action-clean@v1 + + - uses: actions/checkout@v2 + + - name: set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: docker login + uses: docker/login-action@v1.10.0 + with: + # registry: ${{ secrets.DOCKERHUB_ADDR }} + username: ${{ secrets.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_PASS }} + + - name: prepare short tag + id: prepare_short_tag + run: | + SHORT_TAG=`git describe --abbrev=5 --dirty --tags --always` + echo "::set-output name=image_short_tag::$SHORT_TAG" + echo "::notice title=Build Image Short Tag::$SHORT_TAG" + + - name: prepare tag + id: prepare_tag + run: | + TIME_TAG=`TZ=Zero date +"%y%m%d%H%M%S"` + COMMIT_TAG=`echo $GITHUB_SHA | cut -c 1-7` + TAG="$TIME_TAG-$COMMIT_TAG" + echo "::set-output name=image_tag::$TAG" + echo "::notice title=Build Image Tag::$TAG" + + - name: build and push + uses: docker/build-push-action@v2 + with: + push: true + context: . + platforms: linux/amd64,linux/arm64 + tags: | + bougou/alertmanager-webhook-adapter:latest + bougou/alertmanager-webhook-adapter:${{ steps.prepare_tag.outputs.image_tag }} + bougou/alertmanager-webhook-adapter:${{ steps.prepare_short_tag.outputs.image_short_tag }} + + + binary-release: + name: binary release + runs-on: ubuntu-latest + if: startsWith(github.event.ref, 'refs/tags/v') + steps: - uses: actions/checkout@v2 - - name: Set up Go + + - name: set up Go uses: actions/setup-go@v2 with: go-version: 1.18 - - name: Build & test + - name: build & test run: | make dependencies make build-all - - uses: marvinpinto/action-automatic-releases@latest + - name: release + uses: marvinpinto/action-automatic-releases@latest with: repo_token: "${{ secrets.GITHUB_TOKEN }}" prerelease: false diff --git a/README.md b/README.md index 9285c7c..51e5493 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,9 @@ docker run --rm -it -p 127.0.0.1:8090:8090 bougou/alertmanager-webhook-adapter:v ### Run in K8S -``` +Apply manifests: + +```bash cd deploy/k8s kubectl apply -f deployment.yaml kubectl apply -f service.yaml diff --git a/deploy/charts/alertmanager-webhook-adapter/Chart.yaml b/deploy/charts/alertmanager-webhook-adapter/Chart.yaml index ebdd749..24cca86 100644 --- a/deploy/charts/alertmanager-webhook-adapter/Chart.yaml +++ b/deploy/charts/alertmanager-webhook-adapter/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v2 appVersion: 1.1.8 -description: alertmanager webhook adapter +description: helm chart for alertmanager webhook adapter name: alertmanager-webhook-adapter -version: 1.0.0 +version: 1.0.1 type: application maintainers: - name: bougou diff --git a/deploy/charts/alertmanager-webhook-adapter/templates/deployment.yaml b/deploy/charts/alertmanager-webhook-adapter/templates/deployment.yaml index efb5c49..eed7f6c 100644 --- a/deploy/charts/alertmanager-webhook-adapter/templates/deployment.yaml +++ b/deploy/charts/alertmanager-webhook-adapter/templates/deployment.yaml @@ -16,7 +16,7 @@ spec: spec: containers: - name: webhook - image: bougou/alertmanager-webhook-adapter:v1.1.8 + image: {{ .Values.image.name }}:{{ .Values.image.tag }} command: - /alertmanager-webhook-adapter - --listen-address=:8090 @@ -24,7 +24,7 @@ spec: - --tmpl-lang={{ .Values.lang | default "en" }} env: - name: TZ - value: Asia/Shanghai + value: {{ .Values.timezone }} resources: requests: memory: 50Mi diff --git a/deploy/charts/alertmanager-webhook-adapter/values.yaml b/deploy/charts/alertmanager-webhook-adapter/values.yaml index 6977a57..ff30778 100644 --- a/deploy/charts/alertmanager-webhook-adapter/values.yaml +++ b/deploy/charts/alertmanager-webhook-adapter/values.yaml @@ -1,2 +1,6 @@ -signature: "MyIDC" +image: + name: bougou/alertmanager-webhook-adapter + tag: v1.1.8 +signature: MyIDC lang: en +timezone: Asia/Shanghai