Skip to content

Commit

Permalink
Merge pull request #15 from boostcampwm-2024/task-#14-github-cicd
Browse files Browse the repository at this point in the history
Github Actions를 이용한 CI/CD 구축
  • Loading branch information
tuchongkim authored Jan 15, 2025
2 parents 0f5fdc1 + c24f853 commit bce054f
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Deploy Dev in Monorepo

on:
push:
branches:
- dev

jobs:
build-and-deploy:
runs-on: ubuntu-latest

services:
docker:
image: docker:20.10.7
options: --privileged

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache Yarn dependencies
uses: actions/cache@v3
with:
path: |
**/node_modules
~/.yarn-cache
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build backend and frontend
run: |
yarn workspace backend build
yarn workspace frontend build
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker images
run: |
# 백엔드 이미지 빌드 및 푸시
docker build -t ${{ secrets.DOCKER_USERNAME }}/backend:latest -f packages/backend/Dockerfile .
docker push ${{ secrets.DOCKER_USERNAME }}/backend:latest
# 프론트엔드 이미지 빌드 및 푸시
docker build -t ${{ secrets.DOCKER_USERNAME }}/frontend:latest -f packages/frontend/Dockerfile .
docker push ${{ secrets.DOCKER_USERNAME }}/frontend:latest
- name: Deploy to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY}}
password: ${{ secrets.SERVER_PASSWORD }}
port: ${{ secrets.SERVER_PORT }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/frontend:latest
docker pull ${{ secrets.DOCKER_USERNAME }}/backend:latest
docker compose down
docker compose up -d

0 comments on commit bce054f

Please sign in to comment.