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
|
coverage
|
||||||
|
|
||||||
# config
|
# config
|
||||||
/.config
|
/.config/LICENSE
|
||||||
|
/.config/*.env
|
||||||
|
/.config/ci.yml
|
||||||
|
/.config/devenv.yml
|
||||||
|
/.config/example.yml
|
||||||
|
/.config/helm_values_example.yml
|
||||||
|
|
||||||
# misskey
|
# misskey
|
||||||
built
|
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";
|
import { createRedisConnection } from "./built/redis.js";
|
||||||
|
|
||||||
const config = loadConfig();
|
const config = loadConfig();
|
||||||
const redis = createRedisConnection(config);
|
const redis = createRedisConnection({
|
||||||
|
...config,
|
||||||
|
});
|
||||||
|
|
||||||
redis.on("connect", () => redis.disconnect());
|
redis.on("connect", () => redis.disconnect());
|
||||||
redis.on("error", (e) => {
|
redis.on("error", (e) => {
|
||||||
|
|
|
@ -189,11 +189,17 @@ const log = process.env.NODE_ENV !== "production";
|
||||||
|
|
||||||
export const db = new DataSource({
|
export const db = new DataSource({
|
||||||
type: "postgres",
|
type: "postgres",
|
||||||
host: config.db.host,
|
...(process.env.DATABASE_URL
|
||||||
port: config.db.port,
|
? {
|
||||||
username: config.db.user,
|
url: process.env.DATABASE_URL,
|
||||||
password: config.db.pass,
|
}
|
||||||
database: config.db.db,
|
: {
|
||||||
|
host: config.db.host,
|
||||||
|
port: config.db.port,
|
||||||
|
username: config.db.user,
|
||||||
|
password: config.db.pass,
|
||||||
|
database: config.db.db,
|
||||||
|
}),
|
||||||
extra: {
|
extra: {
|
||||||
statement_timeout: 1000 * 30,
|
statement_timeout: 1000 * 30,
|
||||||
...config.db.extra,
|
...config.db.extra,
|
||||||
|
@ -203,16 +209,21 @@ export const db = new DataSource({
|
||||||
cache: !config.db.disableCache
|
cache: !config.db.disableCache
|
||||||
? {
|
? {
|
||||||
type: "ioredis",
|
type: "ioredis",
|
||||||
options: {
|
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
|
||||||
host: config.redis.host,
|
options: process.env.REDIS_URL
|
||||||
port: config.redis.port,
|
? {
|
||||||
family: config.redis.family == null ? 0 : config.redis.family,
|
keyPrefix: `${config.redis.prefix}:query:`,
|
||||||
username: config.redis.user ?? "default",
|
}
|
||||||
password: config.redis.pass,
|
: {
|
||||||
keyPrefix: `${config.redis.prefix}:query:`,
|
host: config.redis.host,
|
||||||
db: config.redis.db || 0,
|
port: config.redis.port,
|
||||||
tls: config.redis.tls,
|
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,
|
: false,
|
||||||
logging: log,
|
logging: log,
|
||||||
|
|
|
@ -6,16 +6,18 @@ export function createConnection() {
|
||||||
if (config.cacheServer) {
|
if (config.cacheServer) {
|
||||||
source = config.cacheServer;
|
source = config.cacheServer;
|
||||||
}
|
}
|
||||||
return new Redis({
|
return new Redis(
|
||||||
port: source.port,
|
process.env.REDIS_URL || {
|
||||||
host: source.host,
|
port: source.port,
|
||||||
family: source.family ?? 0,
|
host: source.host,
|
||||||
password: source.pass,
|
family: source.family ?? 0,
|
||||||
username: source.user ?? "default",
|
password: source.pass,
|
||||||
keyPrefix: `${source.prefix}:`,
|
username: source.user ?? "default",
|
||||||
db: source.db || 0,
|
keyPrefix: `${source.prefix}:`,
|
||||||
tls: source.tls,
|
db: source.db || 0,
|
||||||
});
|
tls: source.tls,
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const subscriber = createConnection();
|
export const subscriber = createConnection();
|
||||||
|
|
|
@ -4,12 +4,18 @@ import { entities } from "./db/postgre.js";
|
||||||
|
|
||||||
export default new DataSource({
|
export default new DataSource({
|
||||||
type: "postgres",
|
type: "postgres",
|
||||||
host: config.db.host,
|
...(process.env.DATABASE_URL
|
||||||
port: config.db.port,
|
? {
|
||||||
username: config.db.user,
|
url: process.env.DATABASE_URL,
|
||||||
password: config.db.pass,
|
}
|
||||||
database: config.db.db,
|
: {
|
||||||
extra: config.db.extra,
|
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,
|
entities: entities,
|
||||||
migrations: ["built/migration/*.js"],
|
migrations: ["built/migration/*.js"],
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,16 +2,18 @@ import Bull from "bull";
|
||||||
import config from "@/config/index.js";
|
import config from "@/config/index.js";
|
||||||
|
|
||||||
export function initialize<T>(name: string, limitPerSec = -1) {
|
export function initialize<T>(name: string, limitPerSec = -1) {
|
||||||
return new Bull<T>(name, {
|
return new Bull<T>(name, process.env.REDIS_URL, {
|
||||||
redis: {
|
redis: process.env.REDIS_URL
|
||||||
port: config.redis.port,
|
? undefined
|
||||||
host: config.redis.host,
|
: {
|
||||||
family: config.redis.family == null ? 0 : config.redis.family,
|
port: config.redis.port,
|
||||||
username: config.redis.user ?? "default",
|
host: config.redis.host,
|
||||||
password: config.redis.pass,
|
family: config.redis.family == null ? 0 : config.redis.family,
|
||||||
db: config.redis.db || 0,
|
username: config.redis.user ?? "default",
|
||||||
tls: config.redis.tls,
|
password: config.redis.pass,
|
||||||
},
|
db: config.redis.db || 0,
|
||||||
|
tls: config.redis.tls,
|
||||||
|
},
|
||||||
prefix: config.redis.prefix ? `${config.redis.prefix}:queue` : "queue",
|
prefix: config.redis.prefix ? `${config.redis.prefix}:queue` : "queue",
|
||||||
limiter:
|
limiter:
|
||||||
limitPerSec > 0
|
limitPerSec > 0
|
||||||
|
|
Loading…
Reference in New Issue