Repository navigation
Merge pull request #45 from TUK-UMC/Jini-10 #8
This file contains hidden or 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 | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '20' | |
| - name: Install Dependencies | |
| working-directory: ./Jini2 | |
| run: npm install | |
| - name: Connect & Deploy to EC2 | |
| env: | |
| SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY_JINI }} | |
| EC2_HOST: ${{ secrets.EC2_HOST_JINI }} | |
| EC2_USER: ${{ secrets.EC2_USER_JINI }} | |
| BACKEND_ENV: ${{ secrets.BACKEND_ENV_JINI }} | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| ssh -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST << 'EOF' | |
| #프로젝트 root로 이동 | |
| cd /home/ubuntu/umc_study/Jini2 | |
| # pull 받아오기 | |
| git pull origin main | |
| # env 파일 생성 | |
| export BACKEND_ENV="${{ secrets.BACKEND_ENV_JINI }}" #echo로만 안될때 사용 | |
| echo "${BACKEND_ENV_JINI}" > .env | |
| # 종속성 설치 | |
| npm install | |
| # 프리즈마 마이그레이션 | |
| npx prisma migrate deploy | |
| # 앱 재시작 - 변경사항 반영 | |
| pm2 reload all || pm2 start src/index.js --name "Jini2" | |
| pm2 status #확인용 | |
| EOF |