Merge pull request #161 from always97/feature-fe-prTemplate #6
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: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
# defaults: | |
# run: | |
# working-directory: ./BE # BE λλ ν 리λ₯Ό μμ λλ ν λ¦¬λ‘ μ€μ | |
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: ν μ€νΈ μ½λ μ€ν | |
run: npm run test | |
- name: λΉλ | |
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 \ | |
FE/package.json \ | |
FE/package-lock.json \ | |
FE/.env | |
# μμΆ νμΌ λ΄μ© νμΈ (λλ²κΉ μ©) | |
echo "Created archive with contents:" | |
tar -tvf project.tar.gz | |
- 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] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
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 | |
tar -xvf project.tar.gz | |
npm i | |
pm2 kill | |
pm2 start dist/main.js --name "backend-server" |