1
+ name : " ECR-ECS-Deployment"
2
+ on :
3
+ workflow_dispatch :
4
+
5
+ jobs :
6
+ ECR_ECS_Deployment :
7
+ name : Build Docker Image And Push To ECR And Deploy To ECS
8
+ runs-on : ubuntu-latest
9
+ steps :
10
+ - name : Checkout
11
+ uses : actions/checkout@v2
12
+
13
+ - name : Setup AWS ECR Details
14
+ uses : aws-actions/configure-aws-credentials@v1
15
+ with :
16
+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
17
+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
18
+ aws-region : ${{secrets.AWS_REGION}}
19
+
20
+ - name : Login to Amazon ECR
21
+ id : login-pf-aws-ecr
22
+ uses : aws-actions/amazon-ecr-login@v1
23
+
24
+ - name : Build and push the tagged docker image to Amazon ECR
25
+ id : containerImage
26
+ env :
27
+ ECR_REGISTRY : ${{ steps.login-pf-aws-ecr.outputs.registry }}
28
+ ECR_REPOSITORY : ${{secrets.AWS_ECR_REPO}}
29
+ IMAGE_TAG : latest
30
+ run : |
31
+ docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
32
+ docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
33
+
34
+ - name : ECR Status Check
35
+ if : steps.containerImage.outcome == 'failure'
36
+ run : exit 1
37
+
38
+ - name : Setup Terraform
39
+
40
+ with :
41
+ terraform_version : latest
42
+ cli_config_credentials_token : ${{ secrets.TFC_API_TOKEN }}
43
+
44
+ - name : Terraform Init
45
+ id : init
46
+ run : terraform init
47
+
48
+ - name : Terraform Validate
49
+ id : validate
50
+ run : terraform validate
51
+
52
+ - name : Terraform Plan
53
+ id : plan
54
+ run : terraform plan
55
+ continue-on-error : true
56
+
57
+ - name : Terraform Plan Status
58
+ if : steps.plan.outcome == 'failure'
59
+ run : exit 1
60
+
61
+ - name : Terraform Apply
62
+ run : terraform apply -auto-approve
0 commit comments