From 4d49527f2912b52336cb24724f8558805e164182 Mon Sep 17 00:00:00 2001 From: rimeir Date: Wed, 16 Apr 2025 23:24:05 +0900 Subject: [PATCH 01/25] =?UTF-8?q?#45=20feat:=20EC2=20=EB=B0=B0=ED=8F=AC?= =?UTF-8?q?=EC=9A=A9=20=ED=86=B5=ED=95=A9=20docker-compose.yml=20=EA=B5=AC?= =?UTF-8?q?=EC=84=B1=20(=ED=94=84=EB=A1=A0=ED=8A=B8+=EB=B0=B1=EC=97=94?= =?UTF-8?q?=EB=93=9C+DB+nginx)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 61 +++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 548186f..fc1526b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,44 @@ version: '3.8' services: + db: + container_name: mysql + image: mysql:8.0 + restart: always + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD} + MYSQL_DATABASE: ${MYSQL_DATABASE} + MYSQL_USER: ${MYSQL_USERNAME} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + ports: + - "3306:3306" + volumes: + - mysql_data:/var/lib/mysql # 데이터를 Docker Volume에 저장 + healthcheck: + test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ] + interval: 10s + timeout: 5s + retries: 5 + start_period: 20s + env_file: + - .env + + frontend: + container_name: frontend + image: frontend-service +# build: +# context: frontend +# dockerfile: Dockerfile + ports: + - "3000:3000" + restart: always + backend: container_name: backend image: backend-service - build: - context: backend - dockerfile: Dockerfile +# build: +# context: backend +# dockerfile: Dockerfile ports: - "8080:8080" environment: @@ -15,28 +47,17 @@ services: SPRING_DATASOURCE_PASSWORD: ${MYSQL_PASSWORD} env_file: - .env - healthcheck: - test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ] - interval: 10s - retries: 5 - start_period: 20s - timeout: 5s volumes: - ./config/application-prod.yml:/app/config/application-prod.yml - db: - container_name: mysql - image: mysql:8.0 - restart: always - environment: - MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD} - MYSQL_DATABASE: ${MYSQL_DATABASE} - MYSQL_USER: ${MYSQL_USERNAME} - MYSQL_PASSWORD: ${MYSQL_PASSWORD} + nginx: + image: nginx:latest + container_name: nginx ports: - - "3306:3306" + - "80:80" + - "443:443" volumes: - - mysql_data:/var/lib/mysql # 데이터를 Docker Volume에 저장 + - ./nginx/nginx.conf:/etc/nginx/nginx.conf volumes: mysql_data: # 데이터 영구 저장 Docker Volume \ No newline at end of file From cd3f3b18bc46160d50650ac3d7e7c2bb92e24246 Mon Sep 17 00:00:00 2001 From: rimeir Date: Wed, 16 Apr 2025 23:24:29 +0900 Subject: [PATCH 02/25] =?UTF-8?q?#45=20feat:=20feat:=20nginx=20=EB=A6=AC?= =?UTF-8?q?=EB=B2=84=EC=8A=A4=20=ED=94=84=EB=A1=9D=EC=8B=9C=20=EB=B0=8F=20?= =?UTF-8?q?HTTPS=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx/nginx.conf | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 nginx/nginx.conf diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..c4a7a4b --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,56 @@ +http { + server { + listen 80; + server_name postdmex.com www.postdmex.com; + + location / { + proxy_pass http://frontend:3000; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /api/ { + proxy_pass http://backend:8080; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location ~ /.well-known/acme-challenge/ { + root /var/www/html; + } + } + + server { + listen 443 ssl; + server_name postdmex.com www.postdmex.com; + + ssl_certificate /etc/letsencrypt/live/postdmex.com/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/postdmex.com/privkey.pem; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers HIGH:!aNULL:!MD5; + + location / { + proxy_pass http://frontend:3000; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /api/ { + proxy_pass http://backend:8080; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + } +} \ No newline at end of file From 65a8d189d6f649095d934cc002e6ffafd6f45d70 Mon Sep 17 00:00:00 2001 From: rimeir Date: Wed, 16 Apr 2025 23:37:43 +0900 Subject: [PATCH 03/25] =?UTF-8?q?#45=20feat:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=20SSR=EC=9A=A9=20Dockerfile=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/Dockerfile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 frontend/Dockerfile diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..36c6c6c --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,11 @@ +FROM node:18-alpine + +WORKDIR /app + +COPY . . + +RUN npm install +RUN npm run build + +EXPOSE 3000 +CMD ["npm", "start"] \ No newline at end of file From 1fab8662b1953782c2a934598f42e62cc630653e Mon Sep 17 00:00:00 2001 From: rimeir Date: Wed, 16 Apr 2025 23:38:05 +0900 Subject: [PATCH 04/25] =?UTF-8?q?#45=20feat:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C=20GitHub=20Actions=20=EB=B0=B0=ED=8F=AC=20?= =?UTF-8?q?=EC=9B=8C=ED=81=AC=ED=94=8C=EB=A1=9C=EC=9A=B0=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/frontend.yml | 76 ++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/frontend.yml diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml new file mode 100644 index 0000000..7406e91 --- /dev/null +++ b/.github/workflows/frontend.yml @@ -0,0 +1,76 @@ +name: Deploy Frontend to EC2 + +on: + push: + branches: + - main + - develop + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Get GitHub Actions Public IP + id: ip + uses: haythem/public-ip@v1.3 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ap-northeast-2 + + - name: Authorize GitHub IP for EC2 SSH + run: | + aws ec2 authorize-security-group-ingress \ + --group-id ${{ secrets.AWS_SECURITY_GROUP_ID }} \ + --protocol tcp \ + --port 22 \ + --cidr ${{ steps.ip.outputs.ipv4 }}/32 + + - name: Login to Amazon ECR + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build Docker image and push to AWS ECR + run: | + cd frontend + docker build -t frontend-service . + docker tag backend-service:latest ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest + docker push ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest + + - name: SSH into EC2 and deploy frontend + uses: appleboy/ssh-action@v0.1.10 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} + port: ${{ secrets.PORT }} + script: | + cd /home/${{ secrets.EC2_USERNAME }}/frontend + + echo "Logging into ECR and pulling image..." + aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }} + +# echo "Updating environment variables..." +# cat < .env +# NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }} +# BASE_URL=${{ secrets.BASE_URL }} +# EOF + + echo "Deploying frontend container..." + docker compose pull frontend + docker compose up -d --no-deps frontend + + - name: Remove GitHub Actions IP from EC2 security group + if: always() + run: | + aws ec2 revoke-security-group-ingress \ + --group-id ${{ secrets.AWS_SECURITY_GROUP_ID }} \ + --protocol tcp \ + --port 22 \ + --cidr ${{ steps.ip.outputs.ipv4 }}/32 \ No newline at end of file From 1c291cdf492ade392f48c811825f6893bc8e105f Mon Sep 17 00:00:00 2001 From: rimeir Date: Wed, 16 Apr 2025 23:40:26 +0900 Subject: [PATCH 05/25] =?UTF-8?q?#45=20fix:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=ED=99=98=EA=B2=BD=20=ED=8C=8C=EC=9D=BC=20=EB=B9=84=EA=B3=B5?= =?UTF-8?q?=EA=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/application-test.yml | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 backend/src/main/resources/application-test.yml diff --git a/backend/src/main/resources/application-test.yml b/backend/src/main/resources/application-test.yml deleted file mode 100644 index e52c212..0000000 --- a/backend/src/main/resources/application-test.yml +++ /dev/null @@ -1,13 +0,0 @@ -spring: - datasource: - url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 - driver-class-name: org.h2.Driver - username: sa - password: - jpa: - database-platform: org.hibernate.dialect.H2Dialect - hibernate: - ddl-auto: update # 테이블 유지 - sql: - init: - mode: always \ No newline at end of file From ba94204557f52db4150ac5d48ccfb2e61d681e28 Mon Sep 17 00:00:00 2001 From: rimeir Date: Wed, 16 Apr 2025 23:58:19 +0900 Subject: [PATCH 06/25] =?UTF-8?q?#45=20test:=20CI/CD=20=ED=8C=8C=EC=9D=B4?= =?UTF-8?q?=ED=94=84=EB=9D=BC=EC=9D=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend.yml | 1 + .github/workflows/frontend.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index d9d8efe..1ba9178 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -5,6 +5,7 @@ on: branches: - main - develop + - feature/* jobs: deploy: diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 7406e91..cab1778 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -5,6 +5,7 @@ on: branches: - main - develop + - feature/* jobs: deploy: From 74e25b3131acd4d2fbe383099b91c743ba694db0 Mon Sep 17 00:00:00 2001 From: rimeir Date: Thu, 17 Apr 2025 00:07:25 +0900 Subject: [PATCH 07/25] =?UTF-8?q?#45=20test:=20CI/CD=20=ED=8C=8C=EC=9D=B4?= =?UTF-8?q?=ED=94=84=EB=9D=BC=EC=9D=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend.yml | 2 +- .github/workflows/frontend.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 1ba9178..9737a9b 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -5,7 +5,7 @@ on: branches: - main - develop - - feature/* + - feature/** jobs: deploy: diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index cab1778..9eef0af 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -5,7 +5,7 @@ on: branches: - main - develop - - feature/* + - feature/** jobs: deploy: From 20e153d79b0f827fc02a39d84a62120918870fe0 Mon Sep 17 00:00:00 2001 From: rimeir Date: Thu, 17 Apr 2025 00:11:52 +0900 Subject: [PATCH 08/25] =?UTF-8?q?#45=20test:=20CI/CD=20=ED=8C=8C=EC=9D=B4?= =?UTF-8?q?=ED=94=84=EB=9D=BC=EC=9D=B8=20=EC=88=98=EB=8F=99=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/frontend.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 9eef0af..a14ce43 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -6,6 +6,7 @@ on: - main - develop - feature/** + workflow_dispatch: jobs: deploy: From c1873457afcdaf40f206383ecba9d8fa0bb80fe8 Mon Sep 17 00:00:00 2001 From: rimeir Date: Thu, 17 Apr 2025 00:15:05 +0900 Subject: [PATCH 09/25] =?UTF-8?q?#45=20fix:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C=20CI/CD=20=ED=8C=8C=EC=9D=B4=ED=94=84?= =?UTF-8?q?=EB=9D=BC=EC=9D=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/frontend.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index a14ce43..f0355cd 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -57,12 +57,6 @@ jobs: echo "Logging into ECR and pulling image..." aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }} - -# echo "Updating environment variables..." -# cat < .env -# NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }} -# BASE_URL=${{ secrets.BASE_URL }} -# EOF echo "Deploying frontend container..." docker compose pull frontend From 9b61c95c7b568a8f8d4acc8e4934e181bab95335 Mon Sep 17 00:00:00 2001 From: rimeir Date: Thu, 17 Apr 2025 00:17:59 +0900 Subject: [PATCH 10/25] =?UTF-8?q?#45=20fix:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C=20CI/CD=20=EB=B0=B0=ED=8F=AC=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/frontend.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index f0355cd..f31836f 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -42,7 +42,7 @@ jobs: run: | cd frontend docker build -t frontend-service . - docker tag backend-service:latest ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest + docker tag frontend-service:latest ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest docker push ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest - name: SSH into EC2 and deploy frontend From b5958f39e198a87011ef5d6ece941adf887959c4 Mon Sep 17 00:00:00 2001 From: rimeir Date: Fri, 18 Apr 2025 00:05:05 +0900 Subject: [PATCH 11/25] =?UTF-8?q?#45=20fix:=20CI/CD=20EC2=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=EA=B2=BD=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend.yml | 2 +- .github/workflows/frontend.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 9737a9b..6d9b832 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -71,7 +71,7 @@ jobs: key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} port: ${{ secrets.PORT }} script: | - cd /home/${{ secrets.EC2_USERNAME }}/backend + cd /home/${{ secrets.EC2_USERNAME }}/postdm aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_REPOSITORY }} diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index f31836f..522d6fb 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -53,7 +53,7 @@ jobs: key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} port: ${{ secrets.PORT }} script: | - cd /home/${{ secrets.EC2_USERNAME }}/frontend + cd /home/${{ secrets.EC2_USERNAME }}/postdm echo "Logging into ECR and pulling image..." aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }} From 2b4289dcb7c8ccf52ec475a0b40061e6d3b7d1da Mon Sep 17 00:00:00 2001 From: rimeir Date: Fri, 18 Apr 2025 00:25:17 +0900 Subject: [PATCH 12/25] =?UTF-8?q?#45=20fix:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C=20CI/CD=20docker=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/frontend.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 522d6fb..34a6081 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -57,10 +57,20 @@ jobs: echo "Logging into ECR and pulling image..." aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }} - - echo "Deploying frontend container..." - docker compose pull frontend - docker compose up -d --no-deps frontend + + echo "PULLING LATEST IMAGE..." + docker pull ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest + + echo "STOPPING AND REMOVING EXISTING CONTAINERS..." + sudo docker compose down --remove-orphans || true + + echo "REMOVING UNUSED DOCKER IMAGES..." + docker image rm ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest || true + + echo "STARTING NEW CONTAINER..." + sudo docker compose up -d --force-recreate + + echo "✅ DEPLOYMENT COMPLETE!" - name: Remove GitHub Actions IP from EC2 security group if: always() From 1cc9622b393712f318b56ed76ec16d9654291eeb Mon Sep 17 00:00:00 2001 From: rimeir Date: Mon, 21 Apr 2025 21:19:39 +0900 Subject: [PATCH 13/25] =?UTF-8?q?#45=20fix:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C,=20=EB=B0=B1=EC=97=94=EB=93=9C=20CI=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend.yml | 88 ++-------------------------------- .github/workflows/frontend.yml | 55 ++------------------- 2 files changed, 8 insertions(+), 135 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 6d9b832..f276616 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -1,7 +1,9 @@ -name: Deploy Backend to EC2 +name: Backend CI on: push: + paths: + - 'backend/**' branches: - main - develop @@ -15,10 +17,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Get GitHub Actions Public IP - id: ip - uses: haythem/public-ip@v1.3 - - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v2 with: @@ -26,15 +24,6 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ap-northeast-2 - - name: Add GitHub Actions IP to EC2 security group - run: | - echo "Authorizing IP ${{ steps.ip.outputs.ipv4 }}" - aws ec2 authorize-security-group-ingress \ - --group-id ${{ secrets.AWS_SECURITY_GROUP_ID }} \ - --protocol tcp \ - --port 22 \ - --cidr ${{ steps.ip.outputs.ipv4 }}/32 - - name: Login to AWS ECR run: | ECR_URL="${{ secrets.AWS_ECR_REPOSITORY }}" @@ -46,73 +35,4 @@ jobs: cd backend docker build -t backend-service . docker tag backend-service:latest ${{ secrets.AWS_ECR_REPOSITORY }}:latest - docker push ${{ secrets.AWS_ECR_REPOSITORY }}:latest - - - name: Logout from AWS ECR - run: | - docker logout ${{ secrets.AWS_ECR_REPOSITORY }} - echo "Logged out from AWS ECR." - - - name: Copy backend directory to EC2 - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} - port: 22 - source: "backend/*,docker-compose.yml" - target: "/home/${{ secrets.EC2_USERNAME }}/backend" - - - name: Deploy to EC2 via SSH - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} - port: ${{ secrets.PORT }} - script: | - cd /home/${{ secrets.EC2_USERNAME }}/postdm - - aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_REPOSITORY }} - - echo "PULLING LATEST IMAGE..." - docker pull ${{ secrets.AWS_ECR_REPOSITORY }}:latest - - echo "STOPPING AND REMOVING EXISTING CONTAINERS..." - sudo docker compose down --remove-orphans || true - - echo "REMOVING UNUSED DOCKER IMAGES..." - docker image rm ${{ secrets.AWS_ECR_REPOSITORY }}:latest || true - - echo "UPDATING .env FILE..." - cat < .env - MYSQL_URL=${{ secrets.MYSQL_URL }} - MYSQL_USERNAME=${{ secrets.MYSQL_USERNAME }} - MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} - MYSQL_ROOT_PASSWORD=${{ secrets.MYSQL_ROOT_PASSWORD }} - MYSQL_DATABASE=${{ secrets.MYSQL_DATABASE }} - SPRING_PROFILES_ACTIVE=${{ secrets.SPRING_PROFILES_ACTIVE }} - JWT_SECRET=${{ secrets.JWT_SECRET }} - JWT_EXPIRATION=${{ secrets.JWT_EXPIRATION }} - JWT_EXPIREDMS=${{ secrets.JWT_EXPIREDMS }} - JWT_REFRESHEDMS=${{ secrets.JWT_REFRESHEDMS }} - SPRING_MAIL_HOST=${{ secrets.SPRING_MAIL_HOST }} - SPRING_MAIL_PORT=${{ secrets.SPRING_MAIL_PORT }} - SPRING_MAIL_USERNAME=${{ secrets.SPRING_MAIL_USERNAME }} - SPRING_MAIL_PASSWORD=${{ secrets.SPRING_MAIL_PASSWORD }} - EOF - - echo "STARTING NEW CONTAINER..." - sudo docker compose up -d --force-recreate - - echo "✅ DEPLOYMENT COMPLETE!" - - - name: Remove GitHub Actions IP from EC2 security group - if: always() - run: | - echo "Revoking IP ${{ steps.ip.outputs.ipv4 }}" - aws ec2 revoke-security-group-ingress \ - --group-id ${{ secrets.AWS_SECURITY_GROUP_ID }} \ - --protocol tcp \ - --port 22 \ - --cidr ${{ steps.ip.outputs.ipv4 }}/32 \ No newline at end of file + docker push ${{ secrets.AWS_ECR_REPOSITORY }}:latest \ No newline at end of file diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 34a6081..6cb420d 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -1,12 +1,13 @@ -name: Deploy Frontend to EC2 +name: Frontend CI on: push: + paths: + - 'frontend/**' branches: - main - develop - feature/** - workflow_dispatch: jobs: deploy: @@ -16,10 +17,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Get GitHub Actions Public IP - id: ip - uses: haythem/public-ip@v1.3 - - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v2 with: @@ -27,14 +24,6 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ap-northeast-2 - - name: Authorize GitHub IP for EC2 SSH - run: | - aws ec2 authorize-security-group-ingress \ - --group-id ${{ secrets.AWS_SECURITY_GROUP_ID }} \ - --protocol tcp \ - --port 22 \ - --cidr ${{ steps.ip.outputs.ipv4 }}/32 - - name: Login to Amazon ECR uses: aws-actions/amazon-ecr-login@v1 @@ -43,40 +32,4 @@ jobs: cd frontend docker build -t frontend-service . docker tag frontend-service:latest ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest - docker push ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest - - - name: SSH into EC2 and deploy frontend - uses: appleboy/ssh-action@v0.1.10 - with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} - port: ${{ secrets.PORT }} - script: | - cd /home/${{ secrets.EC2_USERNAME }}/postdm - - echo "Logging into ECR and pulling image..." - aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }} - - echo "PULLING LATEST IMAGE..." - docker pull ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest - - echo "STOPPING AND REMOVING EXISTING CONTAINERS..." - sudo docker compose down --remove-orphans || true - - echo "REMOVING UNUSED DOCKER IMAGES..." - docker image rm ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest || true - - echo "STARTING NEW CONTAINER..." - sudo docker compose up -d --force-recreate - - echo "✅ DEPLOYMENT COMPLETE!" - - - name: Remove GitHub Actions IP from EC2 security group - if: always() - run: | - aws ec2 revoke-security-group-ingress \ - --group-id ${{ secrets.AWS_SECURITY_GROUP_ID }} \ - --protocol tcp \ - --port 22 \ - --cidr ${{ steps.ip.outputs.ipv4 }}/32 \ No newline at end of file + docker push ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest \ No newline at end of file From 582ba86977b82837b160ad42c5e7d28a4ea33454 Mon Sep 17 00:00:00 2001 From: rimeir Date: Mon, 21 Apr 2025 21:19:56 +0900 Subject: [PATCH 14/25] =?UTF-8?q?#45=20fix:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C,=20=EB=B0=B1=EC=97=94=EB=93=9C=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9=20CD=20=EA=B5=AC=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..b587917 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,76 @@ +name: Deploy with Docker Compose + +on: + workflow_dispatch: + push: + branches: + - main + - develop + - feature/** + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Get GitHub Actions Public IP + id: ip + uses: haythem/public-ip@v1.3 + + - name: Authorize GitHub IP + run: | + aws ec2 authorize-security-group-ingress \ + --group-id ${{ secrets.AWS_SECURITY_GROUP_ID }} \ + --protocol tcp \ + --port 22 \ + --cidr ${{ steps.ip.outputs.ipv4 }}/32 + + - name: Deploy to EC2 with docker-compose + uses: appleboy/ssh-action@v0.1.10 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} + script: | + cd /home/ubuntu/app + + echo "Logging in to ECR..." + aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.ECR_REGISTRY }} + + echo "Updating .env file" + cat < .env + MYSQL_URL=${{ secrets.MYSQL_URL }} + MYSQL_USERNAME=${{ secrets.MYSQL_USERNAME }} + MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} + MYSQL_ROOT_PASSWORD=${{ secrets.MYSQL_ROOT_PASSWORD }} + MYSQL_DATABASE=${{ secrets.MYSQL_DATABASE }} + + SPRING_PROFILES_ACTIVE=${{ secrets.SPRING_PROFILES_ACTIVE }} + JWT_SECRET=${{ secrets.JWT_SECRET }} + JWT_EXPIRATION=${{ secrets.JWT_EXPIRATION }} + JWT_EXPIREDMS=${{ secrets.JWT_EXPIREDMS }} + JWT_REFRESHEDMS=${{ secrets.JWT_REFRESHEDMS }} + + SPRING_MAIL_HOST=${{ secrets.SPRING_MAIL_HOST }} + SPRING_MAIL_PORT=${{ secrets.SPRING_MAIL_PORT }} + SPRING_MAIL_USERNAME=${{ secrets.SPRING_MAIL_USERNAME }} + SPRING_MAIL_PASSWORD=${{ secrets.SPRING_MAIL_PASSWORD }} + + EOF + + echo "Pulling latest images..." + docker compose pull + + echo "Starting containers..." + docker compose up -d --force-recreate + + - name: Revoke GitHub IP + if: always() + run: | + aws ec2 revoke-security-group-ingress \ + --group-id ${{ secrets.AWS_SECURITY_GROUP_ID }} \ + --protocol tcp \ + --port 22 \ + --cidr ${{ steps.ip.outputs.ipv4 }}/32 \ No newline at end of file From fd877263e0de6685611df3c9dfbb978e2d252442 Mon Sep 17 00:00:00 2001 From: rimeir Date: Mon, 21 Apr 2025 21:33:31 +0900 Subject: [PATCH 15/25] =?UTF-8?q?#45=20test:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C,=20=EB=B0=B1=EC=97=94=EB=93=9C=20CI=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend.yml | 2 -- .github/workflows/frontend.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index f276616..5958d19 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -2,8 +2,6 @@ name: Backend CI on: push: - paths: - - 'backend/**' branches: - main - develop diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 6cb420d..cee7655 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -2,8 +2,6 @@ name: Frontend CI on: push: - paths: - - 'frontend/**' branches: - main - develop From 9aba3fec76c9c4e84c9c0000483f5aadb9f9626f Mon Sep 17 00:00:00 2001 From: rimeir Date: Mon, 21 Apr 2025 21:34:14 +0900 Subject: [PATCH 16/25] =?UTF-8?q?#45=20fix:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C,=20=EB=B0=B1=EC=97=94=EB=93=9C=20CI=EA=B0=80?= =?UTF-8?q?=20=EC=84=B1=EA=B3=B5=EC=A0=81=EC=9C=BC=EB=A1=9C=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=EB=90=9C=20=EA=B2=BD=EC=9A=B0=EC=97=90=EB=A7=8C=20?= =?UTF-8?q?=EB=8F=99=EC=9E=91=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EB=B0=8F=20=EB=A6=AC=EC=A0=84=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b587917..ec11f36 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,6 +1,10 @@ name: Deploy with Docker Compose on: + workflow_run: + workflows: [ "Frontend CI", "Backend CI" ] + types: + - completed workflow_dispatch: push: branches: @@ -10,6 +14,8 @@ on: jobs: deploy: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest steps: @@ -26,6 +32,7 @@ jobs: --protocol tcp \ --port 22 \ --cidr ${{ steps.ip.outputs.ipv4 }}/32 + --region ap-northeast-2 - name: Deploy to EC2 with docker-compose uses: appleboy/ssh-action@v0.1.10 From 53a561fe768448f97dc5c071d01ef6df164c21aa Mon Sep 17 00:00:00 2001 From: rimeir Date: Mon, 21 Apr 2025 21:56:07 +0900 Subject: [PATCH 17/25] =?UTF-8?q?#45=20fix:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=EC=97=94=EB=93=9C,=20=EB=B0=B1=EC=97=94=EB=93=9C=20CI=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20=EC=A1=B0=EA=B1=B4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ec11f36..71ca01d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,21 +1,15 @@ name: Deploy with Docker Compose on: - workflow_run: - workflows: [ "Frontend CI", "Backend CI" ] - types: - - completed - workflow_dispatch: push: branches: - main - develop - feature/** + workflow_dispatch: jobs: deploy: - if: ${{ github.event.workflow_run.conclusion == 'success' }} - runs-on: ubuntu-latest steps: From da09f1f2ca3718da043506d567888e9d2a31c216 Mon Sep 17 00:00:00 2001 From: rimeir Date: Mon, 21 Apr 2025 22:01:54 +0900 Subject: [PATCH 18/25] =?UTF-8?q?#45=20fix:=20AWS=20=EC=9E=90=EA=B2=A9=20?= =?UTF-8?q?=EC=A6=9D=EB=AA=85=20=EA=B5=AC=EC=84=B1=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 71ca01d..fd8f1ae 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,6 +19,13 @@ jobs: id: ip uses: haythem/public-ip@v1.3 + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ap-northeast-2 + - name: Authorize GitHub IP run: | aws ec2 authorize-security-group-ingress \ @@ -26,7 +33,6 @@ jobs: --protocol tcp \ --port 22 \ --cidr ${{ steps.ip.outputs.ipv4 }}/32 - --region ap-northeast-2 - name: Deploy to EC2 with docker-compose uses: appleboy/ssh-action@v0.1.10 @@ -35,7 +41,7 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} script: | - cd /home/ubuntu/app + cd /home/${{ secrets.EC2_USERNAME }}/postdm echo "Logging in to ECR..." aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.ECR_REGISTRY }} From 8e4b3ea0d7e09e62f71f16ab7864084becdb8005 Mon Sep 17 00:00:00 2001 From: rimeir Date: Mon, 21 Apr 2025 22:16:50 +0900 Subject: [PATCH 19/25] =?UTF-8?q?#45=20fix:=20jobs=EB=A1=9C=20CI/CD=20?= =?UTF-8?q?=ED=86=B5=ED=95=A9=20=ED=8C=8C=EC=9D=BC=EB=A1=9C=20=EA=B5=AC?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend.yml | 36 ----------- .../{deploy.yml => ci_cd_pipeline.yml} | 60 +++++++++++++++++-- .github/workflows/frontend.yml | 33 ---------- 3 files changed, 56 insertions(+), 73 deletions(-) delete mode 100644 .github/workflows/backend.yml rename .github/workflows/{deploy.yml => ci_cd_pipeline.yml} (59%) delete mode 100644 .github/workflows/frontend.yml diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml deleted file mode 100644 index 5958d19..0000000 --- a/.github/workflows/backend.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Backend CI - -on: - push: - branches: - - main - - develop - - feature/** - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-northeast-2 - - - name: Login to AWS ECR - run: | - ECR_URL="${{ secrets.AWS_ECR_REPOSITORY }}" - echo "Logging into AWS ECR: $ECR_URL" - aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_URL - - - name: Build Docker image and push to AWS ECR - run: | - cd backend - docker build -t backend-service . - docker tag backend-service:latest ${{ secrets.AWS_ECR_REPOSITORY }}:latest - docker push ${{ secrets.AWS_ECR_REPOSITORY }}:latest \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/ci_cd_pipeline.yml similarity index 59% rename from .github/workflows/deploy.yml rename to .github/workflows/ci_cd_pipeline.yml index fd8f1ae..3c636f0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/ci_cd_pipeline.yml @@ -1,4 +1,4 @@ -name: Deploy with Docker Compose +name: CI/CD Pipeline on: push: @@ -9,9 +9,61 @@ on: workflow_dispatch: jobs: - deploy: + frontend: + name: Build & Push Frontend + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ap-northeast-2 + + - name: Login to Amazon ECR + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build Docker image and push to AWS ECR + run: | + cd frontend + docker build -t frontend-service . + docker tag frontend-service:latest ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest + docker push ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest + + backend: + name: Build & Push Backend runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ap-northeast-2 + + - name: Login to AWS ECR + run: | + ECR_URL="${{ secrets.AWS_ECR_REPOSITORY }}" + echo "Logging into AWS ECR: $ECR_URL" + aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_URL + - name: Build Docker image and push to AWS ECR + run: | + cd backend + docker build -t backend-service . + docker tag backend-service:latest ${{ secrets.AWS_ECR_REPOSITORY }}:latest + docker push ${{ secrets.AWS_ECR_REPOSITORY }}:latest + + deploy: + name: Deploy to EC2 + runs-on: ubuntu-latest + needs: [frontend, backend] steps: - uses: actions/checkout@v3 @@ -42,10 +94,10 @@ jobs: key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} script: | cd /home/${{ secrets.EC2_USERNAME }}/postdm - + echo "Logging in to ECR..." aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.ECR_REGISTRY }} - + echo "Updating .env file" cat < .env MYSQL_URL=${{ secrets.MYSQL_URL }} diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml deleted file mode 100644 index cee7655..0000000 --- a/.github/workflows/frontend.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Frontend CI - -on: - push: - branches: - - main - - develop - - feature/** - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-northeast-2 - - - name: Login to Amazon ECR - uses: aws-actions/amazon-ecr-login@v1 - - - name: Build Docker image and push to AWS ECR - run: | - cd frontend - docker build -t frontend-service . - docker tag frontend-service:latest ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest - docker push ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }}:latest \ No newline at end of file From 5b2bdc05e97624053357f90e5eac9946d1c24732 Mon Sep 17 00:00:00 2001 From: rimeir Date: Tue, 22 Apr 2025 00:49:47 +0900 Subject: [PATCH 20/25] =?UTF-8?q?#45=20fix:=20=ED=94=84=EB=A1=A0=ED=8A=B8?= =?UTF-8?q?=20=EB=B0=8F=20=EB=B0=B1=EC=97=94=EB=93=9C=20ECR=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EB=AA=A8=EB=91=90=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci_cd_pipeline.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_cd_pipeline.yml b/.github/workflows/ci_cd_pipeline.yml index 3c636f0..e42b9df 100644 --- a/.github/workflows/ci_cd_pipeline.yml +++ b/.github/workflows/ci_cd_pipeline.yml @@ -96,7 +96,9 @@ jobs: cd /home/${{ secrets.EC2_USERNAME }}/postdm echo "Logging in to ECR..." - aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.ECR_REGISTRY }} + aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_REPOSITORY }} + aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }} + echo "Updating .env file" cat < .env From f6d6cd1103ef9775a3e195e51a2a746dd6d71354 Mon Sep 17 00:00:00 2001 From: rimeir Date: Wed, 23 Apr 2025 01:18:12 +0900 Subject: [PATCH 21/25] =?UTF-8?q?#45=20fix:=20docker=20compose=20ECR=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci_cd_pipeline.yml | 1 - docker-compose.yml | 11 +++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci_cd_pipeline.yml b/.github/workflows/ci_cd_pipeline.yml index e42b9df..27a0d33 100644 --- a/.github/workflows/ci_cd_pipeline.yml +++ b/.github/workflows/ci_cd_pipeline.yml @@ -99,7 +99,6 @@ jobs: aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_REPOSITORY }} aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_FRONTEND_REPOSITORY }} - echo "Updating .env file" cat < .env MYSQL_URL=${{ secrets.MYSQL_URL }} diff --git a/docker-compose.yml b/docker-compose.yml index fc1526b..eac4c17 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,20 +25,14 @@ services: frontend: container_name: frontend - image: frontend-service -# build: -# context: frontend -# dockerfile: Dockerfile + image: 536697226608.dkr.ecr.ap-northeast-2.amazonaws.com/postdm/frontend-app ports: - "3000:3000" restart: always backend: container_name: backend - image: backend-service -# build: -# context: backend -# dockerfile: Dockerfile + image: 536697226608.dkr.ecr.ap-northeast-2.amazonaws.com/postdm/backend-app ports: - "8080:8080" environment: @@ -58,6 +52,7 @@ services: - "443:443" volumes: - ./nginx/nginx.conf:/etc/nginx/nginx.conf + - /etc/letsencrypt:/etc/letsencrypt:ro volumes: mysql_data: # 데이터 영구 저장 Docker Volume \ No newline at end of file From 93079bba23438df425dfffd982af60720c6a6e27 Mon Sep 17 00:00:00 2001 From: "ella.oh" Date: Mon, 12 May 2025 23:38:31 +0900 Subject: [PATCH 22/25] =?UTF-8?q?#45=20fix:=20docker=20compose=20nginx=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index eac4c17..192328a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,18 +41,20 @@ services: SPRING_DATASOURCE_PASSWORD: ${MYSQL_PASSWORD} env_file: - .env - volumes: - - ./config/application-prod.yml:/app/config/application-prod.yml nginx: - image: nginx:latest + image: nginx:1.25-alpine container_name: nginx + depends_on: + - frontend + - backend ports: - "80:80" - "443:443" volumes: - ./nginx/nginx.conf:/etc/nginx/nginx.conf - /etc/letsencrypt:/etc/letsencrypt:ro + restart: always volumes: mysql_data: # 데이터 영구 저장 Docker Volume \ No newline at end of file From f18854652ad49f72291d121ba0bdc4d331b7ec32 Mon Sep 17 00:00:00 2001 From: "ella.oh" Date: Mon, 12 May 2025 23:38:49 +0900 Subject: [PATCH 23/25] =?UTF-8?q?#45=20fix:=20nginx=20=EC=8B=A4=ED=96=89?= =?UTF-8?q?=20=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx/nginx.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index c4a7a4b..8ed5d09 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -3,6 +3,10 @@ http { listen 80; server_name postdmex.com www.postdmex.com; + location ~ /.well-known/acme-challenge/ { + root /var/www/html; + } + location / { proxy_pass http://frontend:3000; proxy_http_version 1.1; @@ -20,10 +24,6 @@ http { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } - - location ~ /.well-known/acme-challenge/ { - root /var/www/html; - } } server { From b827ff30974ec244a02a528c67c3942c25a8b867 Mon Sep 17 00:00:00 2001 From: "ella.oh" Date: Tue, 13 May 2025 18:14:36 +0900 Subject: [PATCH 24/25] =?UTF-8?q?#45=20fix:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20nginx=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=EC=84=9C=20=EB=B0=9C=EA=B8=89=20=EB=B6=80=EB=B6=84=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 1 + nginx/nginx.conf | 28 ---------------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 192328a..713ae8f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,6 +54,7 @@ services: volumes: - ./nginx/nginx.conf:/etc/nginx/nginx.conf - /etc/letsencrypt:/etc/letsencrypt:ro + - /var/www/html:/var/www/html restart: always volumes: diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 8ed5d09..acdd2a4 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -25,32 +25,4 @@ http { proxy_set_header X-Forwarded-Proto $scheme; } } - - server { - listen 443 ssl; - server_name postdmex.com www.postdmex.com; - - ssl_certificate /etc/letsencrypt/live/postdmex.com/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/postdmex.com/privkey.pem; - ssl_protocols TLSv1.2 TLSv1.3; - ssl_ciphers HIGH:!aNULL:!MD5; - - location / { - proxy_pass http://frontend:3000; - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - - location /api/ { - proxy_pass http://backend:8080; - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - } } \ No newline at end of file From 20fc274ef303fad9436dc245edfe9a4ccf37abcc Mon Sep 17 00:00:00 2001 From: "ella.oh" Date: Thu, 15 May 2025 23:41:45 +0900 Subject: [PATCH 25/25] =?UTF-8?q?#45=20fix:=20nginx=20=ED=95=84=EC=88=98?= =?UTF-8?q?=20=EB=B8=94=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx/nginx.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index acdd2a4..c247a79 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1,3 +1,5 @@ +events {} + http { server { listen 80;