Skip to content

Commit 1f0c022

Browse files
authored
Merge pull request #528 from NotYuSheng/ci/publish-docker-ghcr
Ci/publish docker ghcr
2 parents 8dd3eb5 + 61e70c4 commit 1f0c022

File tree

2 files changed

+144
-36
lines changed

2 files changed

+144
-36
lines changed
Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
name: Publish to Docker Hub
22

33
on:
4+
# Triggers minor version ( vX.Y.Z-ShortHash )
45
push:
56
branches:
67
- master
8+
# Triggers major version ( vX.Y.Z )
9+
release:
10+
types: [created]
11+
12+
workflow_dispatch:
713

814
jobs:
9-
build-and-push-webui:
15+
build-and-push:
1016
runs-on: ubuntu-latest
1117

18+
strategy:
19+
matrix:
20+
name: [whisper-webui, whisper-webui-backend]
21+
1222
steps:
1323
- name: Clean up space for action
1424
run: rm -rf /opt/hostedtoolcache
1525

16-
- name: Log in to Docker Hub
17-
uses: docker/login-action@v2
18-
with:
19-
username: ${{ secrets.DOCKER_USERNAME }}
20-
password: ${{ secrets.DOCKER_PASSWORD }}
21-
2226
- name: Checkout repository
2327
uses: actions/checkout@v3
2428

@@ -28,46 +32,61 @@ jobs:
2832
- name: Set up QEMU
2933
uses: docker/setup-qemu-action@v3
3034

31-
- name: Build and push Docker image
32-
uses: docker/build-push-action@v5
33-
with:
34-
context: .
35-
file: ./Dockerfile
36-
push: true
37-
tags: ${{ secrets.DOCKER_USERNAME }}/whisper-webui:latest
38-
39-
- name: Log out of Docker Hub
40-
run: docker logout
41-
42-
build-and-push-backend:
43-
runs-on: ubuntu-latest
44-
45-
steps:
46-
- name: Clean up space for action
47-
run: rm -rf /opt/hostedtoolcache
35+
- name: Extract metadata
36+
id: meta
37+
run: |
38+
SHORT_SHA=$(git rev-parse --short HEAD)
39+
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV
40+
41+
# Triggered by a release event — versioning as major ( vX.Y.Z )
42+
if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
43+
TAG_NAME="${{ github.event.release.tag_name }}"
44+
echo "GIT_TAG=$TAG_NAME" >> $GITHUB_ENV
45+
echo "IS_RELEASE=true" >> $GITHUB_ENV
46+
47+
# Triggered by a general push event — versioning as minor ( vX.Y.Z-ShortHash )
48+
else
49+
git fetch --tags
50+
LATEST_TAG=$(git tag --list 'v*.*.*' | sort -V | tail -n1)
51+
FALLBACK_TAG="${LATEST_TAG:-v0.0.0}"
52+
echo "GIT_TAG=${FALLBACK_TAG}-${SHORT_SHA}" >> $GITHUB_ENV
53+
echo "IS_RELEASE=false" >> $GITHUB_ENV
54+
fi
55+
56+
- name: Set Dockerfile path
57+
id: dockerfile
58+
run: |
59+
if [ "${{ matrix.name }}" = "whisper-webui" ]; then
60+
echo "DOCKERFILE=./Dockerfile" >> $GITHUB_ENV
61+
elif [ "${{ matrix.name }}" = "whisper-webui-backend" ]; then
62+
echo "DOCKERFILE=./backend/Dockerfile" >> $GITHUB_ENV
63+
else
64+
echo "Unknown component: ${{ matrix.name }}"
65+
exit 1
66+
fi
4867
4968
- name: Log in to Docker Hub
5069
uses: docker/login-action@v2
5170
with:
5271
username: ${{ secrets.DOCKER_USERNAME }}
5372
password: ${{ secrets.DOCKER_PASSWORD }}
5473

55-
- name: Checkout repository
56-
uses: actions/checkout@v3
57-
58-
- name: Set up Docker Buildx
59-
uses: docker/setup-buildx-action@v3
60-
61-
- name: Set up QEMU
62-
uses: docker/setup-qemu-action@v3
63-
64-
- name: Build and push Docker image
74+
- name: Build and push Docker image (version tag)
6575
uses: docker/build-push-action@v5
6676
with:
6777
context: .
68-
file: ./backend/Dockerfile
78+
file: ${{ env.DOCKERFILE }}
6979
push: true
70-
tags: ${{ secrets.DOCKER_USERNAME }}/whisper-webui-backend:latest
80+
tags: |
81+
${{ secrets.DOCKER_USERNAME }}/${{ matrix.name }}:${{ env.GIT_TAG }}
82+
83+
- name: Tag and push as latest (if release)
84+
if: env.IS_RELEASE == 'true'
85+
run: |
86+
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ matrix.name }}:${{ env.GIT_TAG }}
87+
docker tag ${{ secrets.DOCKER_USERNAME }}/${{ matrix.name }}:${{ env.GIT_TAG }} \
88+
${{ secrets.DOCKER_USERNAME }}/${{ matrix.name }}:latest
89+
docker push ${{ secrets.DOCKER_USERNAME }}/${{ matrix.name }}:latest
7190
7291
- name: Log out of Docker Hub
7392
run: docker logout

.github/workflows/publish-ghcr.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Publish to GHCR
2+
3+
on:
4+
# Triggers minor version ( vX.Y.Z-ShortHash )
5+
push:
6+
branches:
7+
- master
8+
# Triggers major version ( vX.Y.Z )
9+
release:
10+
types: [created]
11+
12+
workflow_dispatch:
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
18+
strategy:
19+
matrix:
20+
name: [whisper-webui, whisper-webui-backend]
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v3
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v3
31+
32+
- name: Extract metadata
33+
id: meta
34+
run: |
35+
SHORT_SHA=$(git rev-parse --short HEAD)
36+
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV
37+
38+
# Triggered by a release event — versioning as major ( vX.Y.Z )
39+
if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
40+
TAG_NAME="${{ github.event.release.tag_name }}"
41+
echo "GIT_TAG=$TAG_NAME" >> $GITHUB_ENV
42+
echo "IS_RELEASE=true" >> $GITHUB_ENV
43+
44+
# Triggered by a general push event — versioning as minor ( vX.Y.Z-ShortHash )
45+
else
46+
git fetch --tags
47+
LATEST_TAG=$(git tag --list 'v*.*.*' | sort -V | tail -n1)
48+
FALLBACK_TAG="${LATEST_TAG:-v0.0.0}"
49+
echo "GIT_TAG=${FALLBACK_TAG}-${SHORT_SHA}" >> $GITHUB_ENV
50+
echo "IS_RELEASE=false" >> $GITHUB_ENV
51+
fi
52+
53+
echo "REPO_OWNER_LC=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_ENV
54+
55+
- name: Set Dockerfile path
56+
id: dockerfile
57+
run: |
58+
if [ "${{ matrix.name }}" = "whisper-webui" ]; then
59+
echo "DOCKERFILE=./Dockerfile" >> $GITHUB_ENV
60+
elif [ "${{ matrix.name }}" = "whisper-webui-backend" ]; then
61+
echo "DOCKERFILE=./backend/Dockerfile" >> $GITHUB_ENV
62+
else
63+
echo "Unknown component: ${{ matrix.name }}"
64+
exit 1
65+
fi
66+
67+
- name: Log in to GitHub Container Registry
68+
uses: docker/login-action@v2
69+
with:
70+
registry: ghcr.io
71+
username: ${{ github.actor }}
72+
password: ${{ secrets.GITHUB_TOKEN }}
73+
74+
- name: Build and push Docker image (version tag)
75+
uses: docker/build-push-action@v5
76+
with:
77+
context: .
78+
file: ${{ env.DOCKERFILE }}
79+
push: true
80+
tags: |
81+
ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:${{ env.GIT_TAG }}
82+
83+
- name: Tag and push as latest (if release)
84+
if: env.IS_RELEASE == 'true'
85+
run: |
86+
docker pull ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:${{ env.GIT_TAG }}
87+
docker tag ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:${{ env.GIT_TAG }} \
88+
ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:latest
89+
docker push ghcr.io/${{ env.REPO_OWNER_LC }}/${{ matrix.name }}:latest

0 commit comments

Comments
 (0)