Merge branch 'ft/use-env-for-dburls' into 'develop'
Use env config for db Co-authored-by: naskya <m@naskya.net> Co-authored-by: deathg.rip <josh@deathg.rip> See merge request firefish/firefish!10706
This commit is contained in:
commit
ec2f807ae7
|
@ -16,7 +16,12 @@ report.*.json
|
|||
coverage
|
||||
|
||||
# config
|
||||
/.config
|
||||
/.config/LICENSE
|
||||
/.config/*.env
|
||||
/.config/ci.yml
|
||||
/.config/devenv.yml
|
||||
/.config/example.yml
|
||||
/.config/helm_values_example.yml
|
||||
|
||||
# misskey
|
||||
built
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# fly.toml app configuration file generated for infinite-jetzt-firefish on 2024-03-21T21:20:45-04:00
|
||||
#
|
||||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
||||
#
|
||||
|
||||
app = 'example-fly-firefish'
|
||||
primary_region = 'bos'
|
||||
|
||||
[build]
|
||||
|
||||
[http_service]
|
||||
internal_port = 3000
|
||||
force_https = true
|
||||
auto_stop_machines = true
|
||||
auto_start_machines = true
|
||||
min_machines_running = 0
|
||||
processes = ['firefish']
|
||||
|
||||
[[vm]]
|
||||
memory = '1gb'
|
||||
cpu_kind = 'shared'
|
||||
cpus = 1
|
|
@ -2,7 +2,9 @@ import { loadConfig } from "./built/config.js";
|
|||
import { createRedisConnection } from "./built/redis.js";
|
||||
|
||||
const config = loadConfig();
|
||||
const redis = createRedisConnection(config);
|
||||
const redis = createRedisConnection({
|
||||
...config,
|
||||
});
|
||||
|
||||
redis.on("connect", () => redis.disconnect());
|
||||
redis.on("error", (e) => {
|
||||
|
|
|
@ -189,11 +189,17 @@ const log = process.env.NODE_ENV !== "production";
|
|||
|
||||
export const db = new DataSource({
|
||||
type: "postgres",
|
||||
host: config.db.host,
|
||||
port: config.db.port,
|
||||
username: config.db.user,
|
||||
password: config.db.pass,
|
||||
database: config.db.db,
|
||||
...(process.env.DATABASE_URL
|
||||
? {
|
||||
url: process.env.DATABASE_URL,
|
||||
}
|
||||
: {
|
||||
host: config.db.host,
|
||||
port: config.db.port,
|
||||
username: config.db.user,
|
||||
password: config.db.pass,
|
||||
database: config.db.db,
|
||||
}),
|
||||
extra: {
|
||||
statement_timeout: 1000 * 30,
|
||||
...config.db.extra,
|
||||
|
@ -203,16 +209,21 @@ export const db = new DataSource({
|
|||
cache: !config.db.disableCache
|
||||
? {
|
||||
type: "ioredis",
|
||||
options: {
|
||||
host: config.redis.host,
|
||||
port: config.redis.port,
|
||||
family: config.redis.family == null ? 0 : config.redis.family,
|
||||
username: config.redis.user ?? "default",
|
||||
password: config.redis.pass,
|
||||
keyPrefix: `${config.redis.prefix}:query:`,
|
||||
db: config.redis.db || 0,
|
||||
tls: config.redis.tls,
|
||||
},
|
||||
port: process.env.REDIS_URL, // typeorm passes "port" as the first argument to ioredis when using the "ioredis" cache driver so we can use it to pass the redis url
|
||||
options: process.env.REDIS_URL
|
||||
? {
|
||||
keyPrefix: `${config.redis.prefix}:query:`,
|
||||
}
|
||||
: {
|
||||
host: config.redis.host,
|
||||
port: config.redis.port,
|
||||
family: config.redis.family == null ? 0 : config.redis.family,
|
||||
username: config.redis.user ?? "default",
|
||||
password: config.redis.pass,
|
||||
keyPrefix: `${config.redis.prefix}:query:`,
|
||||
db: config.redis.db || 0,
|
||||
tls: config.redis.tls,
|
||||
},
|
||||
}
|
||||
: false,
|
||||
logging: log,
|
||||
|
|
|
@ -6,16 +6,18 @@ export function createConnection() {
|
|||
if (config.cacheServer) {
|
||||
source = config.cacheServer;
|
||||
}
|
||||
return new Redis({
|
||||
port: source.port,
|
||||
host: source.host,
|
||||
family: source.family ?? 0,
|
||||
password: source.pass,
|
||||
username: source.user ?? "default",
|
||||
keyPrefix: `${source.prefix}:`,
|
||||
db: source.db || 0,
|
||||
tls: source.tls,
|
||||
});
|
||||
return new Redis(
|
||||
process.env.REDIS_URL || {
|
||||
port: source.port,
|
||||
host: source.host,
|
||||
family: source.family ?? 0,
|
||||
password: source.pass,
|
||||
username: source.user ?? "default",
|
||||
keyPrefix: `${source.prefix}:`,
|
||||
db: source.db || 0,
|
||||
tls: source.tls,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export const subscriber = createConnection();
|
||||
|
|
|
@ -4,12 +4,18 @@ import { entities } from "./db/postgre.js";
|
|||
|
||||
export default new DataSource({
|
||||
type: "postgres",
|
||||
host: config.db.host,
|
||||
port: config.db.port,
|
||||
username: config.db.user,
|
||||
password: config.db.pass,
|
||||
database: config.db.db,
|
||||
extra: config.db.extra,
|
||||
...(process.env.DATABASE_URL
|
||||
? {
|
||||
url: process.env.DATABASE_URL,
|
||||
}
|
||||
: {
|
||||
host: config.db.host,
|
||||
port: config.db.port,
|
||||
username: config.db.user,
|
||||
password: config.db.pass,
|
||||
database: config.db.db,
|
||||
}),
|
||||
...(config.db && { extra: config.db.extra }),
|
||||
entities: entities,
|
||||
migrations: ["built/migration/*.js"],
|
||||
});
|
||||
|
|
|
@ -2,16 +2,18 @@ import Bull from "bull";
|
|||
import config from "@/config/index.js";
|
||||
|
||||
export function initialize<T>(name: string, limitPerSec = -1) {
|
||||
return new Bull<T>(name, {
|
||||
redis: {
|
||||
port: config.redis.port,
|
||||
host: config.redis.host,
|
||||
family: config.redis.family == null ? 0 : config.redis.family,
|
||||
username: config.redis.user ?? "default",
|
||||
password: config.redis.pass,
|
||||
db: config.redis.db || 0,
|
||||
tls: config.redis.tls,
|
||||
},
|
||||
return new Bull<T>(name, process.env.REDIS_URL, {
|
||||
redis: process.env.REDIS_URL
|
||||
? undefined
|
||||
: {
|
||||
port: config.redis.port,
|
||||
host: config.redis.host,
|
||||
family: config.redis.family == null ? 0 : config.redis.family,
|
||||
username: config.redis.user ?? "default",
|
||||
password: config.redis.pass,
|
||||
db: config.redis.db || 0,
|
||||
tls: config.redis.tls,
|
||||
},
|
||||
prefix: config.redis.prefix ? `${config.redis.prefix}:queue` : "queue",
|
||||
limiter:
|
||||
limitPerSec > 0
|
||||
|
|
Loading…
Reference in New Issue