From 9b0c7f08bfac664bb195394311d0ddc636771ae2 Mon Sep 17 00:00:00 2001 From: zkldi Date: Tue, 8 Jun 2021 14:41:04 +0100 Subject: [PATCH] Figure out config and CI updates --- server/.github/test.conf.json5 | 13 +++++++++++++ server/.github/workflows/tests.yml | 13 ++----------- server/package.json | 2 +- server/src/external/redis/redis-IPC.ts | 7 ++++--- server/src/lib/constants/version.ts | 1 + server/src/lib/setup/config.ts | 2 ++ server/src/main.ts | 12 ++++++------ server/src/server/server-config.ts | 3 --- 8 files changed, 29 insertions(+), 24 deletions(-) create mode 100644 server/.github/test.conf.json5 delete mode 100644 server/src/server/server-config.ts diff --git a/server/.github/test.conf.json5 b/server/.github/test.conf.json5 new file mode 100644 index 000000000..1b0299538 --- /dev/null +++ b/server/.github/test.conf.json5 @@ -0,0 +1,13 @@ +{ + MONGO_BASE_URL: "127.0.0.1", + LOG_LEVEL: "info", + CAPTCHA_SECRET_KEY: "unused", + SESSION_SECRET: "unused", + FLO_API_URL: "https://flo.example.com", + EAG_API_URL: "https://eag.example.com", + ARC_API_URL: "https://arc.example.com", + ARC_AUTH_TOKEN: "unused", + CDN_ROOT: "./local-cdn", + PORT: 8080, + TYPE: "ktchi", // It really doesn't matter whether we're in bokutachi or kamaitachi mode. If we had the performance we could run these in parallel? +} diff --git a/server/.github/workflows/tests.yml b/server/.github/workflows/tests.yml index a54d5f4d7..418b3aeee 100644 --- a/server/.github/workflows/tests.yml +++ b/server/.github/workflows/tests.yml @@ -1,16 +1,7 @@ -name: KTBlack-Server CI +name: Tachi-Server CI env: - KTBSV_MONGO_BASE_URL: "127.0.0.1" NODE_ENV: "test" - KTBSV_LOG_LEVEL: "info" - KTBSV_CAPTCHA_SECRET_KEY: "unused" - KTBSV_SESSION_SECRET: "unused" - KTBSV_FLO_API_URL: "https://flo.example.com" - KTBSV_EAG_API_URL: "https://eag.example.com" - KTBSV_ARC_API_URL: "https://arc.example.com" - KTBSV_ARC_AUTH_TOKEN: "unused" - KTCDN_ROOT: "./local-cdn" CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} on: @@ -27,7 +18,7 @@ jobs: - name: Checkout Code uses: actions/checkout@v2 - - name: Install Node.js 15 + - name: Install Node.js 16 uses: actions/setup-node@v2 with: node-version: 16.x diff --git a/server/package.json b/server/package.json index 3228eb149..f45d075ac 100644 --- a/server/package.json +++ b/server/package.json @@ -5,7 +5,7 @@ "main": "js/index.js", "scripts": { "fulltest": "tap", - "paralleltest": "export KTBSV_PARALLEL_TESTS=true && tap -J", + "paralleltest": "export TACHI_PARALLEL_TESTS=true && tap -J", "watchtest": "tap --watch", "build": "tsc --project tsconfig.build.json", "lint": "eslint ./src --ext .ts --fix", diff --git a/server/src/external/redis/redis-IPC.ts b/server/src/external/redis/redis-IPC.ts index 768c149bc..05253c4ea 100644 --- a/server/src/external/redis/redis-IPC.ts +++ b/server/src/external/redis/redis-IPC.ts @@ -1,6 +1,7 @@ import redis from "redis"; import { RedisIPCChannels, RedisIPCData } from "tachi-common"; import CreateLogCtx from "../../lib/logger/logger"; +import { CONFIG } from "../../lib/setup/config"; const logger = CreateLogCtx(__filename); @@ -18,7 +19,7 @@ const SubCallbacks: Partial = {}; const SubClient = redis.createClient(); const PubClient = redis.createClient(); -const PREFIX = "KTBSV"; +const PREFIX = CONFIG.TYPE.toUpperCase(); // KTCHI or BTCHI export function RedisPub(channel: T, data: RedisIPCData[T]) { PubClient.publish(`${PREFIX}-${channel}`, JSON.stringify(data)); @@ -39,11 +40,11 @@ export function RedisSub(channel: T, callback: Redis } SubClient.on("message", (channel, strData) => { - if (!channel.startsWith("KTBSV-")) { + if (!channel.startsWith(`${PREFIX}-`)) { return; // not our business } - const ktChannel = channel.slice("KTBSV-".length) as RedisIPCChannels; + const ktChannel = channel.slice(`${PREFIX}-`.length) as RedisIPCChannels; if (!Object.prototype.hasOwnProperty.call(SubCallbacks, ktChannel)) { return; // no callbacks to call diff --git a/server/src/lib/constants/version.ts b/server/src/lib/constants/version.ts index 9e2e09ef3..ad5cb46b9 100644 --- a/server/src/lib/constants/version.ts +++ b/server/src/lib/constants/version.ts @@ -1,4 +1,5 @@ // The Downward Spiral +// Version Info is intentionally identical between all variants of tachi export const VERSION_INFO = { major: 2, diff --git a/server/src/lib/setup/config.ts b/server/src/lib/setup/config.ts index 24d4eacdd..e03381f6e 100644 --- a/server/src/lib/setup/config.ts +++ b/server/src/lib/setup/config.ts @@ -87,3 +87,5 @@ export const ARC_API_URL = tachiConfig.ARC_API_URL; export const ARC_AUTH_TOKEN = tachiConfig.ARC_AUTH_TOKEN; export const KTCDN_ROOT = tachiConfig.CDN_ROOT; export const CONF_INFO = tachiConfig.INFO; +export const PORT = tachiConfig.PORT; +export const CONFIG = tachiConfig; diff --git a/server/src/main.ts b/server/src/main.ts index 2d6bc196f..54ebe4028 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -1,13 +1,13 @@ import CreateLogCtx from "./lib/logger/logger"; import server from "./server/server"; -import serverConfig from "./server/server-config"; -import { LOG_LEVEL } from "./lib/setup/config"; +import { CONF_INFO, LOG_LEVEL, PORT } from "./lib/setup/config"; + import { FormatVersion } from "./lib/constants/version"; const logger = CreateLogCtx(__filename); -logger.info(`Booting Kamaitachi BLACK - ${FormatVersion()} [ENV: ${process.env.NODE_ENV}]`); -logger.info(`Log level on ${LOG_LEVEL ?? "info"}.`); +logger.info(`Booting ${CONF_INFO.NAME} - ${FormatVersion()} [ENV: ${process.env.NODE_ENV}]`); +logger.info(`Log level is set to ${LOG_LEVEL}.`); -server.listen(serverConfig.PORT); -logger.info(`Listening on ${serverConfig.PORT}`); +server.listen(PORT); +logger.info(`Listening on port ${PORT}`); diff --git a/server/src/server/server-config.ts b/server/src/server/server-config.ts deleted file mode 100644 index cc203615b..000000000 --- a/server/src/server/server-config.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default { - PORT: process.env.KTBSV_PORT ?? 8080, -};