config: BE Actions 수정(11) #13
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: 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 ./be | |
echo "${{ secrets.ENV_PRODUCTION }}" > .env | |
shell: bash | |
# - name: Install dependencies | |
# run: | | |
# cd ./be | |
# pnpm install --no-frozen-lockfile | |
# - name: Build application | |
# run: | | |
# cd ./be | |
# 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 files via SCP | |
run: | | |
zip -r be.zip be | |
scp -P ${{ secrets.SERVER_PORT }} ./be.zip ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }}:/home/${{ secrets.SSH_USER }}/deploy/clovapatra/be.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: | | |
export PATH=$PATH:/home/${{ secrets.SSH_USER }}/.nvm/versions/node/v21.7.3/bin | |
cd ~/deploy/clovapatra/ | |
if pm2 list | grep -q "clovapatra"; then | |
pm2 delete clovapatra | |
fi | |
sudo rm -rf ./be | |
unzip -o be.zip -d ./ | |
rm be.zip | |
cd ./be | |
pnpm install --prod | |
pnpm run build | |
pm2 start dist/main.js --name clovapatra | |
pm2 save |