44 inputs :
55 env :
66 type : choice
7- description : ' AWS Incubator Env'
8- options :
9- - dev
10- - prod
7+ description : " AWS Incubator Env"
8+ options :
9+ - dev
10+ - prod
1111 ref :
12- description : ' Branch, Tag, or SHA'
12+ description : " Branch, Tag, or SHA"
1313 required : true
1414env :
1515 AWS_SHARED_CLUSTER : incubator-prod
1919 DOCKER_PATH : backend
2020jobs :
2121 setup_env :
22- name : Set-up environment
22+ name : Set-up environment
2323 runs-on : ubuntu-latest
2424 steps :
25- - name : Debug Action
26- 27- - name : Checkout
28- uses : actions/checkout@v4
29- with :
30- ref : ${{ github.event.inputs.ref }}
31- - name : Set AWS Env & Image Tag per workflow
32- run : |
33- SHORT_SHA=$(git rev-parse --short HEAD)
34- if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
35- INPUT_ENV=${{ github.event.inputs.env }}; INPUT_REF=${{ github.event.inputs.ref }}
36- echo AWS_APPENV="$AWS_APP_NAME"-$INPUT_ENV >> $GITHUB_ENV
37- echo IMAGE_TAG=$SHORT_SHA >> $GITHUB_ENV
38- fi
25+ - name : Debug Action
26+ 27+ - name : Checkout
28+ uses : actions/checkout@v4
29+ with :
30+ ref : ${{ github.event.inputs.ref }}
31+ - name : Set AWS Env & Image Tag per workflow
32+ run : |
33+ SHORT_SHA=$(git rev-parse --short HEAD)
34+ if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
35+ INPUT_ENV=${{ github.event.inputs.env }}; INPUT_REF=${{ github.event.inputs.ref }}
36+ echo AWS_APPENV="$AWS_APP_NAME"-$INPUT_ENV >> $GITHUB_ENV
37+ echo IMAGE_TAG=$SHORT_SHA >> $GITHUB_ENV
38+ fi
3939 outputs :
4040 AWS_APPENV : ${{ env.AWS_APPENV }}
4141 IMAGE_TAG : ${{ env.IMAGE_TAG }}
@@ -44,70 +44,69 @@ jobs:
4444 runs-on : ubuntu-latest
4545 needs : [setup_env]
4646 steps :
47- - name : Checkout
48- uses : actions/checkout@v4
49- with :
50- ref : ${{ github.event.inputs.ref }}
51- - name : Configure AWS credentials
52- uses : aws-actions/configure-aws-credentials@v1
53- with :
54- aws-access-key-id : ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
55- aws-secret-access-key : ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
56- aws-region : ${{ env.AWS_REGION }}
57- - name : Login to Amazon ECR
58- id : login-ecr
59- uses : aws-actions/amazon-ecr-login@v1
60- - name : Init Docker Cache
61- 62- with :
63- key : ${{ github.workflow }}-2-{hash}
64- restore-keys : |
65- ${{ github.workflow }}-2-
66- - name : Build & Push Image to ECR
67- uses : kciter/aws-ecr-action@v3
68- with :
69- access_key_id : ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
70- secret_access_key : ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
71- account_id : ${{ secrets.INCUBATOR_AWS_ACCOUNT_ID }}
72- repo : ${{ needs.setup_env.outputs.AWS_APPENV }}
73- region : ${{ env.AWS_REGION }}
74- tags : latest,${{ needs.setup_env.outputs.IMAGE_TAG }}
75- dockerfile : ${{ env.DOCKERFILE }}
76- path : ${{ env.DOCKER_PATH }}
47+ - name : Checkout
48+ uses : actions/checkout@v4
49+ with :
50+ ref : ${{ github.event.inputs.ref }}
51+ - name : Configure AWS credentials
52+ uses : aws-actions/configure-aws-credentials@v4
53+ with :
54+ aws-access-key-id : ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
55+ aws-secret-access-key : ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
56+ aws-region : ${{ env.AWS_REGION }}
57+ - name : Login to Amazon ECR
58+ id : login-ecr
59+ uses : aws-actions/amazon-ecr-login@v2
60+ - name : Set up Docker Buildx
61+ uses : docker/setup-buildx-action@v3
62+ - name : Build & Push Image to ECR
63+ env :
64+ ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
65+ ECR_REPOSITORY : ${{ needs.setup_env.outputs.AWS_APPENV }}
66+ IMAGE_TAG : ${{ needs.setup_env.outputs.IMAGE_TAG }}
67+ run : |
68+ docker buildx build \
69+ --platform linux/amd64 \
70+ --cache-from type=gha \
71+ --cache-to type=gha,mode=max \
72+ --push \
73+ -f ${{ env.DOCKERFILE }} \
74+ -t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
75+ -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
76+ ${{ env.DOCKER_PATH }}
7777 deploy :
7878 name : Deploy to AWS ECS
7979 runs-on : ubuntu-latest
8080 needs : [setup_env, build]
8181 steps :
82- - name : Configure AWS credentials
83- uses : aws-actions/configure-aws-credentials@v1
84- with :
85- aws-access-key-id : ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
86- aws-secret-access-key : ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
87- aws-region : ${{ env.AWS_REGION }}
88- - name : Login to Amazon ECR
89- id : login-ecr
90- uses : aws-actions/amazon-ecr-login@v1
91- - name : Pull Task Definition & write to file
92- id : aws-task-definition
93- run : |
94- aws ecs describe-task-definition \
95- --task-definition ${{ needs.setup_env.outputs.AWS_APPENV }} \
96- --query taskDefinition | \
97- jq 'del(.taskDefinitionArn,.revision,.status,.registeredBy,.registeredAt,.compatibilities,.requiresAttributes)' > task-def.json
98- - name : Interpolate new Docker Image into Task Definition
99- id : task-definition
100- uses : aws-actions/amazon-ecs-render-task-definition@v1
101- with :
102- task-definition : task-def.json
103- container-name : ${{ needs.setup_env.outputs.AWS_APPENV }}
104- image : ${{ steps.login-ecr.outputs.registry }}/${{ needs.setup_env.outputs.AWS_APPENV }}:${{ needs.setup_env.outputs.IMAGE_TAG }}
105- - name : Deploy Amazon ECS
106- uses : aws-actions/amazon-ecs-deploy-task-definition@v1
107- with :
108- task-definition : ${{ steps.task-definition.outputs.task-definition }}
109- service : ${{ needs.setup_env.outputs.AWS_APPENV }}
110- cluster : ${{ env.AWS_SHARED_CLUSTER }}
111- wait-for-service-stability : true
112- wait-for-minutes : 5 minutes
113-
82+ - name : Configure AWS credentials
83+ uses : aws-actions/configure-aws-credentials@v4
84+ with :
85+ aws-access-key-id : ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
86+ aws-secret-access-key : ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
87+ aws-region : ${{ env.AWS_REGION }}
88+ - name : Login to Amazon ECR
89+ id : login-ecr
90+ uses : aws-actions/amazon-ecr-login@v2
91+ - name : Pull Task Definition & write to file
92+ id : aws-task-definition
93+ run : |
94+ aws ecs describe-task-definition \
95+ --task-definition ${{ needs.setup_env.outputs.AWS_APPENV }} \
96+ --query taskDefinition | \
97+ jq 'del(.taskDefinitionArn,.revision,.status,.registeredBy,.registeredAt,.compatibilities,.requiresAttributes)' > task-def.json
98+ - name : Interpolate new Docker Image into Task Definition
99+ id : task-definition
100+ uses : aws-actions/amazon-ecs-render-task-definition@v1
101+ with :
102+ task-definition : task-def.json
103+ container-name : ${{ needs.setup_env.outputs.AWS_APPENV }}
104+ image : ${{ steps.login-ecr.outputs.registry }}/${{ needs.setup_env.outputs.AWS_APPENV }}:${{ needs.setup_env.outputs.IMAGE_TAG }}
105+ - name : Deploy Amazon ECS
106+ uses : aws-actions/amazon-ecs-deploy-task-definition@v1
107+ with :
108+ task-definition : ${{ steps.task-definition.outputs.task-definition }}
109+ service : ${{ needs.setup_env.outputs.AWS_APPENV }}
110+ cluster : ${{ env.AWS_SHARED_CLUSTER }}
111+ wait-for-service-stability : true
112+ wait-for-minutes : 5
0 commit comments