-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (62 loc) · 2.37 KB
/
push-to-dockerhub.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# This action will push version-tagged and latest images to Docker Hub
# This requires three secrets to be set, the first two should be stored in Organization
# Secrets, the last is a per-repository secret.
# DOCKER_HUB_USERNAME: The Docker Hub username
# DOCKER_HUB_ACCESS_TOKEN: Instead of a password
# DOCKER_REPO_NAME: The full image name as it appears on Docker Hub
name: GitHub Release & Push to Docker Hub
on:
push:
tags: ["v*"]
jobs:
Deploy:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Set up REPO and TAG environment vars
run: |
echo "REPO=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
echo "TAG=${GITHUB_SHA:0:6}" >> $GITHUB_ENV
- name: This run was triggered by a version tag, reset the $TAG variable to the tag name
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo "TAG=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: Create GitHub release
if: ${{ contains(github.ref, 'refs/tags/') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create v${TAG}
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
# https://github.com/docker/login-action
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
# https://github.com/docker/metadata-action
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ secrets.DOCKER_REPO_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# https://github.com/docker/build-push-action
- name: Build and push to DockerHub
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}