-
-
Notifications
You must be signed in to change notification settings - Fork 35
53 lines (52 loc) · 1.85 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
name: "docker"
concurrency:
group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}
cancel-in-progress: true
on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
release:
types:
- created
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: "Checkout source code at current commit"
uses: actions/checkout@v4
- name: Prepare tags for Docker image
if: (github.event_name == 'release' && github.event.action == 'created')
id: prepare
run: |
TAGS=${{ github.repository }}:sha-${GITHUB_SHA:0:7}
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.pull_request.number }}-merge
fi
if [[ -n $VERSION ]]; then
TAGS="$TAGS,${{ github.repository }}:${VERSION}"
fi
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${{ github.repository }}:latest"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: (github.event_name == 'release' && github.event.action == 'created')
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: "Build and push docker image to DockerHub"
id: docker_build
uses: docker/build-push-action@v5
with:
push: ${{ (github.event_name == 'release' && github.event.action == 'created') }}
platforms: linux/amd64,linux/arm64
provenance: false
tags: ${{ steps.prepare.outputs.tags }}