diff --git a/.dockerignore b/.dockerignore index 3819d675c8..63666d8b62 100644 --- a/.dockerignore +++ b/.dockerignore @@ -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 diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000000..4130c51076 --- /dev/null +++ b/fly.toml @@ -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 diff --git a/packages/backend/check_connect.js b/packages/backend/check_connect.js index 7c1e716b3e..632092fe98 100644 --- a/packages/backend/check_connect.js +++ b/packages/backend/check_connect.js @@ -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) => { diff --git a/packages/backend/src/db/postgre.ts b/packages/backend/src/db/postgre.ts index 6baccaa271..52536bb59b 100644 --- a/packages/backend/src/db/postgre.ts +++ b/packages/backend/src/db/postgre.ts @@ -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, diff --git a/packages/backend/src/db/redis.ts b/packages/backend/src/db/redis.ts index 215effd8ea..61df87e0e7 100644 --- a/packages/backend/src/db/redis.ts +++ b/packages/backend/src/db/redis.ts @@ -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(); diff --git a/packages/backend/src/ormconfig.ts b/packages/backend/src/ormconfig.ts index a1891e00df..a18828834d 100644 --- a/packages/backend/src/ormconfig.ts +++ b/packages/backend/src/ormconfig.ts @@ -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"], }); diff --git a/packages/backend/src/queue/initialize.ts b/packages/backend/src/queue/initialize.ts index a874005fbd..a83c732032 100644 --- a/packages/backend/src/queue/initialize.ts +++ b/packages/backend/src/queue/initialize.ts @@ -2,16 +2,18 @@ import Bull from "bull"; import config from "@/config/index.js"; export function initialize(name: string, limitPerSec = -1) { - return new Bull(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(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