-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (93 loc) · 3.69 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Docker
on:
push:
tags:
- 'v*'
jobs:
on-success:
needs: publish
runs-on: ubuntu-latest
if: ${{ always() && needs.publish.result == 'success' }}
steps:
- name: Notification Feishu
uses: whatwewant/action-robot-feishu@v0.0.13
with:
url: ${{ secrets.DOCKER_VERSION_FEISHU_BOT_WEBHOOK_URL }}
title: '✅ Docker 发布:${{ github.repository }}'
text: |
分支: ${{ github.ref }}
提交信息: ${{ github.event.head_commit.message }}
提交人: ${{ github.actor }}
状态: 构建成功(https://github.com/${{ github.repository }}/actions/runs/${{ github.run.id }})
on-failure:
needs: publish
runs-on: ubuntu-latest
if: ${{ always() && needs.publish.result == 'failure' }}
steps:
- name: Notification Feishu
uses: whatwewant/action-robot-feishu@v0.0.13
with:
url: ${{ secrets.DOCKER_VERSION_FEISHU_BOT_WEBHOOK_URL }}
title: '❌ Docker 发布:${{ github.repository }}'
text: |
分支: ${{ github.ref }}
提交信息: ${{ github.event.head_commit.message }}
提交人: ${{ github.actor }}
状态: 构建失败(https://github.com/${{ github.repository }}/actions/runs/${{ github.run.id }})
publish:
runs-on: ubuntu-latest
steps:
- name: Get Current Date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- uses: actions/checkout@v2
with:
fetch-depth: '0'
- name: Docker Meta
id: meta
run: |
VERSION=$(echo ${GITHUB_REF} | sed -e "s%refs/tags/%%g")
BUILD_TIME=$(date +%Y-%m-%d)
COMMIT_HASH=$(git rev-parse --short HEAD)
ACTION_IMAGE_NAME=$(echo $ACTION_IMAGE_REPO | awk -F "/" '{print $2}')
IMAGE_NAME=${ACTION_IMAGE_NAMESPACE}/${ACTION_IMAGE_NAME}
IMAGE_TAGS=${IMAGE_NAME}:${VERSION}
echo "IMAGE_TAGS: ${IMAGE_TAGS}"
echo "VERSION: ${VERSION} (${COMMIT_HASH} ${BUILD_TIME})"
echo "::set-output name=version::${VERSION}"
echo "::set-output name=build_time::${BUILD_TIME}"
echo "::set-output name=commit_hash::${COMMIT_HASH}"
echo "::set-output name=name::${IMAGE_NAME}"
echo "::set-output name=tags::${IMAGE_TAGS}"
shell: bash
env:
ACTION_IMAGE_NAMESPACE: ${{ secrets.DOCKERHUB_USERNAME }}
# ACTION_IMAGE_NAME: ${{ github.repository }}
ACTION_IMAGE_REPO: ${{ github.repository }}
- name: Show Docker Tags
run: |
echo "Docker Tags: ${{ steps.meta.outputs.tags }}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
build-args: |
VERSION=${{ steps.meta.outputs.version }}
BUILD_TIME=${{ steps.meta.outputs.build_time }}
COMMIT_HASH=${{ steps.meta.outputs.commit_hash }}
context: .
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=registry,ref=${{ steps.meta.outputs.name }}:buildcache
cache-to: type=registry,ref=${{ steps.meta.outputs.name }}:buildcache,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64