Skip to content

Commit 8e4b3ea

Browse files
committed
#45 fix: jobs로 CI/CD 통합 파일로 구성
1 parent da09f1f commit 8e4b3ea

File tree

3 files changed

+56
-73
lines changed

3 files changed

+56
-73
lines changed

.github/workflows/backend.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy with Docker Compose
1+
name: CI/CD Pipeline
22

33
on:
44
push:
@@ -9,9 +9,61 @@ on:
99
workflow_dispatch:
1010

1111
jobs:
12-
deploy:
12+
frontend:
13+
name: Build & Push Frontend
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v3
18+
19+
- name: Configure AWS Credentials
20+
uses: aws-actions/configure-aws-credentials@v2
21+
with:
22+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
23+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
24+
aws-region: ap-northeast-2
25+
26+
- name: Login to Amazon ECR
27+
uses: aws-actions/amazon-ecr-login@v1
28+
29+
- name: Build Docker image and push to AWS ECR
30+
run: |
31+
cd frontend
32+
docker build -t frontend-service .
33+
docker tag frontend-service:latest ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest
34+
docker push ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest
35+
36+
backend:
37+
name: Build & Push Backend
1338
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v3
42+
43+
- name: Configure AWS Credentials
44+
uses: aws-actions/configure-aws-credentials@v2
45+
with:
46+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
47+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
48+
aws-region: ap-northeast-2
49+
50+
- name: Login to AWS ECR
51+
run: |
52+
ECR_URL="${{ secrets.AWS_ECR_REPOSITORY }}"
53+
echo "Logging into AWS ECR: $ECR_URL"
54+
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_URL
1455
56+
- name: Build Docker image and push to AWS ECR
57+
run: |
58+
cd backend
59+
docker build -t backend-service .
60+
docker tag backend-service:latest ${{ secrets.AWS_ECR_REPOSITORY }}:latest
61+
docker push ${{ secrets.AWS_ECR_REPOSITORY }}:latest
62+
63+
deploy:
64+
name: Deploy to EC2
65+
runs-on: ubuntu-latest
66+
needs: [frontend, backend]
1567
steps:
1668
- uses: actions/checkout@v3
1769

@@ -42,10 +94,10 @@ jobs:
4294
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
4395
script: |
4496
cd /home/${{ secrets.EC2_USERNAME }}/postdm
45-
97+
4698
echo "Logging in to ECR..."
4799
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.ECR_REGISTRY }}
48-
100+
49101
echo "Updating .env file"
50102
cat <<EOF > .env
51103
MYSQL_URL=${{ secrets.MYSQL_URL }}

.github/workflows/frontend.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)