forked from dingodb/dingo-store
-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (135 loc) · 5.29 KB
/
release-dockerhub.yml
File metadata and controls
154 lines (135 loc) · 5.29 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# This is a basic workflow to help you get started with Actions
name: Release-Dockerhub
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
workflow_run:
workflows: ["CMake_rocky8"]
types:
- completed
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
release:
# The type of runner that the job will run on
if: github.event.pull_request.merged == false
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Download branch name file
uses: actions/download-artifact@v4
with:
name: branch_name
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: ./
- name: Config trigger branch env
run: |
if [ -f branch_name.txt ]; then
echo "BRANCH_NAME=$(cat branch_name.txt)" >> $GITHUB_ENV
fi
- name: Download commit id file
uses: actions/download-artifact@v4
with:
name: commit_id
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: ./
- name: Config commit id env
run: |
if [ -f commit_id.txt ]; then
echo "COMMIT_ID=$(cat commit_id.txt)" >> $GITHUB_ENV
fi
- name: Download event type file
uses: actions/download-artifact@v4
with:
name: event
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: ./
- name: Config trigger event env
run: |
if [ -f event.txt ]; then
echo "EVENT=$(cat event.txt)" >> $GITHUB_ENV
fi
- name: Download tag name file
if: ${{ env.EVENT == 'tag' }}
uses: actions/download-artifact@v4
with:
name: tag_name
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: ./
- name: Config push tag env
if: ${{ env.EVENT == 'tag' }}
run: |
if [ -f tag_name.txt ]; then
echo "TAG_NAME=$(cat tag_name.txt)" >> $GITHUB_ENV
fi
- name: Print env info
id: check-event
run: |
echo "trigger event type is ${{ env.EVENT }}"
echo "continue=true" >> $GITHUB_OUTPUT
if [ "${{ env.EVENT }}" == "pull_request" ]; then
echo "pull request haven't merged, not need to publish image."
echo "continue=false" >> $GITHUB_OUTPUT
fi
if [ -n "${{ env.TAG_NAME }}" ]; then
echo "tag name is ${{ env.TAG_NAME }}, need to publish image."
fi
if [ -n "${{ env.BRANCH_NAME }}" ]; then
echo "branch name is ${{ env.BRANCH_NAME }}"
fi
if [ -n "${{ env.COMMIT_ID }}" ]; then
echo "commit id is ${{ env.COMMIT_ID }}"
fi
- name: Download artifact
if: steps.check-event.outputs.continue == 'true'
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: ci_rocky8.yml
name: dingo-store.tar.gz
- name: rename artifactory name
if: steps.check-event.outputs.continue == 'true'
run: |
cp dingo-store.tar.gz ./docker
# setup Docker buld action
- name: Set up Docker Buildx
if: steps.check-event.outputs.continue == 'true'
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to Github Packages
if: steps.check-event.outputs.continue == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker meta info
if: steps.check-event.outputs.continue == 'true'
id: store-meta
uses: docker/metadata-action@v5
with:
images: dingodatabase/dingo-store
tags: |
type=raw,enable=${{ env.EVENT == 'tag' }},value=${{ env.TAG_NAME }}
type=raw,value=latest,enable=${{ env.BRANCH_NAME == 'main' && env.EVENT != 'tag'}}
type=sha,prefix=,format=short,enable=${{ env.BRANCH_NAME == 'main' && env.EVENT != 'tag' }}
type=raw,value=${{ env.BRANCH_NAME }}-${{ env.COMMIT_ID }},enable=${{ env.EVENT != 'tag' && env.BRANCH_NAME != 'main' }}
type=raw,value=${{ env.BRANCH_NAME }}-latest,enable=${{ env.EVENT != 'tag' && env.BRANCH_NAME != 'main' }}
- name: Build image and push to Docker Hub and GitHub Container Registry
if: steps.check-event.outputs.continue == 'true'
uses: docker/build-push-action@v6
with:
# relative path to the place where source code with Dockerfile is located
context: ./docker
#tags: dingodatabase/dingo-store:latest
tags: ${{ steps.store-meta.outputs.tags }}
# push: ${{ github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' }}
push: true
- name: Image digest
if: steps.check-event.outputs.continue == 'true'
run: echo ${{ steps.docker_build.outputs.digest }}