Merge pull request #23 from ije90s/dev #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: CI/CD Test | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| - name: Install Package | |
| run: npm ci | |
| - name: Test | |
| run: npm test | |
| - name: Build | |
| run: npm run build | |
| - name: Zip | |
| run: tar -czf app.tar.gz dist package.json package-lock.json ecosystem.config.js | |
| - name: Copy files to EC2 | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_PRIVATE_KEY }} | |
| source: "app.tar.gz" | |
| target: "/home/ubuntu/temp" | |
| - name: SSH to EC2 | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_PRIVATE_KEY }} | |
| script_stop: true | |
| script: | | |
| cd /home/ubuntu | |
| mkdir -p app | |
| rm -rf app/* | |
| tar -xzf /home/ubuntu/temp/app.tar.gz -C app | |
| cd app | |
| cp ../.env.prod ./.env | |
| chmod 600 .env | |
| npm ci --only=production | |
| npx typeorm migration:run -d ./dist/data-source.js | |
| pm2 startOrReload ecosystem.config.js --env production | |