Skip to content

Commit 6bf46a5

Browse files
committed
[Add] github workflow template for push to docker
1 parent b9005e8 commit 6bf46a5

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

.github/workflows/docker-push.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build and Push Docker image on Release
2+
3+
on:
4+
workflow_run:
5+
# workflows: ["Create Release"]
6+
# types:
7+
# - completed
8+
9+
jobs:
10+
build:
11+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Log in to Docker Hub
19+
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
20+
21+
- name: Get repository name
22+
id: repo_name
23+
run: echo "REPO_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_OUTPUT
24+
25+
- name: Get latest release tag
26+
id: get_tag
27+
run: |
28+
TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
29+
echo "TAG=$TAG" >> $GITHUB_OUTPUT
30+
31+
- name: Build Docker image
32+
run: |
33+
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ steps.repo_name.outputs.REPO_NAME }}:latest \
34+
-t ${{ secrets.DOCKER_USERNAME }}/${{ steps.repo_name.outputs.REPO_NAME }}:${{ steps.get_tag.outputs.TAG }} .
35+
36+
- name: Push Docker image
37+
run: |
38+
docker push ${{ secrets.DOCKER_USERNAME }}/${{ steps.repo_name.outputs.REPO_NAME }}:latest
39+
docker push ${{ secrets.DOCKER_USERNAME }}/${{ steps.repo_name.outputs.REPO_NAME }}:${{ steps.get_tag.outputs.TAG }}

0 commit comments

Comments
 (0)