11---
2- name : ' Reusable: Build and push image'
2+ name : " Reusable: Build and push image"
33
44" on " :
55 workflow_call :
@@ -17,32 +17,56 @@ name: 'Reusable: Build and push image'
1717 type : boolean
1818 default : false
1919 registry :
20- description : ' FQDN of the registry'
20+ description : " FQDN of the registry"
2121 type : string
22- required : true
22+ required : false
23+ default : " "
2324 registry_url :
24- description : ' URL to push image to'
25+ description : " URL to push image to"
2526 type : string
2627 required : false
27- default : ' harbor.puzzle.ch/pitc-ruby-public/ptime/int/rails '
28+ default : " "
2829
2930 secrets :
3031 PUZZLE_REGISTRY_USERNAME :
31- description : ' Needed for the registry login'
32+ description : " Needed for the registry login"
3233 required : true
3334 PUZZLE_REGISTRY_TOKEN :
34- description : ' Needed for the registry login'
35+ description : " Needed for the registry login"
3536 required : true
3637
3738jobs :
3839 build :
3940 environment : ${{ inputs.environment }}
40- runs-on : ' ubuntu-latest'
41+ runs-on : " ubuntu-latest"
42+
43+ env :
44+ BUILD_REGISTRY : ${{ inputs.registry || vars.REGISTRY }}
45+ BUILD_REGISTRY_URL : ${{ inputs.registry_url || vars.REGISTRY_URL }}
46+
4147 steps :
48+ - name : Input Validation
49+ run : |
50+ exit_code=0
51+
52+ if [ -z "${BUILD_REGISTRY}" ]; then
53+ echo "::error title=Configuration Error::BUILD_REGISTRY is empty."
54+ echo "Please ensure 'registry' input is set or 'REGISTRY' variable is configured in the ${{ inputs.environment }} environment."
55+ exit_code=1
56+ fi
57+
58+ if [ -z "${BUILD_REGISTRY_URL}" ]; then
59+ echo "::error title=Configuration Error::BUILD_REGISTRY_URL is empty."
60+ echo "Please ensure 'registry_url' input is set or 'REGISTRY_URL' variable is configured in the ${{ inputs.environment }} environment."
61+ exit_code=1
62+ fi
63+
64+ exit "${exit_code}"
65+
4266 - uses : docker/setup-buildx-action@v3
4367 - uses : docker/login-action@v3
4468 with :
45- registry : ${{ inputs.registry }}
69+ registry : ${{ env.BUILD_REGISTRY }}
4670 username : ${{ secrets.PUZZLE_REGISTRY_USERNAME }}
4771 password : ${{ secrets.PUZZLE_REGISTRY_TOKEN }}
4872 - uses : docker/build-push-action@v4
5579 GITHUB_SHA=${{ github.sha }}
5680 target : app
5781 tags : |
58- ${{ inputs.registry_url }}:latest
59- ${{ inputs.registry_url }}:${{ github.sha }}
82+ ${{ env.BUILD_REGISTRY_URL }}:latest
83+ ${{ env.BUILD_REGISTRY_URL }}:git- ${{ github.sha }}
6084 push : ${{ inputs.push }}
6185 cache-from : type=gha
6286 cache-to : type=gha,mode=max
63- ...
0 commit comments