Check the postgres string first

Fixes #2092
This commit is contained in:
Owen
2025-12-16 10:42:32 -05:00
parent 1b4884afd8
commit 7f7f6eeaea
2 changed files with 27 additions and 25 deletions

View File

@@ -43,23 +43,25 @@ RUN test -f dist/server.mjs
RUN npm run build:cli RUN npm run build:cli
# Prune dev dependencies and clean up to prepare for copy to runner
RUN npm prune --omit=dev && npm cache clean --force
FROM node:24-alpine AS runner FROM node:24-alpine AS runner
WORKDIR /app WORKDIR /app
# Curl used for the health checks # Only curl and tzdata needed at runtime - no build tools!
# Python and build tools needed for better-sqlite3 native compilation RUN apk add --no-cache curl tzdata
RUN apk add --no-cache curl tzdata python3 make g++
# COPY package.json package-lock.json ./ # Copy pre-built node_modules from builder (already pruned to production only)
COPY package*.json ./ # This includes the compiled native modules like better-sqlite3
COPY --from=builder /app/node_modules ./node_modules
RUN npm ci --omit=dev && npm cache clean --force
COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/dist ./dist COPY --from=builder /app/dist ./dist
COPY --from=builder /app/init ./dist/init COPY --from=builder /app/init ./dist/init
COPY --from=builder /app/package.json ./package.json
COPY ./cli/wrapper.sh /usr/local/bin/pangctl COPY ./cli/wrapper.sh /usr/local/bin/pangctl
RUN chmod +x /usr/local/bin/pangctl ./dist/cli.mjs RUN chmod +x /usr/local/bin/pangctl ./dist/cli.mjs

View File

@@ -6,28 +6,28 @@ import { withReplicas } from "drizzle-orm/pg-core";
function createDb() { function createDb() {
const config = readConfigFile(); const config = readConfigFile();
if (!config.postgres) { // check the environment variables for postgres config first before the config file
// check the environment variables for postgres config if (process.env.POSTGRES_CONNECTION_STRING) {
if (process.env.POSTGRES_CONNECTION_STRING) { config.postgres = {
config.postgres = { connection_string: process.env.POSTGRES_CONNECTION_STRING
connection_string: process.env.POSTGRES_CONNECTION_STRING };
}; if (process.env.POSTGRES_REPLICA_CONNECTION_STRINGS) {
if (process.env.POSTGRES_REPLICA_CONNECTION_STRINGS) { const replicas =
const replicas = process.env.POSTGRES_REPLICA_CONNECTION_STRINGS.split(",").map(
process.env.POSTGRES_REPLICA_CONNECTION_STRINGS.split( (conn) => ({
","
).map((conn) => ({
connection_string: conn.trim() connection_string: conn.trim()
})); })
config.postgres.replicas = replicas; );
} config.postgres.replicas = replicas;
} else {
throw new Error(
"Postgres configuration is missing in the configuration file."
);
} }
} }
if (!config.postgres) {
throw new Error(
"Postgres configuration is missing in the configuration file."
);
}
const connectionString = config.postgres?.connection_string; const connectionString = config.postgres?.connection_string;
const replicaConnections = config.postgres?.replicas || []; const replicaConnections = config.postgres?.replicas || [];