-
Notifications
You must be signed in to change notification settings - Fork 116
66 lines (58 loc) · 1.96 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
54
55
56
57
58
59
60
61
62
63
64
65
66
name: Docker Release
on:
push:
tags:
- '*'
branches:
- master
permissions:
contents: read
jobs:
init:
permissions:
contents: none
runs-on: ubuntu-latest
outputs:
do_docker: ${{ steps.vars.outputs.IS_DOCKERHUB_PUSH }}
steps:
- name: Initialize workflow variables
shell: bash
run: |
# work-around for inaccessible 'secrets' object for 'if'; see <https://git.luolix.topmunity/t5/GitHub-Actions/jobs-lt-job-id-gt-if-does-not-work-with-env-secrets/m-p/38549>)
unset IS_DOCKERHUB_PUSH
if [ -z "$DOCKERHUB_PUSH" ]; then IS_DOCKERHUB_PUSH='false'; else IS_DOCKERHUB_PUSH='true' ; fi
echo set-output name=IS_DOCKERHUB_PUSH::${IS_DOCKERHUB_PUSH}
echo ::set-output name=IS_DOCKERHUB_PUSH::${IS_DOCKERHUB_PUSH}
env:
DOCKERHUB_PUSH: ${{ secrets.DOCKERHUB_PUSH }}
build:
name: Build and push Docker image
runs-on: ubuntu-latest
needs: [init]
if: ${{ needs.init.outputs.do_docker == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push latest
uses: docker/build-push-action@v2
if: github.ref == 'refs/heads/master'
with:
push: true
tags: ${{ secrets.DOCKERHUB_REPO }}:latest
- name: Set version variable
id: version
if: startsWith(github.ref, 'refs/tags/')
run: echo ::set-output name=TAG::${GITHUB_REF#refs/tags/}
- name: Build and push tag
uses: docker/build-push-action@v2
if: startsWith(github.ref, 'refs/tags/')
with:
push: true
tags: ${{ secrets.DOCKERHUB_REPO }}:${{ steps.version.outputs.TAG }}