pull/2738/head
Louis Lam 2 years ago
parent 5e976afb27
commit a4de93f976

@ -48,7 +48,10 @@ CMD ["node", "server/server.js"]
############################################ ############################################
FROM release-slim AS release FROM release-slim AS release
RUN apt update && \ 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 --yes --no-install-recommends install mariadb-server && \
apt remove curl && \
rm -rf /var/lib/apt/lists/* && \ rm -rf /var/lib/apt/lists/* && \
apt --yes autoremove apt --yes autoremove

@ -4,6 +4,7 @@ const { setSetting, setting } = require("./util-server");
const { log, sleep } = require("../src/util"); const { log, sleep } = require("../src/util");
const dayjs = require("dayjs"); const dayjs = require("dayjs");
const knex = require("knex"); const knex = require("knex");
const path = require("path");
/** /**
* Database & App Data Folder * Database & App Data Folder
@ -109,24 +110,53 @@ class Database {
static async connect(testMode = false, autoloadModels = true, noLog = false) { static async connect(testMode = false, autoloadModels = true, noLog = false) {
const acquireConnectionTimeout = 120 * 1000; const acquireConnectionTimeout = 120 * 1000;
const Dialect = require("knex/lib/dialects/sqlite3/index.js"); let dbConfig;
Dialect.prototype._driver = () => require("@louislam/sqlite3");
try {
const knexInstance = knex({ dbConfig = fs.readFileSync(path.join(Database.dataDir, "db-config.json"));
client: Dialect, } catch (_) {
connection: { dbConfig = {
filename: Database.path, type: "sqlite",
acquireConnectionTimeout: acquireConnectionTimeout, };
}, }
useNullAsDefault: true,
pool: { let config = {};
min: 1,
max: 1, if (dbConfig.type === "sqlite") {
idleTimeoutMillis: 120 * 1000, const Dialect = require("knex/lib/dialects/sqlite3/index.js");
propagateCreateError: false, Dialect.prototype._driver = () => require("@louislam/sqlite3");
acquireTimeoutMillis: acquireConnectionTimeout,
} 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); R.setup(knexInstance);

@ -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;
}
}
}
Loading…
Cancel
Save