From dbcd1d74855a3ab05cd3fd59ab299141d92ab547 Mon Sep 17 00:00:00 2001 From: bernard-ng Date: Tue, 18 Nov 2025 01:08:00 +0200 Subject: [PATCH] feat(ci): enhance deployment process --- .github/workflows/deploy.yaml | 1 + Makefile | 44 +++++++++++++++++++++++++++++++++++ ecosystem.config.js | 40 +++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 Makefile create mode 100644 ecosystem.config.js diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 123e53a..c66abb4 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -24,6 +24,7 @@ jobs: cd /var/www/html/basango.io git pull origin main --rebase bun install --frozen-lockfile + make deploy curl -X POST "https://api.telegram.org/bot${{ secrets.DEVY_TOKEN }}/sendMessage" \ -H "Content-Type: application/json" \ -d '{ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2921bb7 --- /dev/null +++ b/Makefile @@ -0,0 +1,44 @@ +.PHONY: default +default: help + +.PHONY: help +help: + @echo Tasks: + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +# ----------------------------------- +# Variables +# ----------------------------------- +BUN ?= bun +BUNX ?= bunx +PM2 ?= pm2 +PWD := $(shell pwd) +DRIZZLE_CONFIG ?= packages/db/drizzle.config.ts + +# ----------------------------------- +# Deployment +# ----------------------------------- +.PHONY: deploy +deploy: + $(BUN) install --frozen-lockfile. # Install dependencies + $(BUN) run build:dashboard # Build dashboard app + cd packages/db # Change directory to packages/db + $(BUNX) drizzle-kit migrate # Run database migrations + cd $(PWD) # Change back to root directory + $(PM2) reload ecosystem.config.js --env production # Reload PM2 processes + + +# ----------------------------------- +# PM2 Commands +# ----------------------------------- +.PHONY: start +start: + $(PM2) start ecosystem.config.js --env production + +.PHONY: restart +restart: + $(PM2) reload ecosystem.config.js --env production + +.PHONY: stop +stop: + $(PM2) stop ecosystem.config.js --env production diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 0000000..4bc26b5 --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,40 @@ +const path = require("node:path"); + +const sharedEnv = { + NODE_ENV: "production", +}; + +module.exports = { + apps: [ + { + args: "run crawler:worker", + autorestart: true, + cwd: path.join(__dirname, "apps", "crawler"), + env: sharedEnv, + max_restarts: 5, + name: "worker.basango.io", + script: "bun", + watch: false, + }, + { + args: "run start", + autorestart: true, + cwd: path.join(__dirname, "apps", "api"), + env: sharedEnv, + max_restarts: 5, + name: "api.basango.io", + script: "bun", + watch: false, + }, + { + args: "run start", + autorestart: true, + cwd: path.join(__dirname, "apps", "dashboard"), + env: sharedEnv, + max_restarts: 5, + name: "dashboard.basango.io", + script: "bun", + watch: false, + }, + ], +};