mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
39d2196a14
PostgreSQL 19 was released on 19.11.2026, and TREK refused it at boot as newer than the 14 to 18 it supported (discussion #3214). It now supports 14 to 19. The image installs the version 19 client tools from PGDG's main component, since the per-major component can trail a new release; a client handles every server up to its own major, so pg_dump, pg_restore and psql 19 back up and restore every supported server. The tools are looked for in the 19 directory first. Installs that pointed TREK_DB_PG_BIN_DIR at the old /usr/lib/postgresql/18/bin keep working: the image keeps that path as a link to the 19 tools. CI runs the Postgres lane on 14 and 19 instead of 14 and 18, so the job count stays the same, and the Docker job boots on 19. The list of server functions and roles that reach the host was checked against the release notes; PostgreSQL 19 adds none. The compose example stays on 18, because an existing database stays on the major it was created with.
124 lines
6.2 KiB
TypeScript
124 lines
6.2 KiB
TypeScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { describe, it, expect } from 'vitest';
|
|
|
|
// Container management UIs let you edit a running container's command, and they
|
|
// do it by rendering Config.Cmd back into a text field and re-splitting it with a
|
|
// quote-aware tokenizer on submit. Embedded quotes never survive that round-trip:
|
|
// an inline `sh -c "… echo 'FATAL: …' …"` comes back truncated and the container
|
|
// dies with a shell syntax error before Node starts (#2374). The image therefore
|
|
// keeps its start-up logic in server/scripts/entrypoint.sh and every ENTRYPOINT
|
|
// and CMD element is a single bare token. Pin that shape so it cannot drift back.
|
|
const repoRoot = path.resolve(__dirname, '../../..');
|
|
|
|
const dockerfile = fs.readFileSync(path.join(repoRoot, 'Dockerfile'), 'utf8');
|
|
const entrypointPath = path.join(repoRoot, 'server', 'scripts', 'entrypoint.sh');
|
|
|
|
// Anchored at column 0 and requiring the JSON exec form, so the HEALTHCHECK's
|
|
// indented shell-form `CMD wget -qO- … || exit 1` is not picked up.
|
|
const readExecForms = (): string[][] =>
|
|
[...dockerfile.matchAll(/^(?:ENTRYPOINT|CMD)[ \t]+(\[[^\n]*\])$/gm)].map((m) => JSON.parse(m[1]));
|
|
|
|
describe('container start-up shape', () => {
|
|
const execForms = readExecForms();
|
|
|
|
it('finds both exec-form lines (guards against matching nothing or the healthcheck)', () => {
|
|
expect(execForms).toHaveLength(2);
|
|
});
|
|
|
|
it('keeps every ENTRYPOINT and CMD element a single token free of quotes and spaces', () => {
|
|
for (const argv of execForms) {
|
|
expect(argv.length).toBeGreaterThan(0);
|
|
for (const element of argv) expect(element).toMatch(/^[^\s'"]+$/);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('entrypoint script', () => {
|
|
const source = fs.readFileSync(entrypointPath, 'utf8');
|
|
|
|
it('exists and is copied into the image by the Dockerfile', () => {
|
|
expect(fs.existsSync(entrypointPath)).toBe(true);
|
|
expect(dockerfile).toContain('COPY server/scripts/entrypoint.sh /usr/local/bin/trek-entrypoint');
|
|
});
|
|
|
|
it('has LF line endings (a CRLF shebang kills the container with "no such file or directory")', () => {
|
|
expect(source).not.toContain('\r');
|
|
});
|
|
|
|
it('keeps the volume-over-/app preflight wording the wiki quotes', () => {
|
|
expect(source).toContain('FATAL: TREK application files are missing from the image.');
|
|
});
|
|
|
|
// A blanket `chown -R` over the volumes rewrote every inode on every start; on a
|
|
// large or network-backed PVC the container sat there for minutes without a log
|
|
// line, which looked like gosu hanging (#2918).
|
|
// Only the commands count; the comments are free to talk about the old chown.
|
|
const code = source
|
|
.split('\n')
|
|
.filter((line) => !line.trimStart().startsWith('#'))
|
|
.join('\n');
|
|
|
|
it('never walks the volumes on a start where they already belong to node', () => {
|
|
// Only the dir and its direct entries are looked at, never the whole tree.
|
|
expect(code).toContain('find "$dir" -maxdepth 1 \\( ! -user node -o -group 0 \\) -print -quit');
|
|
expect(code).not.toMatch(/find "\$dir" \\\(/);
|
|
// The recursive hand-over sits behind that check and behind a chown of the dir that worked.
|
|
const check = code.indexOf('-maxdepth 1');
|
|
const dirChown = code.indexOf('if chown node "$dir"');
|
|
expect(dirChown).toBeGreaterThan(check);
|
|
expect(code.indexOf('chown -R')).toBeGreaterThan(dirChown);
|
|
expect(code.indexOf('find "$dir" -group 0 -exec chgrp -h node {} +')).toBeGreaterThan(code.indexOf('chown -R'));
|
|
expect(code).toContain('Correcting ownership of $dir for the node user...');
|
|
});
|
|
|
|
// A Kubernetes fsGroup other than 1000 gives every file that gid. Handing the
|
|
// group back to node would leave the kubelet's OnRootMismatch with a mismatched
|
|
// root on the next start, and the two recursive walks would undo each other on
|
|
// every start (#2918 again). So only the user is taken over, plus a root group.
|
|
it('takes over the owning user and a root group, never a foreign fsGroup', () => {
|
|
expect(code).not.toContain('-group node');
|
|
expect(code).not.toContain('node:node');
|
|
expect(code).toContain('chown -R -h node "$dir"');
|
|
});
|
|
|
|
it('says so once instead of walking a volume that refuses chown', () => {
|
|
expect(code).toContain('cannot be handed to the node user (chown refused); run the container as uid 1000 instead.');
|
|
});
|
|
|
|
// Under runAsUser: 1000 there is no privilege to drop and gosu cannot switch
|
|
// users, so the non-root branch has to exec Node itself before any chown or privilege drop.
|
|
it('starts Node directly, without chown or a privilege drop, when not running as root', () => {
|
|
const nonRootCheck = code.indexOf('if [ "$(id -u)" != "0" ]; then');
|
|
expect(nonRootCheck).toBeGreaterThan(-1);
|
|
const branchEnd = code.indexOf('\nfi\n', nonRootCheck);
|
|
expect(branchEnd).toBeGreaterThan(nonRootCheck);
|
|
const branch = code.slice(nonRootCheck, branchEnd);
|
|
expect(branch).toContain('exec node --require tsconfig-paths/register dist/index.js');
|
|
expect(branch).not.toContain('setpriv');
|
|
expect(code.indexOf('chown')).toBeGreaterThan(branchEnd);
|
|
expect(code.indexOf('setpriv')).toBeGreaterThan(branchEnd);
|
|
});
|
|
|
|
// gosu is Go: it changes the ids by signalling every runtime thread and spinning until
|
|
// each answers, so a host that drops that signal hung it at full CPU (#3135).
|
|
it('drops to node through setpriv, not gosu, when started as root', () => {
|
|
expect(source).toContain(
|
|
'exec setpriv --reuid=node --regid=node --init-groups -- node --require tsconfig-paths/register dist/index.js',
|
|
);
|
|
expect(source).toContain('export HOME=/home/node');
|
|
expect(source).not.toMatch(/^\s*exec gosu/m);
|
|
});
|
|
});
|
|
|
|
// Earlier images carried the version 18 client tools, and the old .env.example
|
|
// suggested TREK_DB_PG_BIN_DIR=/usr/lib/postgresql/18/bin. resolvePgTool looks
|
|
// only in a configured directory, so without the link such an install loses its
|
|
// backups and the mandatory pre-migrate snapshot after updating the image.
|
|
describe('postgres client tools in the image', () => {
|
|
it('installs the version 19 client and keeps the version 18 directory as a link to it', () => {
|
|
expect(dockerfile).toMatch(/\bpostgresql-client-19\b/);
|
|
expect(dockerfile).toContain('ln -s /usr/lib/postgresql/19/bin /usr/lib/postgresql/18/bin');
|
|
});
|
|
});
|