forked from directus/directus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.cjs
More file actions
45 lines (36 loc) · 1.32 KB
/
Copy pathdocker-entrypoint.cjs
File metadata and controls
45 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env node
'use strict';
/**
* Container entrypoint for the hardened (distroless) runtime image.
*
* The hardened base image ships no shell, so the previous shell-form CMD
* (`node cli.js bootstrap && pm2-runtime start ecosystem.config.cjs`) can no
* longer run. This launcher reproduces that two-step boot in pure Node:
*
* 1. `directus bootstrap` - idempotent DB install/migrate + ensure admin.
* 2. Hand off to pm2-runtime as the long-lived process supervisor.
*
* pm2 is copied into /directus/pm2 from the build stage (see Dockerfile), so we
* invoke its bin directly rather than relying on a global shim on PATH.
*/
const { spawnSync, spawn } = require('node:child_process');
const node = process.execPath;
const bootstrap = spawnSync(node, ['cli.js', 'bootstrap'], { stdio: 'inherit' });
if (bootstrap.status !== 0) {
process.exit(bootstrap.status ?? 1);
}
const pm2 = spawn(node, ['pm2/bin/pm2-runtime', 'start', 'ecosystem.config.cjs'], { stdio: 'inherit' });
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGQUIT']) {
process.on(signal, () => pm2.kill(signal));
}
pm2.on('exit', (code, signal) => {
if (signal) {
process.kill(process.pid, signal);
} else {
process.exit(code ?? 0);
}
});
pm2.on('error', (err) => {
console.error('Failed to start pm2-runtime:', err);
process.exit(1);
});