-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from cleverhu/add-build-workflow
Add build workflow
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |