Skip to content

Commit

Permalink
ci: 增加构建action
Browse files Browse the repository at this point in the history
  • Loading branch information
wan92hen committed Jul 13, 2022
1 parent cdad810 commit af2e74e
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build Docker Image and Push

on:
pull_request:
paths:
- "**"
- "!**.md"
push:
branches:
- "**"
tags:
- '**'

workflow_dispatch:

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
name: Build Docker Image and Push
steps:
- uses: actions/checkout@v2
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
- name: Prepare Docker Build
id: prepare
run: |
REGISTRY=${{ secrets.REGISTRY }}
DOCKER_IMAGE=${REGISTRY}/f2ccloud/prometheus-agent
DOCKER_PLATFORMS=linux/amd64
TAG_NAME=${{ env.GITHUB_REF_SLUG }}
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME}"
DOCKER_IMAGE_UI_TAGS="--tag ${DOCKER_IMAGE_UI}:${TAG_NAME}"
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=docker_image_ui::${DOCKER_IMAGE_UI}
echo ::set-output name=version::${TAG_NAME}
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
--build-arg VERSION=${{ env.GITHUB_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${DOCKER_IMAGE_TAGS} \
.
- name: Login to Registry
uses: docker/login-action@v1
with:
registry: ${{ secrets.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- name: Docker build
run: |
docker build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }}
- name: Docker push
# 只有tag、定时任务或手动触发时,才push镜像
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
run: |
docker push ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}
- name: Wechat Work Robot Message
uses: fifsky/[email protected]
with:
# wechat work robot webhook
url: ${{ secrets.WECHAT_WEBHOOK }}
# message type
type: markdown
content: |
# GitHub 构建通知
## 构建结果
> from github action message
> ^_^
- repository: ${{ github.repository }}
- committer: ${{ github.actor }}
- compare: [view](${{ github.event.compare }})
- job status: ${{ job.status }}

0 comments on commit af2e74e

Please sign in to comment.