66 types :
77 - created
88 schedule :
9- - cron : 00 00 * * *
9+ - cron : 00 00 * * 0
1010
1111permissions :
1212 contents : read
13+ # for docker/build-push-action to publish docker image
14+ packages : write
15+
16+ env :
17+ REGISTRY : ghcr.io
1318
1419jobs :
1520 docker :
16- permissions :
17- # for docker/build-push-action to publish docker image
18- packages : write
19-
2021 runs-on : ubuntu-latest
22+ strategy :
23+ matrix :
24+ include :
25+ - dockerfile : Dockerfile
26+ image_name : ${{ github.repository }}
27+ - dockerfile : Dockerfile.tools
28+ image_name : ${{ github.repository }}-tools
2129 steps :
2230 - name : Checkout code
2331 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -26,60 +34,48 @@ jobs:
2634
2735 - name : Set up Docker Buildx
2836 uses : docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
37+
2938 - name : Login to GitHub Container Registry
3039 uses : docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
3140 with :
32- registry : ghcr.io
33- username : ${{ github.repository_owner }}
41+ registry : ${{ env.REGISTRY }}
42+ username : ${{ github.actor }}
3443 password : ${{ secrets.GITHUB_TOKEN }}
35- - name : Set tag for image
36- env :
37- REF_TYPE : ${{ github.ref_type }}
38- REF_NAME : ${{ github.ref_name }}
39- run : >-
40- echo IMAGE_TAG=$(
41- [ $REF_TYPE == 'tag' ]
42- && echo $REF_NAME
43- || echo 'latest'
44- ) >> $GITHUB_ENV
45-
46- - name : Set IMAGE_REPO environment variable
47- # Lowercase the org/repo name to allow for workflow to run in forks,
48- # which owners have uppercase letters in username
49- run : >-
50- echo "IMAGE_REPO=ghcr.io/${GITHUB_REPOSITORY@L}" >> $GITHUB_ENV
51- - name : Set up Docker Buildx
52- uses : docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
5344
54- - name : Build and Push release
55- if : github.event_name != 'schedule'
56- uses : docker/build-push- action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
45+ - name : Extract metadata (tags, labels) for Docker
46+ id : meta
47+ uses : docker/metadata- action@c1e51972afc2121e065aed6d45c65596fe445f3f
5748 with :
58- context : .
59- build-args : |
60- INSTALL_ALL=true
61- platforms : linux/amd64,linux/arm64
62- push : true
49+ images : ${{ env.REGISTRY }}/${{ matrix.image_name }}
6350 tags : |
64- ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}
65- ${{ env.IMAGE_REPO }}:latest
66- # Fix multi-platform: https://github.com/docker/buildx/issues/1533
67- provenance : false
68- secrets : |
69- "github_token=${{ secrets.GITHUB_TOKEN }}"
51+ type=ref,event=branch
52+ type=ref,event=pr
53+ type=sha
54+ type=raw,value=latest,enable={{is_default_branch}}
55+ type=raw,value={{github.ref_name}},enable={{github.ref_type == 'tag'}}
56+ type=raw,value=nightly,enable={{github.event_name == 'schedule'}}
7057
71- - name : Build and Push nightly
72- if : github.event_name == 'schedule'
58+ - name : Build and Push release
7359 uses : docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
7460 with :
7561 context : .
62+ file : ${{ matrix.dockerfile }}
7663 build-args : |
7764 INSTALL_ALL=true
7865 platforms : linux/amd64,linux/arm64
7966 push : true
80- tags : |
81- ${{ env.IMAGE_REPO }}:nightly
67+ tags : ${{ steps.meta.outputs.tags }}
68+ labels : ${{ steps.meta.outputs.labels }}
8269 # Fix multi-platform: https://github.com/docker/buildx/issues/1533
8370 provenance : false
84- secrets : |
85- "github_token=${{ secrets.GITHUB_TOKEN }}"
71+
72+ - name : Test tools image
73+ if : matrix.dockerfile == 'Dockerfile.tools' && github.event_name != 'schedule'
74+ env :
75+ IMAGE_TAGS : ${{ steps.meta.outputs.tags }}
76+ run : |
77+ IMAGE_TAG=$(echo "$IMAGE_TAGS" | head -n1)
78+ echo "Testing tools image: $IMAGE_TAG"
79+ docker run --rm "$IMAGE_TAG" terraform --version
80+ docker run --rm "$IMAGE_TAG" terraform-docs --version
81+ docker run --rm "$IMAGE_TAG" tflint --version
0 commit comments