@aopslabs/aops-server 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/THIRD_PARTY_NOTICES +11 -11
- package/cockpit/.vite/manifest.json +122 -122
- package/cockpit/community.module-inventory.json +176 -177
- package/package.json +2 -1
- package/scripts/container-start.mjs +106 -0
- package/npm-shrinkwrap.json +0 -5069
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
|
|
5
|
+
import { applyCommunityStrictPgSchema } from "@aopslabs/aops-pg-bootstrap";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
resolveCommunityHostOptionsFromEnvironment,
|
|
9
|
+
runCommunityHost,
|
|
10
|
+
} from "./community-host.mjs";
|
|
11
|
+
|
|
12
|
+
function nonEmpty(value) {
|
|
13
|
+
return typeof value === "string" ? value.trim() : "";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function port(value, fallback, label) {
|
|
17
|
+
const candidate = nonEmpty(value) || String(fallback);
|
|
18
|
+
if (!/^[1-9]\d{0,4}$/.test(candidate) || Number(candidate) > 65535) {
|
|
19
|
+
throw new Error(`aops_container_${label}_port_invalid`);
|
|
20
|
+
}
|
|
21
|
+
return candidate;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function normalizeContainerPostgresUrl(value, tlsPolicy = "require") {
|
|
25
|
+
const candidate = nonEmpty(value);
|
|
26
|
+
let parsed;
|
|
27
|
+
try {
|
|
28
|
+
parsed = new URL(candidate);
|
|
29
|
+
} catch {
|
|
30
|
+
throw new Error("aops_container_postgresql_url_required");
|
|
31
|
+
}
|
|
32
|
+
if (
|
|
33
|
+
(parsed.protocol !== "postgres:" && parsed.protocol !== "postgresql:") ||
|
|
34
|
+
!parsed.hostname || !parsed.username || !parsed.password || !parsed.pathname.slice(1) ||
|
|
35
|
+
parsed.search || parsed.hash
|
|
36
|
+
) {
|
|
37
|
+
throw new Error("aops_container_postgresql_url_invalid");
|
|
38
|
+
}
|
|
39
|
+
const tls = nonEmpty(tlsPolicy).toLowerCase() || "require";
|
|
40
|
+
if (tls === "disable") parsed.searchParams.set("sslmode", "disable");
|
|
41
|
+
else if (tls === "require") {
|
|
42
|
+
parsed.searchParams.set("sslmode", "require");
|
|
43
|
+
parsed.searchParams.set("uselibpqcompat", "true");
|
|
44
|
+
} else if (tls === "verify-full") parsed.searchParams.set("sslmode", "verify-full");
|
|
45
|
+
else throw new Error("aops_container_postgresql_tls_invalid");
|
|
46
|
+
return parsed.toString();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function migrationInputs() {
|
|
50
|
+
const packageRoot = path.resolve(import.meta.dirname, "..");
|
|
51
|
+
const packagePolicy = path.join(import.meta.dirname, "community-migration-policy-package-v1.json");
|
|
52
|
+
const sourcePolicy = path.join(import.meta.dirname, "community-migration-policy-v1.json");
|
|
53
|
+
const packaged = existsSync(packagePolicy);
|
|
54
|
+
const policyPath = packaged ? packagePolicy : sourcePolicy;
|
|
55
|
+
return {
|
|
56
|
+
policy: JSON.parse(readFileSync(policyPath, "utf8")),
|
|
57
|
+
workspaceRoot: packaged ? packageRoot : path.resolve(packageRoot, "../.."),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function resolveContainerRuntimeEnvironment(env = process.env) {
|
|
62
|
+
const internalPort = port(env.AOPS_PORT, 5900, "internal");
|
|
63
|
+
if (internalPort !== "5900") throw new Error("aops_container_internal_port_required:5900");
|
|
64
|
+
const publicPort = port(env.AOPS_PUBLIC_PORT, 5900, "public");
|
|
65
|
+
const configuredAuth = nonEmpty(env.AOPS_AUTH_PROVIDER).toLowerCase() || "trusted-local";
|
|
66
|
+
if (configuredAuth !== "trusted-local") throw new Error("aops_container_trusted_local_required");
|
|
67
|
+
return {
|
|
68
|
+
...env,
|
|
69
|
+
NODE_ENV: "production",
|
|
70
|
+
AOPS_PG_URL: normalizeContainerPostgresUrl(env.AOPS_PG_URL, env.AOPS_POSTGRES_TLS),
|
|
71
|
+
AOPS_DB_BOOTSTRAP_MODE: "explicit",
|
|
72
|
+
AOPS_AUTH_PROVIDER: "trusted-local",
|
|
73
|
+
AOPS_SERVER_EXPOSURE: "container",
|
|
74
|
+
COMMUNITY_PORT: internalPort,
|
|
75
|
+
AOPS_COMMUNITY_PUBLIC_PORT: publicPort,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function runContainerServer(
|
|
80
|
+
env = process.env,
|
|
81
|
+
dependencies = {},
|
|
82
|
+
) {
|
|
83
|
+
const runtimeEnv = resolveContainerRuntimeEnvironment(env);
|
|
84
|
+
const hostEnv = env === process.env ? Object.assign(process.env, runtimeEnv) : runtimeEnv;
|
|
85
|
+
const migration = migrationInputs();
|
|
86
|
+
const logs = [];
|
|
87
|
+
const receipt = await (dependencies.migrate ?? applyCommunityStrictPgSchema)({
|
|
88
|
+
repoUrl: runtimeEnv.AOPS_PG_URL,
|
|
89
|
+
workspaceRoot: migration.workspaceRoot,
|
|
90
|
+
policy: migration.policy,
|
|
91
|
+
logs,
|
|
92
|
+
});
|
|
93
|
+
process.stderr.write(
|
|
94
|
+
`[aops-container] PostgreSQL ${receipt.migrationPlan.action}; pending=${receipt.migrationPlan.pendingMigrations.length}\n`,
|
|
95
|
+
);
|
|
96
|
+
const host = dependencies.host ?? runCommunityHost;
|
|
97
|
+
return host(resolveCommunityHostOptionsFromEnvironment(hostEnv), hostEnv);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const isMain = typeof process.argv[1] === "string" && import.meta.url === pathToFileURL(process.argv[1]).href;
|
|
101
|
+
if (isMain) {
|
|
102
|
+
runContainerServer().catch((error) => {
|
|
103
|
+
process.stderr.write(`[aops-container] ${error instanceof Error ? error.message : String(error)}\n`);
|
|
104
|
+
process.exitCode = 1;
|
|
105
|
+
});
|
|
106
|
+
}
|