Skip to content

Commit 5532bb9

Browse files
committed
update CICD workflow
1 parent 7665782 commit 5532bb9

2 files changed

Lines changed: 23 additions & 15 deletions

File tree

.github/workflows/backend_ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,12 @@ jobs:
6565
- name: Shut down
6666
if: always()
6767
run: docker-compose -f docker-compose.yml down
68-
68+
69+
- name: Login to Amazon ECR
70+
uses: aws-actions/amazon-ecr-login@v2
71+
72+
- name: Build and Push Docker Image to ECR
73+
run: |
74+
docker build -t ${{ secrets.ECR_REPO }}:latest .
75+
docker tag ${{ secrets.ECR_REPO }}:latest ${{ secrets.ECR_REPO }}:latest
76+
docker push ${{ secrets.ECR_REPO }}:latest

.github/workflows/deploy.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ name: Deploy to AWS ECR
22

33
on:
44
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
58

69
jobs:
7-
docker-build-push:
10+
deploy:
811
runs-on: ubuntu-latest
912

1013
steps:
11-
- name: Check out repository
12-
uses: actions/checkout@v4.2.2
14+
# - name: Check out repository
15+
# uses: actions/checkout@v4.2.2
1316

1417
- name: Configure AWS Credentials
1518
uses: aws-actions/configure-aws-credentials@v4
@@ -21,25 +24,22 @@ jobs:
2124
- name: Login to Amazon ECR
2225
uses: aws-actions/amazon-ecr-login@v2
2326

24-
- name: Build Docker image
25-
run: |
26-
docker build -t ${{ secrets.ECR_REPO }}:latest .
27+
# - name: Build Docker image
28+
# run: |
29+
# docker build -t ${{ secrets.ECR_REPO }}:latest .
30+
31+
# - name: Push Docker image to Amazon ECR
32+
# run: |
33+
# docker push ${{ secrets.ECR_REPO }}:latest
2734

28-
- name: Push Docker image to Amazon ECR
29-
run: |
30-
docker push ${{ secrets.ECR_REPO }}:latest
31-
32-
deploy:
33-
runs-on: ubuntu-latest
34-
needs: docker-build-push
35-
steps:
3635
- name: Deploy via SSH to EC2
3736
uses: appleboy/ssh-action@v1.2.0
3837
with:
3938
host: ${{ secrets.EC2_HOST }}
4039
username: ubuntu
4140
key: ${{ secrets.SSH_PRIVATE_KEY_EC2 }}
4241
script: |
42+
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.ECR_REPO }}
4343
cd /home/ubuntu/myapp
4444
docker-compose pull
4545
docker-compose up -d --force-recreate

0 commit comments

Comments
 (0)