-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37cd74f
commit 8217b3e
Showing
1 changed file
with
41 additions
and
29 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ํ์ผ ๋ถ๋ฌ์ค๊ธฐ | ||
|
@@ -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] | ||
|
@@ -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/ |