Merge pull request #168 from boostcampwm-2024/dev-be #10
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: Deploy To EC2 | |
on: | |
push: | |
branches: ["release"] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Github Repository νμΌ λΆλ¬μ€κΈ° | |
uses: actions/checkout@v4 | |
- name: Node μ€μΉ | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
- name: BE μμ‘΄μ± μ€μΉ | |
working-directory: ./BE | |
run: npm ci | |
- name: FE μμ‘΄μ± μ€μΉ | |
working-directory: ./FE | |
run: npm ci | |
- name: .env νμΌ λ§λ€κΈ° | |
run: | | |
echo '${{ secrets.ENV }}' > .env | |
- name: BE ν μ€νΈ μ½λ μ€ν | |
working-directory: ./BE | |
run: npm run test | |
# 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: | | |
# BEμ FE λͺ¨λ νμ νμΌλ€μ ν¨κ» μμΆ | |
tar -czvf project.tar.gz \ | |
BE/dist \ | |
BE/package.json \ | |
BE/package-lock.json \ | |
.env \ | |
FE/dist \ | |
FE/package.json \ | |
FE/package-lock.json \ | |
- 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: SSHλ‘ EC2μ μ μνκΈ° | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
script_stop: true | |
script: | | |
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 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/ |