From 53a6ff7a625cf2d7c5d6f5d2b709d09304e5279b Mon Sep 17 00:00:00 2001 From: cleverhu Date: Thu, 15 Dec 2022 11:32:33 +0800 Subject: [PATCH] add build image workflow Signed-off-by: cleverhu --- .github/workflows/build-image.yaml | 54 ++++++++++++++++++++++++++ .github/workflows/push-helm-chart.yaml | 29 ++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 .github/workflows/build-image.yaml create mode 100644 .github/workflows/push-helm-chart.yaml diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml new file mode 100644 index 000000000..52e74baad --- /dev/null +++ b/.github/workflows/build-image.yaml @@ -0,0 +1,54 @@ +name: Build Docker Image + +on: + push: + branches: + - master + tags: + - v* + +env: + REPO: ghcr.io/daocloud/kubernetes-cronhpa-controller +jobs: + main: + # 在 Ubuntu 上运行 + runs-on: ubuntu-latest + steps: + # git checkout 代码 + - name: Checkout + uses: actions/checkout@v2 + # 设置 QEMU, 后面 docker buildx 依赖此. + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + # 设置 Docker buildx, 方便构建 Multi platform 镜像 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + # 登录 docker hub + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GH_TOKEN }} + # 通过 git 命令获取当前 tag 信息, 存入环境变量 APP_VERSION + - name: Generate App Version + run: echo APP_VERSION=`git describe --tags --always` >> $GITHUB_ENV + # 构建 Docker 并推送到 Docker hub + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + # 是否 docker push + push: true + # 生成多平台镜像, see https://github.com/docker-library/bashbrew/blob/v0.1.1/architecture/oci-platform.go + platforms: | + linux/amd64 + linux/arm64 + # docker build arg, 注入 APP_NAME/APP_VERSION + build-args: | + APP_VERSION=${{ env.APP_VERSION }} + # 生成两个 docker tag: ${APP_VERSION} 和 latest + tags: | + ${{ env.REPO }}:latest + ${{ env.REPO }}:${{ env.APP_VERSION }} + file: multi_arch_Dockerfile diff --git a/.github/workflows/push-helm-chart.yaml b/.github/workflows/push-helm-chart.yaml new file mode 100644 index 000000000..32d51eaab --- /dev/null +++ b/.github/workflows/push-helm-chart.yaml @@ -0,0 +1,29 @@ +name: Push helm charts + +on: + push: + tags: + - v* + +env: + APP_NAME: kubernetes-cronhpa-controller + REPO: ghcr.io/daocloud/kubernetes-cronhpa-controller + APP_VERSION: 1.3.0 +jobs: + main: + # 在 Ubuntu 上运行 + runs-on: ubuntu-latest + steps: + # git checkout 代码 + - name: Checkout + uses: actions/checkout@v2 + # 通过 git 命令获取当前 tag 信息, 存入环境变量 APP_VERSION + - name: Generate Chart Version + run: echo CHART_VERSION=`git describe --tags --always| sed 's/^v//g'` >> $GITHUB_ENV + - name: Push chart to charts + run: | + helm plugin install https://github.com/chartmuseum/helm-push + helm repo add ${{ env.APP_NAME }} ${{ secrets.REGISTRY }} + helm dep up ./charts + helm package ./charts/ -d dist --version ${{ env.CHART_VERSION }} + helm cm-push ./dist/${{ env.APP_NAME }}-${{ env.CHART_VERSION }}.tgz ${{ env.APP_NAME }} -a ${{ env.APP_VERSION }} -v ${{ env.CHART_VERSION }} -u ${{ secrets.REGISTRY_USER_NAME }} -p ${{ secrets.REGISTRY_PASSWORD }}