@@ -3,6 +3,9 @@ name: Build
33on :
44 workflow_call :
55 inputs :
6+ env-name :
7+ required : true
8+ type : string
69 tag-name :
710 description : Docker tag to create
811 required : false
3033 BUILD_NUMBER : ${{github.run_id}}
3134
3235 OUT_DIR : ./out
33- AWS_REGION : " us-east-1"
3436
35- ECR_REPO : 917902836630.dkr.ecr.us-east-1.amazonaws.com/api-server
36- ECR_ADDRESS : 917902836630.dkr.ecr.us-east-1.amazonaws.com
37+ # ECR_REPO: 917902836630.dkr.ecr.us-east-1.amazonaws.com/api-server
38+ # ECR_ADDRESS: 917902836630.dkr.ecr.us-east-1.amazonaws.com
3739
3840
3941jobs :
42+ setup-vars :
43+ uses : ./.github/workflows/_setup.yaml
44+ with :
45+ env-name : ${{ inputs.env-name }}
46+
4047 build :
4148 name : Docker Build and Push
4249 runs-on : ubuntu-latest
50+ needs : setup-vars
51+ env :
52+ AWS_REGION : ${{ needs.setup-vars.outputs.region }}
4353 outputs :
4454 image-name : ${{ steps.sha.outputs.IMAGE_NAME }}
4555 image-sha : ${{ steps.sha.outputs.SHORT_SHA }}
@@ -55,27 +65,21 @@ jobs:
5565 - name : configure aws credentials
5666 uses : aws-actions/configure-aws-credentials@v4
5767 with :
58- role-to-assume : arn:aws:iam::917902836630:role/cmiml- devops-oidc-github- role
68+ role-to-assume : ${{ needs.setup-vars.outputs. devops-role }}
5969 role-session-name : gha-oidc-runner
60- aws-region : ${{ env.AWS_REGION }}
70+ aws-region : ${{ needs.setup-vars.outputs.region }}
6171
62- - name : Get secrets by name and by ARN
63- uses : aws-actions/aws-secretsmanager-get-secrets@v2
64- with :
65- parse-json-secrets : true
66- secret-ids : |
67- ,cmiml-devops
6872
6973 - name : Login to ECR
7074 run : |
71- aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ env.ECR_ADDRESS }}
75+ aws ecr get-login-password --region ${{ needs.setup-vars.outputs.region }} | docker login --username AWS --password-stdin ${{ needs.setup-vars.outputs.ecr-repo }}
7276
7377 - name : Generate short sha
7478 id : sha
7579 run : |
7680 SHORT_SHA=$(git rev-parse --short HEAD)
7781 echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_OUTPUT
78- echo "IMAGE_NAME=${ECR_REPO} :${SHORT_SHA}" >> "$GITHUB_OUTPUT"
82+ echo "IMAGE_NAME=${{ needs.setup-vars.outputs.ecr-repo }}/api-server :${SHORT_SHA}" >> "$GITHUB_OUTPUT"
7983
8084 - name : Build and push
8185 uses : docker/build-push-action@v6
@@ -87,33 +91,10 @@ jobs:
8791 PIPENV_EXTRA_ARGS=--dev
8892 DD_GIT_REPOSITORY_URL=${{ github.repositoryUrl }}
8993 DD_GIT_COMMIT_SHA=${{ github.sha }}
90- cache-to : mode=max,image-manifest=true,oci-mediatypes=true,type=registry,ref=${{ env.ECR_REPO }}:cache
91- cache-from : type=registry,ref=${{ env.ECR_REPO }}:cache
94+ cache-to : mode=max,image-manifest=true,oci-mediatypes=true,type=registry,ref=${{ needs.setup-vars.outputs.ecr-repo }}/api-server :cache
95+ cache-from : type=registry,ref=${{ needs.setup-vars.outputs.ecr-repo }}/api-server :cache
9296 tags : |
93- ${{ env.ECR_REPO }}:${{ inputs.tag-name }}
94- ${{ env.ECR_REPO }}:${{ steps.sha.outputs.SHORT_SHA }}
97+ ${{ needs.setup-vars.outputs.ecr-repo }}/api-server :${{ inputs.tag-name }}
98+ ${{ needs.setup-vars.outputs.ecr-repo }}/api-server :${{ steps.sha.outputs.SHORT_SHA }}
9599 platforms : linux/amd64,linux/arm64
96100
97- # # TODO What is this used for? Leftover artifact from Jenkins
98- # - name: Extract Jira ticket numbers from commit message
99- # run: |
100- # tickets=$(git log -1 --pretty=%B | grep -io 'M2-[0-9]\+' | tr '[:lower:]' '[:upper:]' | sort | uniq | tr '\n' ' ')
101- # if [ -z "$tickets" ]; then
102- # echo "No Jira tickets found in the latest commit message."
103- # else
104- # echo "Jira ticket numbers found: ${tickets}"
105- # if [ "${GITHUB_BRANCH_OR_TAG}" != "develop" ]; then
106- # echo "Skipping saving Jira ticket numbers to a file because the branch is not develop"
107- # else
108- # file="jira-tickets.json"
109- # echo "{ \"issues\": $(echo "${tickets}" | jq -R -s -c 'split(" ")[:-1]') }" > "${file}"
110- # echo "Jira ticket numbers saved to ${file}"
111- # fi
112- # fi
113- #
114- # - name: Upload artifacts
115- # uses: actions/upload-artifact@v4
116- # with:
117- # name: build-artifacts
118- # path: |
119- # ${GITHUB_REPO_NAME}/${OUT_DIR}/jira-tickets.json
0 commit comments