diff --git a/.forgejo/workflows/beta.yml b/.forgejo/workflows/beta.yml new file mode 100644 index 0000000..bf096a2 --- /dev/null +++ b/.forgejo/workflows/beta.yml @@ -0,0 +1,77 @@ +name: Deploy Beta (NATIVE) + +on: + push: + branches: + - beta + +jobs: + deploy: + runs-on: ubuntu-latest + container: + image: node:20-alpine + steps: + - name: Install git + run: apk add --no-cache git + + - name: Checkout Code + uses: https://github.com/actions/checkout@v4 + + - name: Package Application + run: | + tar -czf app.tar.gz --exclude=.git --exclude=node_modules --exclude=data --exclude=tmp . + + - name: Deploy to cisystem EC2 + run: | + apk add --no-cache openssh-client + mkdir -p ~/.ssh + echo "${{ secrets.BETA_EC2_SSH_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + + # Copy app archive and systemd service + scp -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa app.tar.gz resourcemanagement.service ${{ secrets.BETA_EC2_USERNAME }}@${{ secrets.BETA_EC2_HOST }}:/tmp/ + + # Execute deployment commands on cisystem + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.BETA_EC2_USERNAME }}@${{ secrets.BETA_EC2_HOST }} << 'EOF' + set -e + + # ── 1. Target Directory Setup ──────────────────────────────── + sudo mkdir -p /home/ubuntu/resourcemanagement/logs + sudo chown -R ubuntu:ubuntu /home/ubuntu/resourcemanagement + tar -xzf /tmp/app.tar.gz -C /home/ubuntu/resourcemanagement + + cd /home/ubuntu/resourcemanagement + + # ── 2. Environment Configuration ──────────────────────────── + cat << 'ENVEOF' > .env + NODE_ENV=production + PORT=3002 + UPTIME_KUMA_PORT=3002 + UPTIME_KUMA_DB_TYPE=postgres + DB_HOST=16.113.106.152 + DB_PORT=5432 + DB_USER=vignesh + DB_PASSWORD=vignesh_secret_pass_2026 + DB_NAME=ResourceManagement + ENVEOF + + # ── 3. Install Dependencies & Build ───────────────────────── + npm install --legacy-peer-deps --engine-strict=false + npm run build + + # ── 4. Systemd Service Deployment ─────────────────────────── + sudo cp /tmp/resourcemanagement.service /etc/systemd/system/resourcemanagement.service + sudo systemctl daemon-reload + sudo systemctl enable resourcemanagement.service + sudo systemctl restart resourcemanagement.service || { + echo "resourcemanagement.service failed to restart! Logs:" + sudo journalctl -u resourcemanagement.service -n 50 --no-pager + exit 1 + } + + # ── 5. Reload Nginx ───────────────────────────────────────── + sudo nginx -t && sudo systemctl reload nginx + + rm -f /tmp/app.tar.gz /tmp/resourcemanagement.service + echo "ResourceManagement deployed successfully to status.tradhox.com!" + EOF diff --git a/resourcemanagement.service b/resourcemanagement.service new file mode 100644 index 0000000..e260902 --- /dev/null +++ b/resourcemanagement.service @@ -0,0 +1,25 @@ +[Unit] +Description=ResourceManagement Monitoring Service (status.tradhox.com) +After=network.target postgresql.service + +[Service] +Type=simple +User=ubuntu +WorkingDirectory=/home/ubuntu/resourcemanagement +Environment=NODE_ENV=production +Environment=PORT=3002 +Environment=UPTIME_KUMA_PORT=3002 +Environment=UPTIME_KUMA_DB_TYPE=postgres +Environment=DB_HOST=16.113.106.152 +Environment=DB_PORT=5432 +Environment=DB_USER=vignesh +Environment=DB_PASSWORD=vignesh_secret_pass_2026 +Environment=DB_NAME=ResourceManagement +ExecStart=/usr/bin/npm start -- --port=3002 +Restart=always +RestartSec=10 +StandardOutput=append:/home/ubuntu/resourcemanagement/logs/app.log +StandardError=append:/home/ubuntu/resourcemanagement/logs/error.log + +[Install] +WantedBy=multi-user.target