@@ -34,16 +34,9 @@ concurrency:
3434
3535jobs :
3636 build :
37- if : github.repository == 'apache/cloudstack-kubernetes-provider' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
37+ if : github.repository == 'apache/cloudstack-kubernetes-provider'
3838 runs-on : ubuntu-22.04
3939 steps :
40- - name : Login to Docker Registry
41- uses : docker/login-action@v3
42- with :
43- registry : ${{ secrets.DOCKER_REGISTRY }}
44- username : ${{ secrets.DOCKERHUB_USER }}
45- password : ${{ secrets.DOCKERHUB_TOKEN }}
46-
4740 - name : Set Docker repository name
4841 run : echo "DOCKER_REPOSITORY=apache" >> $GITHUB_ENV
4942
5750 - name : Set Docker image FULL TAG
5851 run : echo "FULL_TAG=$(if [ "${{ secrets.DOCKER_REGISTRY }}" = "" ];then echo ${DOCKER_REPOSITORY}/cloudstack-kubernetes-provider:${TAG};else echo ${{ secrets.DOCKER_REGISTRY }}/${DOCKER_REPOSITORY}/cloudstack-kubernetes-provider:${TAG};fi)" >> $GITHUB_ENV
5952
60- - name : Build the Docker image for cloudstack-kubernetes-provider
61- run : docker build . --file Dockerfile --tag ${FULL_TAG}
53+ - name : Check if should push
54+ id : should_push
55+ run : |
56+ if [ "${{ github.event_name }}" != "pull_request" ] || [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
57+ echo "should_push=true" >> $GITHUB_OUTPUT
58+ else
59+ echo "should_push=false" >> $GITHUB_OUTPUT
60+ fi
6261
63- - name : Push Docker image to Docker Registry
64- run : docker push ${FULL_TAG}
62+ - name : Set up Docker Buildx
63+ uses : docker/setup-buildx-action@v3
64+
65+ - name : Login to Docker Registry
66+ if : steps.should_push.outputs.should_push == 'true'
67+ uses : docker/login-action@v3
68+ with :
69+ registry : ${{ secrets.DOCKER_REGISTRY }}
70+ username : ${{ secrets.DOCKERHUB_USER }}
71+ password : ${{ secrets.DOCKERHUB_TOKEN }}
72+
73+ - name : Set cache configuration
74+ id : cache_config
75+ run : |
76+ if [ "${{ steps.should_push.outputs.should_push }}" = "true" ]; then
77+ echo "cache_from=type=registry,ref=${FULL_TAG}-cache" >> $GITHUB_OUTPUT
78+ echo "cache_to=type=registry,ref=${FULL_TAG}-cache,mode=max" >> $GITHUB_OUTPUT
79+ fi
80+
81+ - name : Build and push Docker image for cloudstack-kubernetes-provider (multi-arch)
82+ uses : docker/build-push-action@v6
83+ with :
84+ context : .
85+ file : ./Dockerfile
86+ platforms : linux/amd64,linux/arm64
87+ push : ${{ steps.should_push.outputs.should_push == 'true' }}
88+ tags : ${{ env.FULL_TAG }}
89+ cache-from : ${{ steps.cache_config.outputs.cache_from }}
90+ cache-to : ${{ steps.cache_config.outputs.cache_to }}
0 commit comments