1
+ name : Docker
2
+
3
+ on :
4
+ push :
5
+ tags : [ 'v*.*.*' ]
6
+
7
+ env :
8
+ # Use docker.io for Docker Hub if empty
9
+ REGISTRY : ghcr.io
10
+ # github.repository as <account>/<repo>
11
+ IMAGE_NAME : ${{ github.repository }}
12
+
13
+ jobs :
14
+ build :
15
+
16
+ runs-on : ubuntu-latest
17
+ permissions :
18
+ contents : write
19
+ packages : write
20
+
21
+ steps :
22
+ - name : Checkout repository (with submodules)
23
+ uses : actions/checkout@v2
24
+ with :
25
+ submodules : recursive
26
+
27
+ - name : Extract semver
28
+ id : get_version
29
+ uses : battila7/get-version-action@v2
30
+
31
+ # Lowercase image name, as mixed case is not allowed while caching
32
+ - name : lowercase IMAGE_NAME
33
+ run : |
34
+ echo "IMAGE_NAME_LOWER=${IMAGE_NAME,,}" >>${GITHUB_ENV}
35
+ env :
36
+ IMAGE_NAME : ' ${{ env.IMAGE_NAME }}'
37
+
38
+ # Login against a Docker registry except on PR
39
+ # https://github.com/docker/login-action
40
+ - name : Log into registry ${{ env.REGISTRY }}
41
+ if : github.event_name != 'pull_request'
42
+ uses : docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
43
+ with :
44
+ registry : ${{ env.REGISTRY }}
45
+ username : ${{ github.actor }}
46
+ password : ${{ secrets.GITHUB_TOKEN }}
47
+
48
+ # Extract metadata (tags, labels) for Docker
49
+ # https://github.com/docker/metadata-action
50
+ - name : Extract Docker metadata
51
+ id : meta
52
+ uses : docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
53
+ with :
54
+ flavor : |
55
+ latest=${{ !github.event.release.prerelease }}
56
+ tags : |
57
+ type=semver,pattern={{version}}
58
+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}
59
+
60
+ - name : Set up Docker Buildx
61
+ id : buildx
62
+ uses : docker/setup-buildx-action@master
63
+
64
+ # Build and push Docker image with Buildx
65
+ # https://github.com/docker/build-push-action
66
+
67
+ - name : Build and push Docker image
68
+ uses : docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
69
+ with :
70
+ context : .
71
+ builder : ${{ steps.buildx.outputs.name }}
72
+ push : true
73
+ tags : ${{ steps.meta.outputs.tags }}
74
+ labels : ${{ steps.meta.outputs.labels }}
75
+ cache-from : type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:latest
76
+ cache-to : type=inline
77
+ build-args : |
78
+ API_VERSION=${{steps.get_version.outputs.version-without-v}}
79
+
80
+ - name : Generate SBOM
81
+
82
+ with :
83
+ image : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:${{steps.get_version.outputs.version-without-v}}
84
+ github-token : ${{ secrets.GITHUB_TOKEN }}
85
+ format : cyclonedx-json
0 commit comments