1010# If the required repository variables aren't set the workflow will be skipped. This means the workflow won't fail
1111# on the forks of developers who haven't configured the variables/secrets.
1212
13+
1314name : Docker Build
1415
1516on :
2526jobs :
2627 build :
2728 runs-on : ubuntu-latest
28- if : ${{ vars.REGISTRY_SERVER != '' && vars.REGISTRY_USERNAME != '' && vars.REGISTRY_ORGANISATION != '' && vars.PROXY_IMAGE_NAME != '' && vars.OPERATOR_IMAGE_NAME != '' }}
2929 steps :
3030 - name : Checkout
3131 uses : actions/checkout@v4
@@ -43,14 +43,29 @@ jobs:
4343 distribution : ' temurin'
4444 java-version : ' 17'
4545
46- - name : Set env variables
46+ - name : Determine Build Configuration
47+ id : build_configuration
4748 run : |
48- echo "RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
49- echo "PROXY_IMAGE=${{ vars.REGISTRY_SERVER }}/${{ vars.REGISTRY_ORGANISATION }}/${{ vars.PROXY_IMAGE_NAME }}" >> $GITHUB_ENV
50- echo "OPERATOR_IMAGE=${{ vars.REGISTRY_SERVER }}/${{ vars.REGISTRY_ORGANISATION }}/${{ vars.OPERATOR_IMAGE_NAME }}" >> $GITHUB_ENV
49+ RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
50+ echo "release_version=${RELEASE_VERSION}" >> $GITHUB_OUTPUT
51+
52+ # For PRs, or if registry vars are not set, use default local-only tags.
53+ # This allows the build to succeed without attempting to push.
54+ if [[ "${{ github.event_name }}" == "pull_request" || "${{ vars.REGISTRY_SERVER }}" == "" ]]; then
55+ echo "proxy_tags=kroxylicious-proxy:${RELEASE_VERSION}" >> $GITHUB_OUTPUT
56+ echo "operator_tags=kroxylicious-operator:${RELEASE_VERSION}" >> $GITHUB_OUTPUT
57+ echo "push_images=false" >> $GITHUB_OUTPUT
58+ else
59+ PROXY_IMAGE="${{ vars.REGISTRY_SERVER }}/${{ vars.REGISTRY_ORGANISATION }}/${{ vars.PROXY_IMAGE_NAME }}"
60+ OPERATOR_IMAGE="${{ vars.REGISTRY_SERVER }}/${{ vars.REGISTRY_ORGANISATION }}/${{ vars.OPERATOR_IMAGE_NAME }}"
61+ echo "proxy_tags=${PROXY_IMAGE}:${RELEASE_VERSION}" >> $GITHUB_OUTPUT
62+ echo "operator_tags=${OPERATOR_IMAGE}:${RELEASE_VERSION},${OPERATOR_IMAGE}:latest" >> $GITHUB_OUTPUT
63+ echo "push_images=true" >> $GITHUB_OUTPUT
64+ fi
5165
5266 - name : Login to container registry
53- if : github.event_name == 'push' || github.event_name == 'workflow_dispatch'
67+ # Only login when pushing an image and when the required variables are set.
68+ if : steps.build_configuration.outputs.push_images == 'true'
5469 uses : docker/login-action@v3
5570 with :
5671 registry : ${{ vars.REGISTRY_SERVER }}
@@ -62,10 +77,10 @@ jobs:
6277 with :
6378 context : .
6479 platforms : linux/amd64,linux/arm64
65- push : ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch ' }}
80+ push : ${{ steps.build_configuration.outputs.push_images == 'true ' }}
6681 build-args : |
67- KROXYLICIOUS_VERSION=${{ env.RELEASE_VERSION }}
68- tags : ${{ env.PROXY_IMAGE }}:${{ env.RELEASE_VERSION }}
82+ KROXYLICIOUS_VERSION=${{ steps.build_configuration.outputs.release_version }}
83+ tags : ${{ steps.build_configuration.outputs.proxy_tags }}
6984 cache-from : type=gha
7085 cache-to : type=gha,mode=max,compression=zstd
7186
7590 context : .
7691 file : ./Dockerfile.operator
7792 platforms : linux/amd64,linux/arm64
78- push : ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch ' }}
93+ push : ${{ steps.build_configuration.outputs.push_images == 'true ' }}
7994 build-args : |
80- KROXYLICIOUS_VERSION=${{ env.RELEASE_VERSION }}
81- tags : ${{ env.OPERATOR_IMAGE }}:${{ env.RELEASE_VERSION }},${{ env.OPERATOR_IMAGE }}:latest
95+ KROXYLICIOUS_VERSION=${{ steps.build_configuration.outputs.release_version }}
96+ tags : ${{ steps.build_configuration.outputs.operator_tags }}
8297 cache-from : type=gha
8398 cache-to : type=gha,mode=max,compression=zstd
0 commit comments