1
+ name : Build and push Docker images
2
+
3
+ on :
4
+ push :
5
+ branches :
6
+ - ' main'
7
+ - ' docker'
8
+
9
+ jobs :
10
+ generate-matrix :
11
+ runs-on : ubuntu-latest
12
+ outputs :
13
+ matrix-metadata : ${{ steps.metadata.outputs.matrix }}
14
+ steps :
15
+ - uses : hellofresh/action-changed-files@v3
16
+ id : metadata
17
+ with :
18
+ pattern : docker/(?P<image_dir>\w+)/.*
19
+ default-patterns : |
20
+ meta.yml
21
+ Dockerfile
22
+
23
+ update-docker :
24
+ needs : [generate-matrix]
25
+ strategy :
26
+ matrix : ${{ fromJson(needs.generate-matrix.outputs.matrix-metadata) }}
27
+ if : ${{ fromJson(needs.generate-matrix.outputs.matrix-metadata).include[0] }} # skip if the matrix is empty!
28
+ runs-on : ubuntu-latest
29
+ steps :
30
+ - uses : actions/checkout@v4
31
+ -
uses :
pietrobolcato/[email protected]
32
+ id : metadata
33
+ with :
34
+ config : ${{ github.workspace }}/docker/${{ matrix.image_dir }}/meta.yml
35
+ - name : Get date
36
+ id : date
37
+ run : |
38
+ echo "DATE=$(date +"%Y-%m-%d")" >> $GITHUB_OUTPUT
39
+ - name : Login to DockerHub
40
+ # if: github.event_name != 'pull_request'
41
+ uses : docker/login-action@v2
42
+ with :
43
+ username : ${{ secrets.DOCKERHUB_USERNAME }}
44
+ password : ${{ secrets.DOCKERHUB_TOKEN }}
45
+ - name : Build and push
46
+ uses : docker/build-push-action@v4
47
+ # only try building & pushing the container if parsing the metadata worked
48
+ if : ${{ steps.metadata.outputs['container'] != '' }}
49
+ with :
50
+ context : docker/${{ matrix.image_dir }}
51
+ # only push container to docker hub if not triggered from a PR
52
+ push : ${{ github.event_name != 'pull_request' }}
53
+ tags : ${{ steps.metadata.outputs['container'] }}
54
+ build-args : |
55
+ BUILD_DATE=${{ steps.date.outputs.DATE }}
56
+ BUILD_TAG=${{ steps.metadata.outputs['version'] }}
57
+ REPONAME=${{ steps.metadata.outputs['image_name'] }}
0 commit comments