Skip to content

Commit af2e74e

Browse files
committed
ci: 增加构建action
1 parent cdad810 commit af2e74e

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

.github/workflows/build-push.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Build Docker Image and Push
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "**"
7+
- "!**.md"
8+
push:
9+
branches:
10+
- "**"
11+
tags:
12+
- '**'
13+
14+
workflow_dispatch:
15+
16+
concurrency:
17+
group: ${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
name: Build Docker Image and Push
24+
steps:
25+
- uses: actions/checkout@v2
26+
- name: Inject slug/short variables
27+
uses: rlespinasse/github-slug-action@v3.x
28+
- name: Prepare Docker Build
29+
id: prepare
30+
run: |
31+
REGISTRY=${{ secrets.REGISTRY }}
32+
DOCKER_IMAGE=${REGISTRY}/f2ccloud/prometheus-agent
33+
DOCKER_PLATFORMS=linux/amd64
34+
TAG_NAME=${{ env.GITHUB_REF_SLUG }}
35+
DOCKER_IMAGE_TAGS="--tag ${DOCKER_IMAGE}:${TAG_NAME}"
36+
DOCKER_IMAGE_UI_TAGS="--tag ${DOCKER_IMAGE_UI}:${TAG_NAME}"
37+
echo ::set-output name=docker_image::${DOCKER_IMAGE}
38+
echo ::set-output name=docker_image_ui::${DOCKER_IMAGE_UI}
39+
echo ::set-output name=version::${TAG_NAME}
40+
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
41+
--build-arg VERSION=${{ env.GITHUB_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }} \
42+
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
43+
--build-arg VCS_REF=${GITHUB_SHA::8} \
44+
${DOCKER_IMAGE_TAGS} \
45+
.
46+
47+
- name: Login to Registry
48+
uses: docker/login-action@v1
49+
with:
50+
registry: ${{ secrets.REGISTRY }}
51+
username: ${{ secrets.REGISTRY_USERNAME }}
52+
password: ${{ secrets.REGISTRY_PASSWORD }}
53+
54+
- name: Docker build
55+
run: |
56+
docker build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }}
57+
58+
- name: Docker push
59+
# 只有tag、定时任务或手动触发时,才push镜像
60+
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
61+
run: |
62+
docker push ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}
63+
64+
- name: Wechat Work Robot Message
65+
uses: fifsky/wechat-work-action@v0.0.1
66+
with:
67+
# wechat work robot webhook
68+
url: ${{ secrets.WECHAT_WEBHOOK }}
69+
# message type
70+
type: markdown
71+
content: |
72+
# GitHub 构建通知
73+
## 构建结果
74+
> from github action message
75+
> ^_^
76+
- repository: ${{ github.repository }}
77+
- committer: ${{ github.actor }}
78+
- compare: [view](${{ github.event.compare }})
79+
- job status: ${{ job.status }}

0 commit comments

Comments
 (0)