1
+ # This workflow builds the docker image on any PR or Release
2
+ # Releases will be tagged with latest, stable, and their git tag
3
+ # Prereleases will be tagged with prerelease and their git tag
4
+ # Pull Requests will be tagged with branch name and their github ref (pr-{number})
5
+
6
+ name : Create and publish a Docker image
7
+
8
+ on :
9
+ release :
10
+ types : [published]
11
+
12
+ pull_request :
13
+ branches :
14
+ - ' *'
15
+ env :
16
+ REGISTRY : ghcr.io
17
+ IMAGE_NAME : ${{ github.repository }}
18
+ RELEASE : ${{ github.event.release != null && github.event.release.prerelease != true }}
19
+ PRERELEASE : ${{ github.event.release != null && github.event.release.prerelease == true }}
20
+
21
+
22
+ jobs :
23
+ build-and-push-image :
24
+ runs-on : ubuntu-latest
25
+ permissions :
26
+ contents : read
27
+ packages : write
28
+
29
+ steps :
30
+ - name : Checkout repository
31
+ uses : actions/checkout@v2
32
+
33
+ - name : Setup Python
34
+ uses : actions/setup-python@v2
35
+ with :
36
+ python-version : " 3.9"
37
+
38
+ - name : Log in to the Container registry
39
+ uses : docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
40
+ with :
41
+ registry : ${{ env.REGISTRY }}
42
+ username : ${{ github.actor }}
43
+ password : ${{ secrets.GITHUB_TOKEN }}
44
+
45
+ - name : Fix versions
46
+ run : python scripts/github_version_fix.py
47
+
48
+ - name : Setup docker buildx
49
+ uses : docker/setup-buildx-action@v1
50
+ id : buildx
51
+ with :
52
+ install : true
53
+ - name : Extract metadata (tags, labels) for Docker
54
+ id : meta
55
+ uses : docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
56
+ with :
57
+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
58
+ flavor : |
59
+ latest=${{ env.RELEASE }}
60
+ tags : |
61
+ type=ref, event=tag, enable=true
62
+ type=ref, event=branch, enable=true
63
+ type=ref, event=pr, enable=true
64
+ type=raw, value=prerelease, enable=${{ env.PRERELEASE }}
65
+ type=raw, value=stable, enable=${{ env.RELEASE }}
66
+ type=raw, value=${{ github.head_ref }}, enable=${{ github.event.pull_request != null}}
67
+
68
+ - name : Build and push Docker image
69
+
70
+ with :
71
+ context : .
72
+ file : docker/Dockerfile
73
+ push : ${{ github.event.release != null }}
74
+ tags : ${{ steps.meta.outputs.tags }}
75
+ labels : ${{ steps.meta.outputs.labels }}
76
+ cache-from : type=gha
77
+ cache-to : type=gha,mode=max
0 commit comments