pull/2738/head
Louis Lam 2022-12-23 22:43:56 +08:00
parent 5e976afb27
commit a4de93f976
4 changed files with 101 additions and 17 deletions

View File

@ -48,7 +48,10 @@ CMD ["node", "server/server.js"]
############################################
FROM release-slim AS release
RUN apt update && \
apt --yes --no-install-recommends install curl && \
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash -s -- --mariadb-server-version="mariadb-10.11" && \
apt --yes --no-install-recommends install mariadb-server && \
apt remove curl && \
rm -rf /var/lib/apt/lists/* && \
apt --yes autoremove

0
docker/my.cnf Normal file
View File

View File

@ -4,6 +4,7 @@ const { setSetting, setting } = require("./util-server");
const { log, sleep } = require("../src/util");
const dayjs = require("dayjs");
const knex = require("knex");
const path = require("path");
/**
* Database & App Data Folder
@ -109,24 +110,53 @@ class Database {
static async connect(testMode = false, autoloadModels = true, noLog = false) {
const acquireConnectionTimeout = 120 * 1000;
const Dialect = require("knex/lib/dialects/sqlite3/index.js");
Dialect.prototype._driver = () => require("@louislam/sqlite3");
let dbConfig;
const knexInstance = knex({
client: Dialect,
connection: {
filename: Database.path,
acquireConnectionTimeout: acquireConnectionTimeout,
},
useNullAsDefault: true,
pool: {
min: 1,
max: 1,
idleTimeoutMillis: 120 * 1000,
propagateCreateError: false,
acquireTimeoutMillis: acquireConnectionTimeout,
}
});
try {
dbConfig = fs.readFileSync(path.join(Database.dataDir, "db-config.json"));
} catch (_) {
dbConfig = {
type: "sqlite",
};
}
let config = {};
if (dbConfig.type === "sqlite") {
const Dialect = require("knex/lib/dialects/sqlite3/index.js");
Dialect.prototype._driver = () => require("@louislam/sqlite3");
config = {
client: Dialect,
connection: {
filename: Database.path,
acquireConnectionTimeout: acquireConnectionTimeout,
},
useNullAsDefault: true,
pool: {
min: 1,
max: 1,
idleTimeoutMillis: 120 * 1000,
propagateCreateError: false,
acquireTimeoutMillis: acquireConnectionTimeout,
}
};
} else if (dbConfig === "embedded-mariadb") {
config = {
client: "mysql",
connection: {
host: "127.0.0.1",
port: 3306,
user: "your_database_user",
password: "your_database_password",
database: "kuma"
}
};
} else {
throw new Error("Unknown Database type");
}
const knexInstance = knex(config);
R.setup(knexInstance);

View File

@ -0,0 +1,51 @@
const { log } = require("../src/util");
const childProcess = require("child_process");
class EmbeddedMariaDB {
static childProcess = null;
static running = false;
static init() {
}
static start() {
if (this.childProcess) {
log.log("mariadb", "Already started");
return;
}
this.running = true;
this.emitChange("Starting cloudflared");
this.childProcess = childProcess.spawn(this.cloudflaredPath, args);
this.childProcess.stdout.pipe(process.stdout);
this.childProcess.stderr.pipe(process.stderr);
this.childProcess.on("close", (code) => {
this.running = false;
this.childProcess = null;
this.emitChange("Stopped cloudflared", code);
});
this.childProcess.on("error", (err) => {
if (err.code === "ENOENT") {
this.emitError(`Cloudflared error: ${this.cloudflaredPath} is not found`);
} else {
this.emitError(err);
}
});
this.childProcess.stderr.on("data", (data) => {
this.emitError(data.toString());
});
}
static stop() {
if (this.childProcess) {
this.childProcess.kill("SIGINT");
this.childProcess = null;
}
}
}