-
-
Notifications
You must be signed in to change notification settings - Fork 752
55 lines (46 loc) · 1.55 KB
/
docker.yml
File metadata and controls
55 lines (46 loc) · 1.55 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
name: Build and push Docker image upon release
on:
push:
branches:
- 3.x
jobs:
push_to_registry:
name: Build and push Docker image to Docker Hub
runs-on: ubuntu-22.04
env:
DOCKER_REPO: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}
steps:
- name: Fetch full Git history and tags
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get the latest tag
id: get_tag
run: |
TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "TAG=$TAG" >> $GITHUB_ENV
echo "::set-output name=tag::$TAG"
- name: Checkout latest tag
run: git checkout tags/${{ env.TAG }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Check if Docker tag exists
id: tag_check
run: |
TAG_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" \
https://hub.docker.com/v2/repositories/${DOCKER_REPO}/tags/${TAG}/)
echo "exists=$TAG_EXISTS" >> $GITHUB_OUTPUT
- name: Build and push Docker image
if: steps.tag_check.outputs.exists != '200'
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ env.DOCKER_REPO }}:latest
${{ env.DOCKER_REPO }}:${{ env.TAG }}