Skip to content

Commit

Permalink
ci/cd: [BE] deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
DongHoonYu96 authored Nov 6, 2024
1 parent 37cd74f commit 8217b3e
Showing 1 changed file with 41 additions and 29 deletions.
70 changes: 41 additions & 29 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ name: Deploy To EC2

on:
push:
branches:
- release
branches: [ "release" ]

jobs:
deploy:
runs-on: ubuntu-latest
# defaults:
# run:
# working-directory: ./BE # BE ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์„ค์ •

steps:
- name: Github Repository ํŒŒ์ผ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
Expand All @@ -33,40 +29,45 @@ jobs:
run: |
echo '${{ secrets.ENV }}' > .env
- name: ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์‹คํ–‰
- name: BE ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์‹คํ–‰
working-directory: ./BE
run: npm run test

- name: ๋นŒ๋“œ
# todo: FE ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์‹คํ–‰
# - name: FE ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์‹คํ–‰
# working-directory: ./FE
# run: npm run test

- name: BE ๋นŒ๋“œ
working-directory: ./BE
run: npm run build

- name: FE ๋นŒ๋“œ
working-directory: ./FE
run: npm run build

- name: github-action ์ปดํ“จํ„ฐ์—์„œ ์••์ถ•ํ•˜๊ธฐ
run: |
# ํ˜„์žฌ ์œ„์น˜ ํ™•์ธ (๋””๋ฒ„๊น…์šฉ)
pwd
# BE์™€ FE ๋ชจ๋“  ํ•„์š” ํŒŒ์ผ๋“ค์„ ํ•จ๊ป˜ ์••์ถ•
tar -czvf project.tar.gz \
BE/dist \
BE/package.json \
BE/package-lock.json \
BE/.env \
FE/build \
.env \
FE/dist \
FE/package.json \
FE/package-lock.json \
FE/.env
# ์••์ถ• ํŒŒ์ผ ๋‚ด์šฉ ํ™•์ธ (๋””๋ฒ„๊น…์šฉ)
echo "Created archive with contents:"
tar -tvf project.tar.gz
- name: Rsync๋กœ EC2์— ๋นŒ๋“œ๋œ ํŒŒ์ผ ์ „์†กํ•˜๊ธฐ
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
rsync -avz project.tar.gz \
ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/nest-server/tobe/
- name: SCP๋กœ EC2์— ๋นŒ๋“œ๋œ ํŒŒ์ผ ์ „์†กํ•˜๊ธฐ
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
source: project.tar.gz
target: /root/nest-server/tobe
- name: SSH๋กœ EC2์— ์ ‘์†ํ•˜๊ธฐ
uses: appleboy/[email protected]
Expand All @@ -76,11 +77,22 @@ jobs:
key: ${{ secrets.EC2_PRIVATE_KEY }}
script_stop: true
script: |
rm -rf /root/nest-server/current
mkdir /root/nest-server/current
mv /root/nest-server/tobe/project.tar.gz /root/nest-server/current/project.tar.gz
cd /root/nest-server/current
rm -rf /home/ubuntu/nest-server/current
mkdir /home/ubuntu/nest-server/current
mv /home/ubuntu/nest-server/tobe/project.tar.gz /home/ubuntu/nest-server/current/project.tar.gz
cd /home/ubuntu/nest-server/current
tar -xvf project.tar.gz
cd /home/ubuntu/nest-server/current/BE
npm i
cd
cd /home/ubuntu/nest-server/current/FE
npm i
pm2 kill
pm2 stop backend-server || true
cd /home/ubuntu/nest-server/current/BE
pm2 start dist/main.js --name "backend-server"
# todo: # FrontEnd ๋ฐฐํฌ
# # Frontend ๋ฐฐํฌ
# echo "Deploying Frontend..."
# sudo rm -rf /var/www/html/*
# sudo cp -r ../FE/dist/* /var/www/html/

0 comments on commit 8217b3e

Please sign in to comment.