From 39462a472636d8e8a2e0cbdfd86e71f84ac9de4a Mon Sep 17 00:00:00 2001 From: Gyehyun Park Date: Fri, 25 Oct 2024 00:31:03 +0900 Subject: [PATCH] feat: Added docker-compose.yml. Modified deploy.yml --- .github/workflows/deploy.yml | 7 +++---- docker-compose.yml | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 docker-compose.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6c00d86..062e41f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -52,7 +52,6 @@ jobs: key: ${{ secrets.EC2_PRIVATE_KEY }} script_stop: true script: | - docker stop cano-server || true - docker rm cano-server || true - docker pull ${{ steps.login-ecr.outputs.registry }}/cano-server:latest - docker run -d --name cano-server -p 8080:8080 ${{ steps.login-ecr.outputs.registry }}/cano-server:latest \ No newline at end of file + docker-compose down || true # 기존 컨테이너 중지 및 제거 + docker-compose pull # ECR에서 최신 이미지를 가져오기 + docker-compose up -d # 새로운 컨테이너 실행 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0721478 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +services: + db: + image: mysql + container_name: cano-mysql + environment: + MYSQL_ROOT_PASSWORD: password123 + MYSQL_DATABASE: cano + ports: + - "3306:3306" + volumes: + - db_data:/var/lib/mysql + networks: + - cano-network + healthcheck: + test: [ "CMD", "mysqladmin", "ping" ] # MySQL이 healthy 한 지 판단할 수 있는 명령어 + interval: 5s # 5초 간격으로 체크 + retries: 10 # 10번까지 재시도 + + app: + image: cano-server:latest + container_name: cano-server + depends_on: + - db: + condition: service-healthy + ports: + - "8080:8080" + environment: + SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/cano + SPRING_DATASOURCE_USERNAME: root + SPRING_DATASOURCE_PASSWORD: password123 + networks: + - cano-network + +networks: + cano-network: + driver: bridge + +volumes: + db_data: