From c5ee61ff45daf70234968ab1a47950b25a8ae71b Mon Sep 17 00:00:00 2001 From: cheetah Date: Sat, 5 Apr 2025 13:43:13 +0200 Subject: [PATCH] added ci/cd --- .forgejo/workflows/build.yaml | 25 +++++++++++++++++++++++++ Dockerfile | 17 +++++++++++++++++ compose.yaml | 20 ++++++++++++++++++++ config.default.json | 8 ++++++++ config.json | 33 +-------------------------------- index.js | 12 ++++++++++-- 6 files changed, 81 insertions(+), 34 deletions(-) create mode 100644 .forgejo/workflows/build.yaml create mode 100644 Dockerfile create mode 100644 compose.yaml create mode 100644 config.default.json diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml new file mode 100644 index 0000000..0c6b4f2 --- /dev/null +++ b/.forgejo/workflows/build.yaml @@ -0,0 +1,25 @@ +name: build +on: + push: + pull_request: + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-22.04 + steps: + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + registry: git.cheetah.cat + username: ${{ github.actor }} + password: ${{ secrets.PAT_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64 + push: true + tags: git.cheetah.cat/smartpager/${{ github.event.repository.name }}:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..be8dbeb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +ARG NODE_VERSION=23.0.0 + +FROM node:${NODE_VERSION}-alpine + +ENV NODE_ENV production + +WORKDIR /usr/src/app + +COPY package.json . + +RUN npm install + +COPY . . +USER node +EXPOSE 3090 + +CMD node index.js \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..8ce98b7 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,20 @@ +services: + dispatcher: + image: git.cheetah.cat/smartpager/dispatcher:latest + environment: + NODE_ENV: production + volumes: + - ../dispatcher/config.json:/usr/src/app/config.json + ports: + - 3000:3000 + - 3001:3001 + msg_mowas: + build: + context: . + environment: + NODE_ENV: production + DISPATCHER: "dispatcher:3000" + volumes: + - ./config.json:/usr/src/app/config.json + ports: + - 3090:3090 diff --git a/config.default.json b/config.default.json new file mode 100644 index 0000000..87b1b91 --- /dev/null +++ b/config.default.json @@ -0,0 +1,8 @@ +{ + "pager": { + "url": "http://127.0.0.1:3000/api/message/advanced" + }, + "germanUmlautSupport": true, + "regions": [ + ] +} \ No newline at end of file diff --git a/config.json b/config.json index 2e97daf..87b1b91 100644 --- a/config.json +++ b/config.json @@ -1,39 +1,8 @@ { "pager": { - "url": "http://127.0.0.1:3000/api/message/advanced", - "params": { - "type": "simple", - "routing": { - "device": "generic", - "connectors": [ - [ - "dummy", - "1234567" - ] - ] - } - } + "url": "http://127.0.0.1:3000/api/message/advanced" }, "germanUmlautSupport": true, "regions": [ - { - "name": "MD", - "active": true, - "params": { - "type": "duplex", - "routing": { - "device": "birdyslim", - "connectors": [ - [ - "dummy", - "123456" - ] - ] - } - }, - "regionsID": "150030000000", - "mowas": true, - "preset": "184cca745aa" - } ] } \ No newline at end of file diff --git a/index.js b/index.js index 3f9c0d6..5832ab9 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,14 @@ const fs = require('fs') - -const config = require('./config.json') +const actualConfig = require('./config.json') +const defaultConfig = require('./config.default.json') +const config = defaultConfig +Object.assign(config, actualConfig) +let dispatcherHost = "127.0.0.1:3000" +if (!!process.env.DISPATCHER) { + console.log("docker mode") + dispatcherHost = process.env.DISPATCHER + config.pager.url = `http://${ dispatcherHost }/api/message/advanced` +} const axios = require('axios')