Merge branch 'dev' of https://github.com/boostcampwm-2024/web04-RealT… #42
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI-CD | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-test: | |
runs-on: ubuntu-latest | |
services: | |
mysql: | |
image: mysql:8 | |
env: | |
MYSQL_ROOT_PASSWORD: root | |
MYSQL_DATABASE: real_ticket | |
ports: | |
- 3306:3306 | |
redis: | |
image: redis:latest | |
ports: | |
- 6379:6379 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
cache: 'npm' | |
- name: Build Docker image for backend | |
run: | | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_BACKEND }} ./back | |
- name: Build Docker image for frontend | |
run: | | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_FRONTEND }} ./front | |
- name: Run backend container | |
run: | | |
docker run -d --name backend-container -p ${{ secrets.BACKEND_SERVER_PORT }}:${{ secrets.BACKEND_SERVER_PORT }} ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_BACKEND }} | |
- name: Run frontend container | |
run: | | |
docker run -d --name frontend-container -p ${{ secrets.FRONT_SERVER_PORT }}:${{ secrets.FRONT_SERVER_PORT }} ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_FRONTEND }} | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Push backend image to Docker Hub | |
run: | | |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_BACKEND }} | |
- name: Push front image to Docker Hub | |
run: | | |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_FRONTEND }} | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build-and-test | |
steps: | |
- name: Set up sshpass | |
run: | | |
sudo apt update | |
sudo apt install -y sshpass | |
- name: Access Backend server and deploy | |
run: | | |
sshpass -p "${{ secrets.PUBLIC_SERVER_PASSWORD }}" ssh -o StrictHostKeyChecking=no ${{ secrets.PUBLIC_SERVER_USER }}@${{ secrets.PUBLIC_SERVER_IP }} \ | |
"sshpass -p '${{ secrets.BACKEND_SERVER_PASSWORD }}' ssh -o StrictHostKeyChecking=no ${{ secrets.BACKEND_SERVER_USER }}@${{ secrets.BACKEND_SERVER_IP }} \ | |
'./nest/start.sh; exit'" | |
- name: Access Frontend server and deploy | |
run: | | |
sshpass -p "${{ secrets.PUBLIC_SERVER_PASSWORD }}" ssh -o StrictHostKeyChecking=no ${{ secrets.PUBLIC_SERVER_USER }}@${{ secrets.PUBLIC_SERVER_IP }} \ | |
"sshpass -p '${{ secrets.FRONT_SERVER_PASSWORD }}' ssh -o StrictHostKeyChecking=no ${{ secrets.FRONT_SERVER_USER }}@${{ secrets.FRONT_SERVER_IP }} \ | |
'./front/start.sh'" |