refactor (backend): drop support for MK- environment variables

This commit is contained in:
naskya 2024-06-06 17:10:39 +09:00
parent 97765209a2
commit 7e2493b257
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
14 changed files with 27 additions and 119 deletions

View file

@ -2,6 +2,17 @@
You can skip intermediate versions when upgrading from an old version, but please read the notices and follow the instructions for each intermediate version before [upgrading](./upgrade.md). You can skip intermediate versions when upgrading from an old version, but please read the notices and follow the instructions for each intermediate version before [upgrading](./upgrade.md).
## Unreleased
The following environment variables are deprecated and no longer have any effect:
- `MK_ONLY_QUEUE`
- `MK_ONLY_SERVER`
- `MK_NO_DAEMONS`
- `MK_DISABLE_CLUSTERING`
- `MK_VERBOSE`
- `MK_WITH_LOG_TIME`
- `MK_SLOW`
## v20240601 ## v20240601
### For systemd/pm2 users ### For systemd/pm2 users

View file

@ -19,16 +19,6 @@ export const USER_ACTIVE_THRESHOLD: number
* * <https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Containers> * * <https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Containers>
*/ */
export const FILE_TYPE_BROWSERSAFE: string[] export const FILE_TYPE_BROWSERSAFE: string[]
export interface EnvConfig {
onlyQueue: boolean
onlyServer: boolean
noDaemons: boolean
disableClustering: boolean
verbose: boolean
withLogTime: boolean
slow: boolean
}
export function loadEnv(): EnvConfig
export function fetchMeta(): Promise<Meta> export function fetchMeta(): Promise<Meta>
export function updateMetaCache(): Promise<void> export function updateMetaCache(): Promise<void>
export interface PugArgs { export interface PugArgs {

View file

@ -310,7 +310,7 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`) throw new Error(`Failed to load native binding`)
} }
const { SECOND, MINUTE, HOUR, DAY, USER_ONLINE_THRESHOLD, USER_ACTIVE_THRESHOLD, FILE_TYPE_BROWSERSAFE, loadEnv, fetchMeta, updateMetaCache, metaToPugArgs, loadConfig, stringToAcct, acctToString, fetchNodeinfo, nodeinfo_2_1, nodeinfo_2_0, Protocol, Inbound, Outbound, greet, initializeRustLogger, showServerInfo, isBlockedServer, isSilencedServer, isAllowedServer, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, isUnicodeEmoji, sqlLikeEscape, safeForSql, formatMilliseconds, getImageSizeFromUrl, getNoteSummary, isQuote, isSafeUrl, latestVersion, toMastodonId, fromMastodonId, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, decodeReaction, countReactions, toDbReaction, removeOldAttestationChallenges, cpuInfo, cpuUsage, memoryUsage, storageUsage, AntennaSrc, DriveFileUsageHint, MutedNoteReason, NoteVisibility, NotificationType, PageVisibility, PollNoteVisibility, RelayStatus, UserEmojiModPerm, UserProfileFfvisibility, UserProfileMutingNotificationTypes, updateAntennasOnNewNote, watchNote, unwatchNote, PushNotificationKind, sendPushNotification, publishToChannelStream, publishToChatStream, ChatIndexEvent, publishToChatIndexStream, publishToBroadcastStream, publishToGroupChatStream, publishToModerationStream, ChatEvent, getTimestamp, genId, genIdAt, generateSecureRandomString, generateUserToken } = nativeBinding const { SECOND, MINUTE, HOUR, DAY, USER_ONLINE_THRESHOLD, USER_ACTIVE_THRESHOLD, FILE_TYPE_BROWSERSAFE, fetchMeta, updateMetaCache, metaToPugArgs, loadConfig, stringToAcct, acctToString, fetchNodeinfo, nodeinfo_2_1, nodeinfo_2_0, Protocol, Inbound, Outbound, greet, initializeRustLogger, showServerInfo, isBlockedServer, isSilencedServer, isAllowedServer, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, isUnicodeEmoji, sqlLikeEscape, safeForSql, formatMilliseconds, getImageSizeFromUrl, getNoteSummary, isQuote, isSafeUrl, latestVersion, toMastodonId, fromMastodonId, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, decodeReaction, countReactions, toDbReaction, removeOldAttestationChallenges, cpuInfo, cpuUsage, memoryUsage, storageUsage, AntennaSrc, DriveFileUsageHint, MutedNoteReason, NoteVisibility, NotificationType, PageVisibility, PollNoteVisibility, RelayStatus, UserEmojiModPerm, UserProfileFfvisibility, UserProfileMutingNotificationTypes, updateAntennasOnNewNote, watchNote, unwatchNote, PushNotificationKind, sendPushNotification, publishToChannelStream, publishToChatStream, ChatIndexEvent, publishToChatIndexStream, publishToBroadcastStream, publishToGroupChatStream, publishToModerationStream, ChatEvent, getTimestamp, genId, genIdAt, generateSecureRandomString, generateUserToken } = nativeBinding
module.exports.SECOND = SECOND module.exports.SECOND = SECOND
module.exports.MINUTE = MINUTE module.exports.MINUTE = MINUTE
@ -319,7 +319,6 @@ module.exports.DAY = DAY
module.exports.USER_ONLINE_THRESHOLD = USER_ONLINE_THRESHOLD module.exports.USER_ONLINE_THRESHOLD = USER_ONLINE_THRESHOLD
module.exports.USER_ACTIVE_THRESHOLD = USER_ACTIVE_THRESHOLD module.exports.USER_ACTIVE_THRESHOLD = USER_ACTIVE_THRESHOLD
module.exports.FILE_TYPE_BROWSERSAFE = FILE_TYPE_BROWSERSAFE module.exports.FILE_TYPE_BROWSERSAFE = FILE_TYPE_BROWSERSAFE
module.exports.loadEnv = loadEnv
module.exports.fetchMeta = fetchMeta module.exports.fetchMeta = fetchMeta
module.exports.updateMetaCache = updateMetaCache module.exports.updateMetaCache = updateMetaCache
module.exports.metaToPugArgs = metaToPugArgs module.exports.metaToPugArgs = metaToPugArgs

View file

@ -1,29 +0,0 @@
//! Environment options
// FIXME: Are these options used?
#[crate::export(object)]
pub struct EnvConfig {
pub only_queue: bool,
pub only_server: bool,
pub no_daemons: bool,
pub disable_clustering: bool,
pub verbose: bool,
pub with_log_time: bool,
pub slow: bool,
}
#[crate::export]
pub fn load_env() -> EnvConfig {
let node_env = std::env::var("NODE_ENV").unwrap_or_default().to_lowercase();
let is_testing = node_env == "test";
EnvConfig {
only_queue: std::env::var("MK_ONLY_QUEUE").is_ok(),
only_server: std::env::var("MK_ONLY_SERVER").is_ok(),
no_daemons: is_testing || std::env::var("MK_NO_DAEMONS").is_ok(),
disable_clustering: is_testing || std::env::var("MK_DISABLE_CLUSTERING").is_ok(),
verbose: std::env::var("MK_VERBOSE").is_ok(),
with_log_time: std::env::var("MK_WITH_LOG_TIME").is_ok(),
slow: std::env::var("MK_SLOW").is_ok(),
}
}

View file

@ -4,6 +4,5 @@ pub use meta::local_server_info;
pub use server::CONFIG; pub use server::CONFIG;
pub mod constant; pub mod constant;
pub mod environment;
pub mod meta; pub mod meta;
pub mod server; pub mod server;

View file

@ -77,7 +77,6 @@
"koa-mount": "4.0.0", "koa-mount": "4.0.0",
"koa-remove-trailing-slashes": "2.0.3", "koa-remove-trailing-slashes": "2.0.3",
"koa-send": "5.0.1", "koa-send": "5.0.1",
"koa-slow": "2.1.0",
"megalodon": "workspace:*", "megalodon": "workspace:*",
"mfm-js": "0.24.0", "mfm-js": "0.24.0",
"mime-types": "2.1.35", "mime-types": "2.1.35",

View file

@ -1,14 +0,0 @@
declare module "koa-slow" {
import type { Middleware } from "koa";
interface ISlowOptions {
url?: RegExp;
delay?: number;
}
function slow(options?: ISlowOptions): Middleware;
namespace slow {} // Hack
export = slow;
}

View file

@ -3,7 +3,6 @@ import chalk from "chalk";
import Xev from "xev"; import Xev from "xev";
import Logger from "@/services/logger.js"; import Logger from "@/services/logger.js";
import { envOption } from "@/config.js";
import { inspect } from "node:util"; import { inspect } from "node:util";
// for typeorm // for typeorm
@ -31,14 +30,14 @@ export default async function () {
const type = cluster.isPrimary ? "(master)" : "(worker)"; const type = cluster.isPrimary ? "(master)" : "(worker)";
process.title = `Firefish ${mode} ${type}`; process.title = `Firefish ${mode} ${type}`;
if (cluster.isPrimary || envOption.disableClustering) { if (cluster.isPrimary) {
await masterMain(); await masterMain();
if (cluster.isPrimary) { if (cluster.isPrimary) {
ev.mount(); ev.mount();
} }
} }
if (cluster.isWorker || envOption.disableClustering) { if (cluster.isWorker) {
await workerMain(); await workerMain();
} }

View file

@ -10,7 +10,7 @@ import {
updateMetaCache, updateMetaCache,
type Config, type Config,
} from "backend-rs"; } from "backend-rs";
import { config, envOption } from "@/config.js"; import { config } from "@/config.js";
import { db, initDb } from "@/db/postgre.js"; import { db, initDb } from "@/db/postgre.js";
import { inspect } from "node:util"; import { inspect } from "node:util";
@ -39,9 +39,7 @@ export async function masterMain() {
bootLogger.info("Firefish initialized"); bootLogger.info("Firefish initialized");
if (!envOption.disableClustering) { await spawnWorkers(config.clusterLimits);
await spawnWorkers(config.clusterLimits);
}
bootLogger.info( bootLogger.info(
`Now listening on port ${config.port} on ${config.url}`, `Now listening on port ${config.port} on ${config.url}`,
@ -49,14 +47,12 @@ export async function masterMain() {
true, true,
); );
if (!envOption.noDaemons) { import("../daemons/server-stats.js").then((x) => x.default());
import("../daemons/server-stats.js").then((x) => x.default()); import("../daemons/queue-stats.js").then((x) => x.default());
import("../daemons/queue-stats.js").then((x) => x.default()); // Update meta cache every 5 minitues
// Update meta cache every 5 minitues setInterval(() => updateMetaCache(), 1000 * 60 * 5);
setInterval(() => updateMetaCache(), 1000 * 60 * 5); // Remove old attestation challenges
// Remove old attestation challenges setInterval(() => removeOldAttestationChallenges(), 1000 * 60 * 30);
setInterval(() => removeOldAttestationChallenges(), 1000 * 60 * 30);
}
} }
function showEnvironment(): void { function showEnvironment(): void {

View file

@ -1,4 +1,3 @@
import { loadConfig, loadEnv } from "backend-rs"; import { loadConfig } from "backend-rs";
export const config = loadConfig(); export const config = loadConfig();
export const envOption = loadEnv();

View file

@ -1,7 +1,7 @@
import type httpSignature from "@peertube/http-signature"; import type httpSignature from "@peertube/http-signature";
import { v4 as uuid } from "uuid"; import { v4 as uuid } from "uuid";
import { config, envOption } from "@/config.js"; import { config } from "@/config.js";
import type { DriveFile } from "@/models/entities/drive-file.js"; import type { DriveFile } from "@/models/entities/drive-file.js";
import type { IActivity } from "@/remote/activitypub/type.js"; import type { IActivity } from "@/remote/activitypub/type.js";
import type { Webhook, webhookEventTypes } from "@/models/entities/webhook.js"; import type { Webhook, webhookEventTypes } from "@/models/entities/webhook.js";
@ -518,8 +518,6 @@ export function webhookDeliver(
} }
export default function () { export default function () {
if (envOption.onlyServer) return;
deliverQueue.process(config.deliverJobConcurrency || 128, processDeliver); deliverQueue.process(config.deliverJobConcurrency || 128, processDeliver);
inboxQueue.process(config.inboxJobConcurrency || 16, processInbox); inboxQueue.process(config.inboxJobConcurrency || 16, processInbox);
endedPollNotificationQueue.process(endedPollNotification); endedPollNotificationQueue.process(endedPollNotification);

View file

@ -10,10 +10,9 @@ import Router from "@koa/router";
import cors from "@koa/cors"; import cors from "@koa/cors";
import mount from "koa-mount"; import mount from "koa-mount";
import koaLogger from "koa-logger"; import koaLogger from "koa-logger";
import * as slow from "koa-slow";
import { IsNull } from "typeorm"; import { IsNull } from "typeorm";
import { config, envOption } from "@/config.js"; import { config } from "@/config.js";
import Logger from "@/services/logger.js"; import Logger from "@/services/logger.js";
import { Users } from "@/models/index.js"; import { Users } from "@/models/index.js";
import { fetchMeta, stringToAcct } from "backend-rs"; import { fetchMeta, stringToAcct } from "backend-rs";
@ -54,15 +53,6 @@ if (!["production", "test"].includes(process.env.NODE_ENV || "")) {
serverLogger.debug(str); serverLogger.debug(str);
}), }),
); );
// Delay
if (envOption.slow) {
app.use(
slow({
delay: 3000,
}),
);
}
} }
// HSTS // HSTS

View file

@ -2,7 +2,7 @@ import cluster from "node:cluster";
import chalk from "chalk"; import chalk from "chalk";
import { default as convertColor } from "color-convert"; import { default as convertColor } from "color-convert";
import { format as dateFormat } from "date-fns"; import { format as dateFormat } from "date-fns";
import { config, envOption } from "@/config.js"; import { config } from "@/config.js";
import * as SyslogPro from "syslog-pro"; import * as SyslogPro from "syslog-pro";
@ -133,7 +133,6 @@ export default class Logger {
: null; : null;
let log = `${l} ${worker}\t[${domains.join(" ")}]\t${m}`; let log = `${l} ${worker}\t[${domains.join(" ")}]\t${m}`;
if (envOption.withLogTime) log = `${chalk.gray(time)} ${log}`;
console.log(important ? chalk.bold(log) : log); console.log(important ? chalk.bold(log) : log);
@ -212,8 +211,7 @@ export default class Logger {
// Fixed if statement is ignored when logLevel includes debug // Fixed if statement is ignored when logLevel includes debug
if ( if (
config.logLevel?.includes("debug") || config.logLevel?.includes("debug") ||
process.env.NODE_ENV !== "production" || process.env.NODE_ENV !== "production"
envOption.verbose
) { ) {
this.log("debug", message, data, important); this.log("debug", message, data, important);
} }

View file

@ -207,9 +207,6 @@ importers:
koa-send: koa-send:
specifier: 5.0.1 specifier: 5.0.1
version: 5.0.1 version: 5.0.1
koa-slow:
specifier: 2.1.0
version: 2.1.0
megalodon: megalodon:
specifier: workspace:* specifier: workspace:*
version: link:../megalodon version: link:../megalodon
@ -1149,13 +1146,11 @@ packages:
'@biomejs/cli-darwin-arm64@1.8.0': '@biomejs/cli-darwin-arm64@1.8.0':
resolution: {integrity: sha512-dBAYzfIJ1JmWigKlWourT3sJ3I60LZPjqNwwlsyFjiv5AV7vPeWlHVVIImV2BpINwNjZQhpXnwDfVnGS4vr7AA==} resolution: {integrity: sha512-dBAYzfIJ1JmWigKlWourT3sJ3I60LZPjqNwwlsyFjiv5AV7vPeWlHVVIImV2BpINwNjZQhpXnwDfVnGS4vr7AA==}
engines: {node: '>=14.21.3'} engines: {node: '>=14.21.3'}
cpu: [arm64]
os: [darwin] os: [darwin]
'@biomejs/cli-darwin-x64@1.8.0': '@biomejs/cli-darwin-x64@1.8.0':
resolution: {integrity: sha512-ZTTSD0bP0nn9UpRDGQrQNTILcYSj+IkxTYr3CAV64DWBDtQBomlk2oVKWzDaA1LOhpAsTh0giLCbPJaVk2jfMQ==} resolution: {integrity: sha512-ZTTSD0bP0nn9UpRDGQrQNTILcYSj+IkxTYr3CAV64DWBDtQBomlk2oVKWzDaA1LOhpAsTh0giLCbPJaVk2jfMQ==}
engines: {node: '>=14.21.3'} engines: {node: '>=14.21.3'}
cpu: [x64]
os: [darwin] os: [darwin]
'@biomejs/cli-linux-arm64-musl@1.8.0': '@biomejs/cli-linux-arm64-musl@1.8.0':
@ -1167,7 +1162,6 @@ packages:
'@biomejs/cli-linux-arm64@1.8.0': '@biomejs/cli-linux-arm64@1.8.0':
resolution: {integrity: sha512-cx725jTlJS6dskvJJwwCQaaMRBKE2Qss7ukzmx27Rn/DXRxz6tnnBix4FUGPf1uZfwrERkiJlbWM05JWzpvvXg==} resolution: {integrity: sha512-cx725jTlJS6dskvJJwwCQaaMRBKE2Qss7ukzmx27Rn/DXRxz6tnnBix4FUGPf1uZfwrERkiJlbWM05JWzpvvXg==}
engines: {node: '>=14.21.3'} engines: {node: '>=14.21.3'}
cpu: [arm64]
os: [linux] os: [linux]
'@biomejs/cli-linux-x64-musl@1.8.0': '@biomejs/cli-linux-x64-musl@1.8.0':
@ -1179,7 +1173,6 @@ packages:
'@biomejs/cli-linux-x64@1.8.0': '@biomejs/cli-linux-x64@1.8.0':
resolution: {integrity: sha512-cmgmhlD4QUxMhL1VdaNqnB81xBHb3R7huVNyYnPYzP+AykZ7XqJbPd1KcWAszNjUk2AHdx0aLKEBwCOWemxb2g==} resolution: {integrity: sha512-cmgmhlD4QUxMhL1VdaNqnB81xBHb3R7huVNyYnPYzP+AykZ7XqJbPd1KcWAszNjUk2AHdx0aLKEBwCOWemxb2g==}
engines: {node: '>=14.21.3'} engines: {node: '>=14.21.3'}
cpu: [x64]
os: [linux] os: [linux]
'@biomejs/cli-win32-arm64@1.8.0': '@biomejs/cli-win32-arm64@1.8.0':
@ -5620,10 +5613,6 @@ packages:
resolution: {integrity: sha512-tmcyQ/wXXuxpDxyNXv5yNNkdAMdFRqwtegBXUaowiQzUKqJehttS0x2j0eOZDQAyloAth5w6wwBImnFzkUz3pQ==} resolution: {integrity: sha512-tmcyQ/wXXuxpDxyNXv5yNNkdAMdFRqwtegBXUaowiQzUKqJehttS0x2j0eOZDQAyloAth5w6wwBImnFzkUz3pQ==}
engines: {node: '>= 8'} engines: {node: '>= 8'}
koa-slow@2.1.0:
resolution: {integrity: sha512-ii6s1zuZ51p+SY7WIrwjRi1tmPrNpeHEaw5UYi4h1QzAPmIcNk16e9zwKd9+eNNzI9n+Q2LXHAvt1MCfs7j/8w==}
engines: {iojs: '>= 1.0.0', node: '>= 0.12.0'}
koa-static@5.0.0: koa-static@5.0.0:
resolution: {integrity: sha512-UqyYyH5YEXaJrf9S8E23GoJFQZXkBVJ9zYYMPGz919MSX1KuvAcycIuS0ci150HCoPf4XQVhQ84Qf8xRPWxFaQ==} resolution: {integrity: sha512-UqyYyH5YEXaJrf9S8E23GoJFQZXkBVJ9zYYMPGz919MSX1KuvAcycIuS0ci150HCoPf4XQVhQ84Qf8xRPWxFaQ==}
engines: {node: '>= 7.6.0'} engines: {node: '>= 7.6.0'}
@ -5721,9 +5710,6 @@ packages:
lodash.isequal@4.5.0: lodash.isequal@4.5.0:
resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==} resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==}
lodash.isregexp@3.0.5:
resolution: {integrity: sha512-VlV0abdYZs5asSYW1JW5W1f6gxf2SGQt90rzQp7UNTQ8KwcB3CprZe5crN1LIlCA/fB5R9xecrZijGSELJL8Yg==}
lodash.map@4.6.0: lodash.map@4.6.0:
resolution: {integrity: sha512-worNHGKLDetmcEYDvh2stPCrrQRkP20E4l0iIS7F8EvzMqBBi7ltvFN5m1HvTf1P7Jk1txKhvFcmYsCr8O2F1Q==} resolution: {integrity: sha512-worNHGKLDetmcEYDvh2stPCrrQRkP20E4l0iIS7F8EvzMqBBi7ltvFN5m1HvTf1P7Jk1txKhvFcmYsCr8O2F1Q==}
@ -6621,10 +6607,6 @@ packages:
resolution: {integrity: sha512-P8aonTNAnXWJn2pBIqyeWw0I/D4YDOfEavCVvbDG+wx3dCujQX0ENZiW5OcHfbd8HKLfVhCf4F/3Xivf1yWDiA==} resolution: {integrity: sha512-P8aonTNAnXWJn2pBIqyeWw0I/D4YDOfEavCVvbDG+wx3dCujQX0ENZiW5OcHfbd8HKLfVhCf4F/3Xivf1yWDiA==}
engines: {node: '>=14.19.0'} engines: {node: '>=14.19.0'}
q@1.4.1:
resolution: {integrity: sha512-/CdEdaw49VZVmyIDGUQKDDT53c7qBkO6g5CefWz91Ae+l4+cRtcDYwMTXh6me4O8TMldeGHG3N2Bl84V78Ywbg==}
engines: {node: '>=0.6.0', teleport: '>=0.2.0'}
qrcode-generator@1.4.4: qrcode-generator@1.4.4:
resolution: {integrity: sha512-HM7yY8O2ilqhmULxGMpcHSF1EhJJ9yBj8gvDEuZ6M+KGJ0YY2hKpnXvRD+hZPLrDVck3ExIGhmPtSdcjC+guuw==} resolution: {integrity: sha512-HM7yY8O2ilqhmULxGMpcHSF1EhJJ9yBj8gvDEuZ6M+KGJ0YY2hKpnXvRD+hZPLrDVck3ExIGhmPtSdcjC+guuw==}
@ -13609,11 +13591,6 @@ snapshots:
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
koa-slow@2.1.0:
dependencies:
lodash.isregexp: 3.0.5
q: 1.4.1
koa-static@5.0.0: koa-static@5.0.0:
dependencies: dependencies:
debug: 3.2.7 debug: 3.2.7
@ -13802,8 +13779,6 @@ snapshots:
lodash.isequal@4.5.0: {} lodash.isequal@4.5.0: {}
lodash.isregexp@3.0.5: {}
lodash.map@4.6.0: {} lodash.map@4.6.0: {}
lodash.memoize@4.1.2: {} lodash.memoize@4.1.2: {}
@ -14699,8 +14674,6 @@ snapshots:
opentype.js: 0.4.11 opentype.js: 0.4.11
pngjs: 7.0.0 pngjs: 7.0.0
q@1.4.1: {}
qrcode-generator@1.4.4: {} qrcode-generator@1.4.4: {}
qrcode-vue3@1.6.8: qrcode-vue3@1.6.8: