Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be/refactor/#454 aws 마이그레이션 #455

Merged
merged 26 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b1dc420
refactor: docker 캐싱 활용
kimyu0218 Dec 29, 2023
fe601e5
refactor: package-lock.json도 함께 복사하도록 수정
kimyu0218 Dec 29, 2023
163a805
refactor: docker 캐싱 활용
kimyu0218 Dec 29, 2023
66ba3c7
remove: 기존 도커 컴포즈 파일 삭제
kimyu0218 Dec 31, 2023
310e3f8
refactor: 빌드용 도커 컴포즈 분리
kimyu0218 Dec 31, 2023
f43213c
fix: 배포용 도커 컴포즈 수정
kimyu0218 Dec 31, 2023
e4d815c
refactor: 빌드/배포용 도커 컴포즈 분리에 따른 배포 액션 수정
kimyu0218 Dec 31, 2023
0c4f55f
refactor: 원격 서버에서 실행되는 배포 스크립트 수정
kimyu0218 Dec 31, 2023
2f736d3
refactor: networks 옵션 추가
kimyu0218 Jan 5, 2024
b3b55d7
refactor: 도커 컨테이너 종료 후 삭제
kimyu0218 Jan 5, 2024
c39cf28
refactor: 불필요한 변수 삭제
kimyu0218 Jan 5, 2024
5221679
refactor: 비밀키를 이용하여 SSH 접속
kimyu0218 Jan 5, 2024
e4b6629
fix: dial tcp ***:***: i/o timeout 에러 해결
kimyu0218 Jan 6, 2024
cf38ada
fix: undefined network 해결
kimyu0218 Jan 6, 2024
210febb
fix: sudo 추가
kimyu0218 Jan 6, 2024
03b2156
fix: 블루 버전 배포 컴포즈 수정
kimyu0218 Jan 6, 2024
106d6ad
fix: network 이름 오류 수정
kimyu0218 Jan 6, 2024
8c3ccbe
fix: nginx 로그 경로 오류 수정
kimyu0218 Jan 6, 2024
60da2c3
fix: synchronize 값 true로 변경
kimyu0218 Jan 6, 2024
f4088fb
fix: typeorm 로그 파일 수정
kimyu0218 Jan 6, 2024
3fe1bce
refactor: sentry 샘플링 비율 조절 (1.0 -> 0.3)
kimyu0218 Jan 6, 2024
1cfa39b
refactor: 사용하지 않는 도커 이미지 삭제
kimyu0218 Jan 6, 2024
4ac3e08
refactor: 백엔드 관련 파일이 변경되었을 때만 실행되도록 수정
kimyu0218 Jan 6, 2024
2a7f043
fix: prune 명령어 수정
kimyu0218 Jan 6, 2024
0ab4095
refactor: 원격 서버로 파일 전송하는 스텝 하나로 합치기
kimyu0218 Jan 7, 2024
c39b42c
refactor: deploy.sh 내의 불필요한 변수 및 함수 제거
kimyu0218 Jan 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 16 additions & 28 deletions .github/workflows/blue-green-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ name: Blue/Green CD

on:
push:
paths: ["backend/**"]
branches: ["dev"]

env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
GITHUB_SHA: ${{ github.sha }}
TURN_SERVER_NAME: ${{ secrets.TURN_SERVER_NAME }}
TURN_SERVER_USER: ${{ secrets.TURN_SERVER_USER }}
TURN_SERVER_PASSWORD: ${{ secrets.TURN_SERVER_PASSWORD }}

jobs:
build:
Expand All @@ -25,28 +23,29 @@ jobs:
echo "${{ secrets.ENV_FILE }}" > .env
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> .env
echo "GITHUB_SHA=${{ github.sha }}" >> .env
echo "TURN_SERVER_NAME=${{ secrets.TURN_SERVER_NAME }}" >> .env
echo "TURN_SERVER_USER=${{ secrets.TURN_SERVER_USER }}" >> .env
echo "TURN_SERVER_PASSWORD=${{ secrets.TURN_SERVER_PASSWORD }}" >> .env
echo "SENTRY_DSN=${{ secrets.SENTRY_DSN }}" >> .env
mkdir -p config/nginx/ssl/
echo "${{ secrets.SSL_OPTIONS }}" > config/nginx/ssl/options-ssl-nginx.conf
echo "${{ secrets.SSL_FULLCHAIN }}" > config/nginx/ssl/fullchain.pem
echo "${{ secrets.SSL_PRIVKEY }}" > config/nginx/ssl/privkey.pem
echo "${{ secrets.SSL_DHPARAMS }}" > config/nginx/ssl/ssl-dhparams.pem

- name: Copy .env, deploy script, SSL files to Remote Server
- name: Add Remote Host Key to known_hosts
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PUBLIC_KEY }}" >> ~/.ssh/known_hosts

- name: Copy some files needed for Deployment to Remote Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
source: "backend/.env,backend/deploy.sh,backend/config"
source: "backend/.env,backend/deploy.sh,backend/config,backend/compose.blue-deploy.yml,backend/compose.green-deploy.yml,backend/Dockerfile.nginx"
target: "~/app/"
overwrite: true

- name: Docker login
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
Expand All @@ -55,21 +54,10 @@ jobs:
- name: Build & Push Docker Images (Blue & Green)
run: |
cd backend
docker-compose -f docker-compose.blue.yml build --no-cache
docker-compose -f docker-compose.green.yml build --no-cache
docker-compose -f docker-compose.blue.yml push
docker-compose -f docker-compose.green.yml push

- name: Copy Dockerfiles to Remote Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
source: "backend/docker-compose.blue.yml,backend/docker-compose.green.yml,backend/Dockerfile.nginx,backend/Dockerfile.was,backend/Dockerfile.signal"
target: "~/app/"
overwrite: true
docker-compose -f compose.blue-build.yml build
docker-compose -f compose.green-build.yml build
docker-compose -f compose.blue-build.yml push
docker-compose -f compose.green-build.yml push

deploy:
needs: build
Expand All @@ -82,12 +70,12 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}

- name: Run Docker on Remote Server
- name: Run a New Version of the application on Remote Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd ~/app/backend
Expand Down
7 changes: 3 additions & 4 deletions backend/Dockerfile.signal
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ FROM node:20

RUN apt-get update && apt-get install -y tini

WORKDIR /app

COPY signal ./signal

WORKDIR /app/signal

COPY signal/package*.json ./
RUN npm install

COPY signal .
RUN npm run build

CMD ["tini", "--", "npm", "run", "start:prod"]
7 changes: 3 additions & 4 deletions backend/Dockerfile.was
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ FROM node:20

RUN apt-get update && apt-get install -y tini

WORKDIR /app

COPY was ./was

WORKDIR /app/was

COPY was/package*.json ./
RUN npm install

COPY was .
RUN npm run build

CMD ["tini", "--", "npm", "run", "start:prod"]
37 changes: 37 additions & 0 deletions backend/compose.blue-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: "3.3"

services:
was-blue:
container_name: "was-blue"
build:
context: .
dockerfile: Dockerfile.was
env_file: .env
environment:
- PORT=3000
expose:
- "3000"
volumes:
- /var/log/was:/app/was/logs
- /var/log/ormlogs.log:/app/was/ormlogs.log
networks:
- backend
image: "${DOCKER_USERNAME}/magicconch:was-blue-${GITHUB_SHA}"

signal-blue:
container_name: "signal-blue"
build:
context: .
dockerfile: Dockerfile.signal
environment:
- PORT=3001
expose:
- "3001"
networks:
- backend
image: "${DOCKER_USERNAME}/magicconch:signal-blue-${GITHUB_SHA}"

networks:
backend:
external: true
name: backend
34 changes: 16 additions & 18 deletions backend/docker-compose.blue.yml → backend/compose.blue-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,29 @@ services:
was-blue:
image: "${DOCKER_USERNAME}/magicconch:was-blue-${GITHUB_SHA}"
container_name: "was-blue"
build:
context: .
dockerfile: Dockerfile.was
env_file: .env
environment:
- DB_PORT=${DB_PORT}
- DB_HOST=${DB_HOST}
- DB_USERNAME=${DB_USERNAME}
- DB_PASSWORD=${DB_PASSWORD}
- DB_DATABASE=${DB_DATABASE}
- ACCESS_KEY_ID=${ACCESS_KEY_ID}
- SECRET_KEY=${SECRET_KEY}
- X_NCP_CLOVASTUDIO_API_KEY=${X_NCP_CLOVASTUDIO_API_KEY}
- X_NCP_APIGW_API_KEY=${X_NCP_APIGW_API_KEY}
- PORT=3000
- SENTRY_DSN=${SENTRY_DSN}
expose:
- "3000"
volumes:
- /var/log/was:/app/was/logs
- /var/log/typeorm:/app/was/typeorm.log
- /var/log/ormlogs.log:/app/was/ormlogs.log
networks:
- backend

signal-blue:
image: "${DOCKER_USERNAME}/magicconch:signal-blue-${GITHUB_SHA}"
container_name: "signal-blue"
build:
context: .
dockerfile: Dockerfile.signal
environment:
- PORT=3001
expose:
- "3001"
networks:
- backend

nginx:
container_name: "nginx-reverse-proxy"
container_name: "nginx"
build:
context: .
dockerfile: Dockerfile.nginx
Expand All @@ -50,10 +39,19 @@ services:
- certbot
volumes:
- /var/log/nginx:/var/log/nginx
networks:
- backend

certbot:
image: certbot/certbot
volumes:
- /etc/letsencrypt
- /var/www/html:/var/www/html
networks:
- backend
command: certonly --webroot --webroot-path=/var/www/html -d was.tarotmilktea.com

networks:
backend:
external: true
name: backend
37 changes: 37 additions & 0 deletions backend/compose.green-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: "3.3"

services:
was-green:
container_name: "was-green"
build:
context: .
dockerfile: Dockerfile.was
env_file: .env
environment:
- PORT=3002
expose:
- "3002"
volumes:
- /var/log/was:/app/was/logs
- /var/log/ormlogs.log:/app/was/ormlogs.log
networks:
- backend
image: "${DOCKER_USERNAME}/magicconch:was-green-${GITHUB_SHA}"

signal-green:
container_name: "signal-green"
build:
context: .
dockerfile: Dockerfile.signal
environment:
- PORT=3003
expose:
- "3003"
networks:
- backend
image: "${DOCKER_USERNAME}/magicconch:signal-green-${GITHUB_SHA}"

networks:
backend:
external: true
name: backend
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,29 @@ services:
was-green:
image: "${DOCKER_USERNAME}/magicconch:was-green-${GITHUB_SHA}"
container_name: "was-green"
build:
context: .
dockerfile: Dockerfile.was
env_file: .env
environment:
- DB_PORT=${DB_PORT}
- DB_HOST=${DB_HOST}
- DB_USERNAME=${DB_USERNAME}
- DB_PASSWORD=${DB_PASSWORD}
- DB_DATABASE=${DB_DATABASE}
- ACCESS_KEY_ID=${ACCESS_KEY_ID}
- SECRET_KEY=${SECRET_KEY}
- X_NCP_CLOVASTUDIO_API_KEY=${X_NCP_CLOVASTUDIO_API_KEY}
- X_NCP_APIGW_API_KEY=${X_NCP_APIGW_API_KEY}
- PORT=3002
- SENTRY_DSN=${SENTRY_DSN}
expose:
- "3002"
volumes:
- /var/log/was:/app/was/logs
- /var/log/typeorm:/app/was/typeorm.log
- /var/log/ormlogs.log:/app/was/ormlogs.log
networks:
- backend

signal-green:
image: "${DOCKER_USERNAME}/magicconch:signal-green-${GITHUB_SHA}"
container_name: "signal-green"
build:
context: .
dockerfile: Dockerfile.signal
environment:
- PORT=3003
expose:
- "3003"
networks:
- backend

nginx:
container_name: "nginx-reverse-proxy"
container_name: "nginx"
build:
context: .
dockerfile: Dockerfile.nginx
Expand All @@ -50,10 +39,19 @@ services:
- certbot
volumes:
- /var/log/nginx:/var/log/nginx
networks:
- backend

certbot:
image: certbot/certbot
volumes:
- /etc/letsencrypt
- /var/www/html:/var/www/html
networks:
- backend
command: certonly --webroot --webroot-path=/var/www/html -d was.tarotmilktea.com

networks:
backend:
external: true
name: backend
Loading