Skip to content

Commit

Permalink
Merge pull request #4 from cleverhu/add-build-workflow
Browse files Browse the repository at this point in the history
Add build workflow
  • Loading branch information
wawa0210 authored Dec 15, 2022
2 parents d59cefe + 53a6ff7 commit 043ef0e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/build-image.yaml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions .github/workflows/push-helm-chart.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit 043ef0e

Please sign in to comment.