Enhance environment variable handling and Dockerfile configuration
- Introduced a utility function to preprocess environment variables, converting empty strings, undefined, or null values to undefined for better validation in EnvSchema. - Updated Dockerfile to set PORT and HOSTNAME environment variables for improved container configuration. - Revised PHASE-TRACKING.md to include automated deployment verification steps, ensuring a smoother deployment process.
This commit is contained in:
@@ -3,11 +3,14 @@ import { z } from 'zod';
|
||||
|
||||
config();
|
||||
|
||||
const emptyToUndefined = (value: unknown) =>
|
||||
value === '' || value === undefined || value === null ? undefined : value;
|
||||
|
||||
const EnvSchema = z.object({
|
||||
NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),
|
||||
BOT_TOKEN: z.string().min(1),
|
||||
BOT_CLIENT_ID: z.string().min(1),
|
||||
BOT_GUILD_ID: z.string().min(1).optional(),
|
||||
BOT_GUILD_ID: z.preprocess(emptyToUndefined, z.string().min(1).optional()),
|
||||
DATABASE_URL: z.string().url(),
|
||||
REDIS_URL: z.string().url(),
|
||||
LOG_LEVEL: z.string().default('info'),
|
||||
@@ -15,11 +18,11 @@ const EnvSchema = z.object({
|
||||
BACKUP_RETENTION_DAYS: z.coerce.number().int().positive().default(14),
|
||||
BACKUP_CRON: z.string().default('0 3 * * *'),
|
||||
BACKUP_DIR: z.string().default('/backups'),
|
||||
METRICS_TOKEN: z.string().optional(),
|
||||
METRICS_TOKEN: z.preprocess(emptyToUndefined, z.string().min(1).optional()),
|
||||
HEALTH_PORT: z.coerce.number().int().positive().default(8080),
|
||||
PUBLIC_BASE_URL: z.string().url().default('http://localhost:8080'),
|
||||
TWITCH_CLIENT_ID: z.string().min(1).optional(),
|
||||
TWITCH_CLIENT_SECRET: z.string().min(1).optional()
|
||||
TWITCH_CLIENT_ID: z.preprocess(emptyToUndefined, z.string().min(1).optional()),
|
||||
TWITCH_CLIENT_SECRET: z.preprocess(emptyToUndefined, z.string().min(1).optional())
|
||||
});
|
||||
|
||||
export const env = EnvSchema.parse(process.env);
|
||||
|
||||
@@ -40,6 +40,8 @@ RUN pnpm --filter @nexumi/webui build
|
||||
|
||||
FROM base AS runner
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME=0.0.0.0
|
||||
COPY --from=build /app/apps/webui/.next/standalone ./
|
||||
COPY --from=build /app/apps/webui/.next/static ./apps/webui/.next/static
|
||||
COPY --from=build /app/apps/webui/public ./apps/webui/public
|
||||
|
||||
Reference in New Issue
Block a user