fix: turned off img optim #14
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: Node.js CI/CD to VPS | |
| on: | |
| push: | |
| branches: | |
| - main # Trigger saat ada push ke branch 'main' | |
| jobs: | |
| build_and_deploy: | |
| runs-on: ubuntu-latest # Runner yang digunakan oleh GitHub Actions | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 # Mengambil kode dari repositori | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| - name: Install dependencies and build | |
| # Install SEMUA dependensi (termasuk devDependencies) yang dibutuhkan untuk build | |
| run: | | |
| npm install | |
| npm run build | |
| - name: Prepare deployment package | |
| # Arsipkan file produksi, dan kecualikan direktori node_modules di dalam .output | |
| run: tar --exclude='.output/server/node_modules' -czvf deploy.tar.gz .output package.json server/SQL | |
| - name: Deploy package to VPS | |
| # Gunakan scp-action untuk MENDORONG file ke VPS. Ini lebih andal. | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| source: "deploy.tar.gz" | |
| target: "${{ secrets.APP_DIR_ON_VPS }}" | |
| - name: Install dependencies and restart server | |
| # Gunakan ssh-action untuk menjalankan perintah di VPS | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| # Keluar jika ada yang error | |
| set -e | |
| # Pindah ke direktori aplikasi | |
| cd ${{ secrets.APP_DIR_ON_VPS }} | |
| # Ekstrak paket yang baru saja di-upload | |
| tar -xzvf deploy.tar.gz | |
| rm deploy.tar.gz | |
| # Restart aplikasi dengan PM2. | |
| pm2 reload ecosystem.config.cjs | |
| echo "Deployment successful!" |