From 2ee9d4a751c00ba62bd28d9a22a035a045beaaf0 Mon Sep 17 00:00:00 2001 From: mclub4 Date: Sun, 5 May 2024 20:06:24 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=B0=B0=ED=8F=AC=EC=9A=A9=20compose=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 147 ++++++++++++++++++++++++++++++++++- back/docker-compose.yml | 2 + docker-compose.yml | 101 ++++++++++++++++++++++++ 3 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 docker-compose.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8616702b62..05a8009fda 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -66,5 +66,148 @@ jobs: host: ${{ secrets.AWS_HOST }} username: ubuntu key: ${{ secrets.AWS_KEY }} - source: "./back/docker-compose.yml" - target: "capstone" \ No newline at end of file + source: "./docker-compose.yml" + target: "capstone" + + - name: action-slack + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + author_name: PetBuddy Github + fields: repo,message,commit,author,action,eventName,ref,workflow,job,took + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + if: always() + + build-spring: + runs-on: ubuntu-latest + needs: setup-env + + steps: + - name: Build and push Spring + uses: docker/build-push-action@v5 + with: + context: ./back + push: true + tags: ${{ secrets.DOCKER_REPO }}/spring:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: action-slack + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + author_name: PetBuddy Github + fields: repo,message,commit,author,action,eventName,ref,workflow,job,took + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + if: always() + + build-nginx: + runs-on: ubuntu-latest + needs: setup-env + + steps: + - name: Build and push Nginx + uses: docker/build-push-action@v5 + with: + context: ./back/nginx + push: true + tags: ${{ secrets.DOCKER_REPO }}/nginx:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: action-slack + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + author_name: PetBuddy Github + fields: repo,message,commit,author,action,eventName,ref,workflow,job,took + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + if: always() + + build-ruby: + runs-on: ubuntu-latest + needs: setup-env + + steps: + - name: Build and push Ruby on Rails + uses: docker/build-push-action@v5 + with: + context: ./back-chat + push: true + tags: ${{ secrets.DOCKER_REPO }}/ruby:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: action-slack + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + author_name: PetBuddy Github + fields: repo,message,commit,author,action,eventName,ref,workflow,job,took + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + if: always() + + build-gateway: + runs-on: ubuntu-latest + needs: setup-env + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build and push Spring + uses: docker/build-push-action@v5 + with: + context: ./back-gateway + push: true + tags: ${{ secrets.DOCKER_REPO }}/spring-gateway:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: action-slack + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + author_name: PetBuddy Github + fields: repo,message,commit,author,action,eventName,ref,workflow,job,took + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + if: always() + + deploy: + runs-on: ubuntu-latest + needs: [ build-spring, build-nginx, build-ruby, build-gateway ] + + steps: + - name: executing remote ssh commands using password + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.AWS_HOST }} + username: ubuntu + key: ${{ secrets.AWS_KEY }} + script: | + if [ "$(sudo docker ps -qa)" ]; then + sudo docker rm -f $(sudo docker ps -qa) + fi + + sudo docker pull ${{ secrets.DOCKER_REPO }}/spring:latest + sudo docker pull ${{ secrets.DOCKER_REPO }}/nginx:latest + sudo docker pull ${{ secrets.DOCKER_REPO }}/ruby:latest + sudo docker pull ${{ secrets.DOCKER_REPO }}/spring-gateway:latest + + sudo docker compose -f capstone/docker-compose.yml up -d + sudo docker image prune -f + + - name: action-slack + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + author_name: PetBuddy Github + fields: repo,message,commit,author,action,eventName,ref,workflow,job,took + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + if: always() diff --git a/back/docker-compose.yml b/back/docker-compose.yml index c6ab0fa3a6..62aee99004 100644 --- a/back/docker-compose.yml +++ b/back/docker-compose.yml @@ -1,3 +1,5 @@ +## Test Version + version: '3' networks: backend_network: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000..8e746b9084 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,101 @@ +## Production Deploy Version + +version: '3' +networks: + backend_network: + ssl_network: + +services: + redis: + image: redis:7.2.0-alpine + container_name: redis + hostname: redis + restart: unless-stopped + environment: + TZ: "Asia/Seoul" + ports: + - 6379:6379 + healthcheck: + test: ["CMD-SHELL", "redis-cli ping | grep PONG"] + interval: 5s + timeout: 3s + retries: 10 + networks: + - backend_network + + spring_gateway: + container_name: spring_gateway + restart: always + image: capstone30/spring-gateway:test + env_file: + - .env + environment: + TZ: "Asia/Seoul" + ports: + - "8081:8081" + networks: + - backend_network + + spring: + container_name: spring + restart: always + image: capstone30/spring:test + env_file: + - .env + environment: + TZ : "Asia/Seoul" + ports: + - "8080:8080" + depends_on: + redis: + condition: service_healthy + volumes: + - /path/to/logs:/container/path/to/logs + networks: + - backend_network + + ruby: + container_name: ruby + restart: always + image: capstone30/ruby:test + env_file: + - .env + environment: + TZ: "Asia/Seoul" + ports: + - "3000:3000" + networks: + - backend_network + + nginx: + container_name: nginx + image: capstone30/nginx:test + restart: unless-stopped + environment: + TZ: "Asia/Seoul" + ports: + - "80:80" + - "443:443" + env_file: + - .env + volumes: + - ./data/certbot/conf:/etc/letsencrypt + - ./data/certbot/www:/var/www/certbot + depends_on: + - "redis" + - "spring" + - "ruby" + command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'" + networks: + - backend_network + - ssl_network + + certbot: + image: certbot/certbot + restart: unless-stopped + volumes: + - ./data/certbot/conf:/etc/letsencrypt + - ./data/certbot/www:/var/www/certbot + entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'" + networks: + - ssl_network