Skip to content

Merge pull request #161 from always97/feature-fe-prTemplate #6

Merge pull request #161 from always97/feature-fe-prTemplate

Merge pull request #161 from always97/feature-fe-prTemplate #6

Workflow file for this run

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"