-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Reusable workflow to build and push Docker image to Amazon ECR | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
aws_region: | ||
description: 'AWS Region for ECR' | ||
required: true | ||
type: string | ||
|
||
|
||
# Permission can be added at job level or workflow level | ||
permissions: | ||
id-token: write # This is required for requesting the JWT | ||
contents: read # This is required for actions/checkout | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 | ||
|
||
- name: Print out aws region | ||
run: | | ||
echo "AWS Region: ${{ inputs.aws_region }}" | ||
- name: configure aws credentials | ||
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2 | ||
with: | ||
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_STORY_SERVICES_STAGING }}:role/GitHubAction-AssumeRoleWithAction | ||
role-session-name: GitHub_to_AWS_via_FederatedOIDC | ||
aws-region: ${{ inputs.aws_region }} | ||
|
||
- name: Sts GetCallerIdentity | ||
run: | | ||
aws sts get-caller-identity | ||
- name: Get AWS ECR login using oidc token | ||
run: | | ||
aws ecr get-login-password --region ${{ inputs.aws_region }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_STORY_SERVICES_STAGING }}.dkr.ecr.${{ inputs.aws_region }}.amazonaws.com | ||
|
||
|
||
# [Extremely Important] | ||
- name: Remove the cached AWS credentials from the runner | ||
run: | | ||
rm -rf /home/runner/.docker/config.json |