diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index 243201d..388be52 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -7,31 +7,31 @@ on: - 'v*' - 'release-*' jobs: - # build-and-test: - # runs-on: docker - # container: - # image: node:20-slim - # steps: - # - name: Checkout code - # uses: actions/checkout@v4 - # - name: Set up timezone - # run: | - # apt-get update && apt-get install -y tzdata - # ln -snf /usr/share/zoneinfo/Asia/Bangkok /etc/localtime - # echo "Asia/Bangkok" > /etc/timezone - # rm -rf /var/lib/apt/lists/* - # - name: Cache npm dependencies - # uses: actions/cache@v3 - # with: - # path: ~/.npm - # key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - # restore-keys: | - # ${{ runner.os }}-node- - # - name: Install dependencies - # run: npm install - # - name: Show heartbeat.js version and changelogs - # run: | - # awk '/const heartbeatApiInfo = {/,/};/' plugins/heartbeat.js | sed -n '/version:/,/],/p' + build-and-test: + runs-on: docker + container: + image: node:20-slim + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up timezone + run: | + apt-get update && apt-get install -y tzdata + ln -snf /usr/share/zoneinfo/Asia/Bangkok /etc/localtime + echo "Asia/Bangkok" > /etc/timezone + rm -rf /var/lib/apt/lists/* + - name: Cache npm dependencies + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install dependencies + run: npm install + - name: Show version and changelogs from all plugins + run: | + find plugins -type f -name "*.js" -exec sh -c 'echo "From file: {}"; awk "/version:/{flag=1} flag{print} /]/||/}/{flag=0}" "{}" | sed -n "/version:/,/]/p"' \; # - name: Run application # run: npm start # env: diff --git a/app.js b/app.js index a7f72b9..a47652a 100644 --- a/app.js +++ b/app.js @@ -6,6 +6,7 @@ var cookieParser = require("cookie-parser"); var indexRouter = require("./routes/index"); var usersRouter = require("./routes/users"); +var healthRouter = require("./routes/health") // const { createLogger, format, transports } = require('winston'); const { @@ -39,6 +40,7 @@ app app.use("/", indexRouter); app.use("/users", usersRouter); +app.use("/health", healthRouter); Log.debug(`running on port ${process.env.PORT}`); @@ -86,7 +88,7 @@ GoogleFunctions.syncProfilePrice(sheet, "tha", false); // // Test Taobin SyncText -SyncText.run(sheet, "uae", false); +// SyncText.run(sheet, "uae", false); const pm = new PluginsManager(cronTasks, CronJobs); pm.load(); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d80afd1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,48 @@ +version: '3.8' + +services: + my-express-app: + image: pakin-inspiron-15-3530.tail110d9.ts.net/my-express-app:1.0.0 + container_name: my-express-app + restart: unless-stopped + ports: + - "3000:3000" + + # 🔑 KEY: These labels make your app discoverable and manageable + labels: + # Enable automatic updates + - "silserv.enable=true" + + # Registry configuration + - "silserv.registry=pakin-inspiron-15-3530.tail110d9.ts.net" + - "silserv.image=my-express-app" + + # Health check endpoint + - "silserv.health-path=/health" + + # Update strategy: automatic, manual, or cron expression + - "silserv.strategy=automatic" + + # Optional: Additional metadata + # - "silserv.=" + - "silserv.description=My Express Application" + - "silserv.team=backend" + + # 🌐 IMPORTANT: Must be on the update-manager network + networks: + - silserv-network + + environment: + - NODE_ENV=production + - APP_VERSION=1.0.0 + + # Health check for Docker + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3000/health"] + interval: 30s + timeout: 10s + retries: 3 + +networks: + silserv-network: + external: true \ No newline at end of file diff --git a/routes/health.js b/routes/health.js new file mode 100644 index 0000000..eb60852 --- /dev/null +++ b/routes/health.js @@ -0,0 +1,20 @@ +var express = require('express'); +var router = express.Router(); + +const healthStatus = [ + "OK", + "FAIL" +] + +router.get('/', function (req, res) { + const jobs = CronJobs.getAllRunning; + const data = []; + + for (let [name, job] of jobs) { + data.push({ name, status: healthStatus[0] }); + } + + res.json({ data }); +}); + +module.exports = router; \ No newline at end of file