mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
fix(deploy): follow PORT in every probe, wait for a slow boot, and probe the database
Changing PORT left the Dockerfile and compose healthchecks, the chart's containerPort, Service target and probes on 3000, so the container went unhealthy and Kubernetes restarted it in a loop. All of them follow PORT now. The chart gains a startup probe (ten minutes for a first boot, a long migration or a restore at boot, which liveness used to kill after about 105 s), a readiness probe on the new /api/health/ready that asks the database, extraEnv and extraEnvFrom for the settings the chart does not list, slots for the four secrets it had none for, and the DEFAULT_LANGUAGE and MCP_MAX_SESSION_PER_USER values it documented but never set. The Dockerfile no longer hides a failed npm ci behind a ';', pins gosu, and the language lists name all 27 locales.
This commit is contained in:
@@ -39,6 +39,12 @@ export class MaintenanceRepository {
|
||||
this.em.getContext();
|
||||
}
|
||||
|
||||
/** `SELECT 1`: whether the database answers at all, for the readiness probe. */
|
||||
async ping(): Promise<void> {
|
||||
this.validateRequestContext();
|
||||
await this.em.getConnection().execute('SELECT 1');
|
||||
}
|
||||
|
||||
/**
|
||||
* `PRAGMA wal_checkpoint(TRUNCATE)` — rendered text pinned, identical to
|
||||
* the legacy `db.exec('PRAGMA wal_checkpoint(TRUNCATE)')` it replaces at
|
||||
|
||||
@@ -348,7 +348,7 @@ export function applyGlobalMiddleware(
|
||||
|
||||
if (shouldForceHttps) {
|
||||
app.use((req: Request, res: Response, next: NextFunction) => {
|
||||
if (req.path === '/api/health') return next();
|
||||
if (req.path === '/api/health' || req.path === '/api/health/ready') return next();
|
||||
if (req.secure || req.headers['x-forwarded-proto'] === 'https') return next();
|
||||
res.redirect(301, 'https://' + (configuredHost ?? req.headers.host) + req.url);
|
||||
});
|
||||
@@ -358,7 +358,7 @@ export function applyGlobalMiddleware(
|
||||
|
||||
// Request logging with sensitive field redaction (SENSITIVE_KEYS/redact above)
|
||||
app.use((req: Request, res: Response, next: NextFunction) => {
|
||||
if (req.path === '/api/health') return next();
|
||||
if (req.path === '/api/health' || req.path === '/api/health/ready') return next();
|
||||
const startedAt = Date.now();
|
||||
res.on('finish', () => {
|
||||
const ms = Date.now() - startedAt;
|
||||
|
||||
@@ -114,8 +114,9 @@ export const PUBLIC_ROUTE_ALLOW_LIST: string[] = [
|
||||
// run. It never reads the request body as data.
|
||||
'DocSyncWebhookController.nudge',
|
||||
'FeaturesController.features',
|
||||
// The container/uptime probe.
|
||||
// The container/uptime probe, and the readiness probe beside it.
|
||||
'FeaturesController.health',
|
||||
'FeaturesController.ready',
|
||||
// Subscribable ICS feeds. The token in the path is the credential, and the
|
||||
// calendar client polling it has no TREK session to send.
|
||||
'FeedsPublicController.tripFeed',
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Controller, Get, Res } from '@nestjs/common';
|
||||
import { EntityManager } from '@mikro-orm/core';
|
||||
import type { Response } from 'express';
|
||||
import { MaintenanceRepository } from '../../db/repositories/MaintenanceRepository';
|
||||
import { KitineraryExtractorService } from '../booking-import/kitinerary-extractor.service';
|
||||
import { AddonsService } from '../addons/addons.service';
|
||||
import { ADDON_IDS } from '../../addons';
|
||||
@@ -13,6 +15,7 @@ export class FeaturesController {
|
||||
constructor(
|
||||
private readonly extractor: KitineraryExtractorService,
|
||||
private readonly addons: AddonsService,
|
||||
private readonly em: EntityManager,
|
||||
) {}
|
||||
|
||||
/** The container/uptime probe. The forced-HTTPS redirect and HSTS exempt this
|
||||
@@ -24,6 +27,23 @@ export class FeaturesController {
|
||||
res.json({ status: 'ok' });
|
||||
}
|
||||
|
||||
/**
|
||||
* The readiness probe: 503 while the database does not answer (a restore
|
||||
* swapping it, a boot still migrating), so an orchestrator stops sending
|
||||
* traffic without killing the process. Liveness stays on the plain probe
|
||||
* above, which a long restore must not fail.
|
||||
*/
|
||||
@Get('ready')
|
||||
async ready(@Res() res: Response): Promise<void> {
|
||||
res.setHeader('Cache-Control', 'no-store, must-revalidate');
|
||||
try {
|
||||
await new MaintenanceRepository(this.em).ping();
|
||||
res.json({ status: 'ready' });
|
||||
} catch {
|
||||
res.status(503).json({ status: 'unavailable' });
|
||||
}
|
||||
}
|
||||
|
||||
@Get('features')
|
||||
async features() {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user