Skip to content

Commit

Permalink
chore: GIthub Actions 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-taewon-kim committed Oct 31, 2024
1 parent b895445 commit 3e6f1ab
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/be.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Nest.js with PM2 Deployment

on:
push:
branches: ["dev-be"]

permissions:
contents: read

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "21.7.3"

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Import environment variables
run: |
cd ./src
echo "${{ secrets.ENV_PRODUCTION }}" > .env
shell: bash

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

- name: Build application
run: pnpm build

- name: Setup SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Add remote server to known hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
- name: Transfer built files via SCP
run: |
cd dist
zip -r ../dist.zip .
cd ..
scp -P ${{ secrets.SERVER_PORT }} ./dist.zip ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }}:/home/${{ secrets.SSH_USER }}/deploy/clovapatra/dist.zip
- name: Execute remote commands
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SERVER_PORT }}
script: |
cd ~/deploy/clovapatra/
unzip -o dist.zip -d ./dist/
pm2 delete clovapatra || true
pm2 start dist/main.js --name clovapatra
rm dist.zip
59 changes: 59 additions & 0 deletions .github/workflows/fe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: React.js Deployment

on:
push:
branches: ["dev-fe"]

permissions:
contents: read

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cache
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 21.7.3

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Setup SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Add remote server to known hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts
- name: Execute remote commands
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SERVER_PORT }}
script: |
sudo rm -rf /var/www/clovapatra.com/html
sudo mkdir -p /var/www/clovapatra.com/html
sudo chown -R ${{ secrets.SSH_USER }}:${{ secrets.SSH_USER }} /var/www/clovapatra.com/html
- name: Transfer built files via rsync
run: rsync -avz -e 'ssh -p ${{ secrets.SERVER_PORT }}' ./dist/ ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }}:/var/www/clovapatra.com/html

0 comments on commit 3e6f1ab

Please sign in to comment.