3232 name : Push Docker image to container registry
3333 runs-on : ubuntu-latest
3434 strategy :
35+ fail-fast : true
3536 matrix :
3637 dockerfile : [Dockerfile]
3738 concurrency :
4445 actions : read
4546 id-token : write
4647 steps :
47- - name : Check out the repo
48+ - name : Checkout code
4849 uses : actions/checkout@v4
4950
5051 - name : Set password by container registry
5354 "ghcr.io")
5455 echo "REGISTRY_PASS=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
5556 ;;
56- "*.dkr.ecr.*.amazonaws.com")
57- echo "Using AWS ECR - will authenticate in a separate step" >> $GITHUB_STEP_SUMMARY
58- ;;
59- "gcr.io")
60- echo "Using GCR - will authenticate in a separate step" >> $GITHUB_STEP_SUMMARY
61- ;;
6257 *)
6358 if [ -n "${{ secrets.REGISTRY_PASS }}" ]; then
6459 echo "REGISTRY_PASS=${{ secrets.REGISTRY_PASS }}" >> $GITHUB_ENV
@@ -69,67 +64,53 @@ jobs:
6964 ;;
7065 esac
7166
72- - name : Configure AWS Credentials
73- if : contains(env.REGISTRY_URL, '.dkr.ecr.')
74- uses : aws-actions/configure-aws-credentials@v4
75- with :
76- role-to-assume : ${{ secrets.AWS_ROLE_TO_ASSUME }}
77- aws-region : ${{ secrets.AWS_REGION }}
78-
79- - name : Login to Amazon ECR
80- if : contains(env.REGISTRY_URL, '.dkr.ecr.')
81- id : login-ecr
82- uses : aws-actions/amazon-ecr-login@v2
83-
84- - name : Authenticate to Google Cloud
85- if : env.REGISTRY_URL == 'gcr.io'
86- uses : google-github-actions/auth@v2
87- with :
88- credentials_json : ${{ secrets.GCP_SA_KEY }}
89-
9067 - name : Log into container registry
91- if : >
92- env.REGISTRY_URL != '*.dkr.ecr.*.amazonaws.com'
93- && env.REGISTRY_URL != 'gcr.io'
68+ if : github.event_name != 'pull_request'
9469 uses : docker/login-action@v3
9570 with :
9671 registry : ${{ env.REGISTRY_URL }}
9772 username : ${{ env.REGISTRY_USER }}
9873 password : ${{ env.REGISTRY_PASS }}
9974
100- - name : Extract image name from Dockerfile
75+ - name : Set image name
10176 id : image_name
10277 run : |
103- IMAGE=$(grep "LABEL org.opencontainers.image.title" ${{ matrix.dockerfile }} | cut -d'"' -f2)
78+ if [ -n "${{ env.IMAGE }}" ]; then
79+ IMAGE="${{ env.IMAGE }}"
80+ else
81+ IMAGE=$(grep "LABEL org.opencontainers.image.title" Dockerfile | cut -d'"' -f2)
82+ fi
10483 echo "IMAGE=$IMAGE" >> $GITHUB_OUTPUT
84+ echo "IMAGE=$IMAGE" >> $GITHUB_ENV
10585
106- - name : Extract metadata (tags, labels) for Docker
86+ - name : Docker meta
10787 id : meta
10888 uses : docker/metadata-action@v5
10989 with :
11090 images : |
11191 ${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.image_name.outputs.IMAGE }}
11292 tags : |
113- type=raw,value=latest,enable=${{ endsWith(github.ref, 'main') || endsWith(github.ref, 'master') }}
114- type=ref,event=branch,enable=${{ !endsWith(github.ref, 'main') && !endsWith(github.ref, 'master') }}
93+ type=schedule
94+ type=ref,event=branch
95+ type=ref,event=pr
11596 type=semver,pattern={{version}}
116- flavor : |
117- latest=false
97+ type=semver,pattern={{major}}.{{minor}}
98+ type=semver,pattern={{major}}
99+ type=sha
100+ type=raw,value=latest,enable={{is_default_branch}}
118101
119- - name : Set up QEMU
102+ - name : Setup QEMU
120103 uses : docker/setup-qemu-action@v3
121104
122- - name : Set up Docker Buildx
105+ - name : Setup Docker Buildx
123106 uses : docker/setup-buildx-action@v3
124107
125- - name : Build and push Docker image
108+ - name : Build and push
126109 uses : docker/build-push-action@v6
127110 with :
128111 context : .
129112 file : ./${{ matrix.dockerfile }}
130- push : true
131113 tags : ${{ steps.meta.outputs.tags }}
132114 labels : ${{ steps.meta.outputs.labels }}
133- platforms : linux/amd64,linux/arm64/v8
134- cache-from : type=registry,ref=${{ steps.meta.outputs.tags }}
135- cache-to : type=registry,ref=${{ steps.meta.outputs.tags }},mode=max
115+ cache-from : type=registry,ref=${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.image_name.outputs.IMAGE }}:buildcache
116+ cache-to : type=registry,ref=${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.image_name.outputs.IMAGE }}:buildcache,mode=max
0 commit comments