diff --git a/.github/workflows/npm-publish-github-packages.yml b/.github/workflows/npm-publish-github-packages.yml new file mode 100644 index 000000000..21be21f90 --- /dev/null +++ b/.github/workflows/npm-publish-github-packages.yml @@ -0,0 +1,84 @@ +name: CD-TP-admin2-Backend +on: + push: + branches: + - release + + pull_request: + branches: + - release + + release: + types: [created, published] + +jobs: + build: + runs-on: ubuntu-latest + environment: envdev + + strategy: + matrix: + node-version: [ 22 ] + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - run: npm install + + - run: CI=false npm run build --if-present + + - name: Upload build artifact + uses: actions/upload-artifact@v5 + with: + name: tp-admin2-backend-app-artifact-${{ github.run_number }} + path: dist/ + + deploy: + runs-on: ubuntu-latest + environment: envdev + needs: build + + steps: + - name: Download build artifact + uses: actions/download-artifact@v6.0.0 + with: + name: tp-admin2-backend-app-artifact-${{ github.run_number }} + path: ./artifact-files + + - name: Show downloaded files + run: ls -R ./artifact-files + + - name: Setup SSH key + run: | + mkdir -p ~/.ssh + echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/deploy-key.pem + chmod 600 ~/.ssh/deploy-key.pem + ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts + + - name: Copy build files to EC2 server + run: | + # Create .env file from GitHub secret envirnoment envdev + echo "${{ secrets.ENV_FILE }}" > .env + + # Copy artifacts + .env to EC2 + scp -i ~/.ssh/deploy-key.pem -r ./artifact-files/* .env \ + ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/home/ubuntu/admin2-backend + + + - name: Restart app on EC2 + run: | + ssh -i ~/.ssh/deploy-key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF' + # Load NVM so PM2 becomes available + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + + pm2 restart trustlypay_admin2_backend_1.0 || echo "PM2 not found!" + pm2 list || echo "PM2 list failed!" + + sudo systemctl restart apache2 + sudo systemctl status apache2 --no-pager + EOF diff --git a/index.js b/index.js index 54e5fef1f..c6ee820d1 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const port = process.env.PORT || 3000; const server = http.createServer((req, res) => { res.statusCode = 200; - const msg = 'Hello Node!\n' + const msg = 'Hello Node Application!\n' res.end(msg); });