Skip to content

[#13] CICD 개선

[#13] CICD 개선 #26

name: ci/cd action
on:
push:
branches: ['dev']
pull_request:
branches: ['dev']
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install Pnpm
run: npm install -g pnpm
- name: Package install with pnpm
run: pnpm install:all
- name: Set BE .env
run: |
echo "MONGO_URI=${{ secrets.MONGO_URI }}" > apps/server/.env
echo "SSH_HOST=${{ secrets.SSH_HOST }}" >> apps/server/.env
echo "SSH_PORT=${{ secrets.SSH_PORT }}" >> apps/server/.env
echo "SSH_USER=${{ secrets.SSH_USER }}" >> apps/server/.env
echo "SSH_PASSWORD=${{ secrets.SSH_PASSWORD }}" >> apps/server/.env
echo "SSH_DATABASE_HOST=${{ secrets.SSH_DATABASE_HOST }}" >> apps/server/.env
echo "SSH_DATABASE_PORT=${{ secrets.SSH_DATABASE_PORT }}" >> apps/server/.env
echo "LOCAL_PORT=${{ secrets.LOCAL_PORT }}" >> apps/server/.env
echo "IS_LOCAL=true" >> apps/server/.env
echo "SERVER_CORS_ACCEPT=http://localhost:5173" >> apps/server/.env
echo "S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }}" >> apps/server/.env
echo "S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }}" >> apps/server/.env
echo "S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }}" >> apps/server/.env
- name: Set FE .env
run: |
echo "VITE_SERVER_URL=http://localhost:3000" > apps/client/.env
echo "VITE_STATIC_STORAGE_URL=${{ secrets.VITE_STATIC_STORAGE_URL }}" >> apps/client/.env
- name: Buld Frontend
run: |
cd apps/client
pnpm run build
- name: Build Backend
run: |
cd apps/server
pnpm run build
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy with docker
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
cd boolock/refactor-web31-BooLock
git checkout dev
git pull origin dev
echo "MONGO_URI=${{ secrets.DEPLOY_MONGO_URI }}" > apps/server/.env
echo "IS_LOCAL=false" >> apps/server/.env
echo "SERVER_CORS_ACCEPT=${{ secrets.DEPLOY_SERVER_CORS_ACCEPT }}" >> apps/server/.env
echo "S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }}" >> apps/server/.env
echo "S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }}" >> apps/server/.env
echo "S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }}" >> apps/server/.env
echo "NODE_ENV=production" >> apps/server/.env
echo "VITE_SERVER_URL=${{ secrets.DEPLOY_VITE_SERVER_URL }}" > apps/client/.env
echo "VITE_STATIC_STORAGE_URL=${{ secrets.VITE_STATIC_STORAGE_URL }}" >> apps/client/.env
sudo docker compose down
sudo docker compose up -d --build
sudo docker image prune -f