Skip to content

Commit 913154b

Browse files
authored
Create deploy.yml
1 parent 1191450 commit 913154b

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: CI-CD Deploy to ECS
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
env:
8+
AWS_REGION: us-east-1
9+
ECR_REPOSITORY: ci-cd-app
10+
ECS_CLUSTER: ci-cd-cluster
11+
ECS_SERVICE: ci-cd-service
12+
ECS_TASK_DEFINITION: ci-cd-task
13+
CONTAINER_NAME: ci-cd-app
14+
15+
jobs:
16+
deploy:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repo
21+
uses: actions/checkout@v3
22+
23+
- name: Configure AWS credentials
24+
uses: aws-actions/configure-aws-credentials@v4
25+
with:
26+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
27+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
28+
aws-region: ${{ env.AWS_REGION }}
29+
30+
- name: Login to ECR
31+
uses: aws-actions/amazon-ecr-login@v2
32+
33+
- name: Build Docker image
34+
run: |
35+
docker build -t $ECR_REPOSITORY:latest .
36+
37+
- name: Tag image
38+
run: |
39+
docker tag $ECR_REPOSITORY:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/$ECR_REPOSITORY:latest
40+
41+
- name: Push image
42+
run: |
43+
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/$ECR_REPOSITORY:latest
44+
45+
- name: Update ECS service (force new deployment)
46+
run: |
47+
aws ecs update-service \
48+
--cluster $ECS_CLUSTER \
49+
--service $ECS_SERVICE \
50+
--force-new-deployment

0 commit comments

Comments
 (0)