Skip to content

Commit

Permalink
fix: 배포용 compose 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
mclub4 committed May 5, 2024
1 parent c9e839f commit 2ee9d4a
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 2 deletions.
147 changes: 145 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,148 @@ jobs:
host: ${{ secrets.AWS_HOST }}
username: ubuntu
key: ${{ secrets.AWS_KEY }}
source: "./back/docker-compose.yml"
target: "capstone"
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()
2 changes: 2 additions & 0 deletions back/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## Test Version

version: '3'
networks:
backend_network:
Expand Down
101 changes: 101 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2ee9d4a

Please sign in to comment.