@cbnventures/nova 0.33.0 → 0.34.1
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/bin/nova.mjs +5 -2
- package/build/package.json +3 -2
- package/build/scaffold-versions.json +21 -14
- package/build/src/api/app-store-connect.d.ts +28 -0
- package/build/src/api/app-store-connect.d.ts.map +1 -0
- package/build/src/api/app-store-connect.js +494 -0
- package/build/src/api/app-store-connect.js.map +1 -0
- package/build/src/api/google-play-console.d.ts +15 -0
- package/build/src/api/google-play-console.d.ts.map +1 -0
- package/build/src/api/google-play-console.js +136 -0
- package/build/src/api/google-play-console.js.map +1 -0
- package/build/src/cli/generate/github/workflows-blueprint-validate.d.ts +4 -2
- package/build/src/cli/generate/github/workflows-blueprint-validate.d.ts.map +1 -1
- package/build/src/cli/generate/github/workflows-blueprint-validate.js +199 -3
- package/build/src/cli/generate/github/workflows-blueprint-validate.js.map +1 -1
- package/build/src/cli/generate/github/workflows-blueprint.d.ts +6 -0
- package/build/src/cli/generate/github/workflows-blueprint.d.ts.map +1 -1
- package/build/src/cli/generate/github/workflows-blueprint.js +458 -59
- package/build/src/cli/generate/github/workflows-blueprint.js.map +1 -1
- package/build/src/cli/index.js +154 -0
- package/build/src/cli/index.js.map +1 -1
- package/build/src/cli/integration/app-store-connect.d.ts +22 -0
- package/build/src/cli/integration/app-store-connect.d.ts.map +1 -0
- package/build/src/cli/integration/app-store-connect.js +502 -0
- package/build/src/cli/integration/app-store-connect.js.map +1 -0
- package/build/src/cli/integration/discord-developer-portal.d.ts +6 -0
- package/build/src/cli/integration/discord-developer-portal.d.ts.map +1 -0
- package/build/src/cli/integration/discord-developer-portal.js +42 -0
- package/build/src/cli/integration/discord-developer-portal.js.map +1 -0
- package/build/src/cli/integration/google-play-console.d.ts +16 -0
- package/build/src/cli/integration/google-play-console.d.ts.map +1 -0
- package/build/src/cli/integration/google-play-console.js +199 -0
- package/build/src/cli/integration/google-play-console.js.map +1 -0
- package/build/src/cli/integration/index.d.ts +8 -0
- package/build/src/cli/integration/index.d.ts.map +1 -0
- package/build/src/cli/integration/index.js +139 -0
- package/build/src/cli/integration/index.js.map +1 -0
- package/build/src/cli/recipe/package-json/normalize-tooling.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/normalize-tooling.js +47 -3
- package/build/src/cli/recipe/package-json/normalize-tooling.js.map +1 -1
- package/build/src/cli/recipe/package-json/sync-identity.d.ts.map +1 -1
- package/build/src/cli/recipe/package-json/sync-identity.js +51 -18
- package/build/src/cli/recipe/package-json/sync-identity.js.map +1 -1
- package/build/src/cli/scaffold/app/android.d.ts.map +1 -1
- package/build/src/cli/scaffold/app/android.js +2 -0
- package/build/src/cli/scaffold/app/android.js.map +1 -1
- package/build/src/cli/scaffold/app/apple.d.ts.map +1 -1
- package/build/src/cli/scaffold/app/apple.js +2 -0
- package/build/src/cli/scaffold/app/apple.js.map +1 -1
- package/build/src/cli/scaffold/app/astro.d.ts.map +1 -1
- package/build/src/cli/scaffold/app/astro.js +10 -0
- package/build/src/cli/scaffold/app/astro.js.map +1 -1
- package/build/src/cli/scaffold/app/discord-bot.d.ts.map +1 -1
- package/build/src/cli/scaffold/app/discord-bot.js +11 -1
- package/build/src/cli/scaffold/app/discord-bot.js.map +1 -1
- package/build/src/cli/scaffold/app/expressjs.d.ts.map +1 -1
- package/build/src/cli/scaffold/app/expressjs.js +11 -1
- package/build/src/cli/scaffold/app/expressjs.js.map +1 -1
- package/build/src/cli/scaffold/app/nextjs.d.ts.map +1 -1
- package/build/src/cli/scaffold/app/nextjs.js +4 -1
- package/build/src/cli/scaffold/app/nextjs.js.map +1 -1
- package/build/src/cli/scaffold/app/vite.d.ts.map +1 -1
- package/build/src/cli/scaffold/app/vite.js +10 -1
- package/build/src/cli/scaffold/app/vite.js.map +1 -1
- package/build/src/cli/scaffold/docs/docusaurus.d.ts.map +1 -1
- package/build/src/cli/scaffold/docs/docusaurus.js +8 -2
- package/build/src/cli/scaffold/docs/docusaurus.js.map +1 -1
- package/build/src/cli/scaffold/package/github-action.d.ts.map +1 -1
- package/build/src/cli/scaffold/package/github-action.js +4 -0
- package/build/src/cli/scaffold/package/github-action.js.map +1 -1
- package/build/src/cli/scaffold/package/homebridge.d.ts.map +1 -1
- package/build/src/cli/scaffold/package/homebridge.js +1 -0
- package/build/src/cli/scaffold/package/homebridge.js.map +1 -1
- package/build/src/cli/scaffold/package/pfsense.d.ts.map +1 -1
- package/build/src/cli/scaffold/package/pfsense.js +1 -0
- package/build/src/cli/scaffold/package/pfsense.js.map +1 -1
- package/build/src/cli/scaffold/starter/base.d.ts.map +1 -1
- package/build/src/cli/scaffold/starter/base.js +2 -1
- package/build/src/cli/scaffold/starter/base.js.map +1 -1
- package/build/src/cli/scaffold/tool/serverless.d.ts.map +1 -1
- package/build/src/cli/scaffold/tool/serverless.js +5 -0
- package/build/src/cli/scaffold/tool/serverless.js.map +1 -1
- package/build/src/cli/utility/changelog.d.ts +2 -0
- package/build/src/cli/utility/changelog.d.ts.map +1 -1
- package/build/src/cli/utility/changelog.js +225 -129
- package/build/src/cli/utility/changelog.js.map +1 -1
- package/build/src/cli/utility/configure.d.ts.map +1 -1
- package/build/src/cli/utility/configure.js +251 -42
- package/build/src/cli/utility/configure.js.map +1 -1
- package/build/src/lib/docker-packaging.d.ts +22 -1
- package/build/src/lib/docker-packaging.d.ts.map +1 -1
- package/build/src/lib/docker-packaging.js +1048 -76
- package/build/src/lib/docker-packaging.js.map +1 -1
- package/build/src/lib/file-discovery.js +1 -1
- package/build/src/lib/file-discovery.js.map +1 -1
- package/build/src/lib/ignore-files.d.ts.map +1 -1
- package/build/src/lib/ignore-files.js +4 -1
- package/build/src/lib/ignore-files.js.map +1 -1
- package/build/src/lib/integration.d.ts +14 -0
- package/build/src/lib/integration.d.ts.map +1 -0
- package/build/src/lib/integration.js +323 -0
- package/build/src/lib/integration.js.map +1 -0
- package/build/src/lib/nova-config.d.ts.map +1 -1
- package/build/src/lib/nova-config.js +22 -3
- package/build/src/lib/nova-config.js.map +1 -1
- package/build/src/lib/package-scripts.d.ts.map +1 -1
- package/build/src/lib/package-scripts.js +2 -1
- package/build/src/lib/package-scripts.js.map +1 -1
- package/build/src/lib/regex.d.ts +8 -0
- package/build/src/lib/regex.d.ts.map +1 -1
- package/build/src/lib/regex.js +10 -2
- package/build/src/lib/regex.js.map +1 -1
- package/build/src/lib/release-history.d.ts +2 -1
- package/build/src/lib/release-history.d.ts.map +1 -1
- package/build/src/lib/release-history.js +18 -0
- package/build/src/lib/release-history.js.map +1 -1
- package/build/src/lib/run-workspaces.d.ts +2 -0
- package/build/src/lib/run-workspaces.d.ts.map +1 -1
- package/build/src/lib/run-workspaces.js +121 -1
- package/build/src/lib/run-workspaces.js.map +1 -1
- package/build/src/lib/scaffold-allow-scripts.d.ts +4 -0
- package/build/src/lib/scaffold-allow-scripts.d.ts.map +1 -0
- package/build/src/lib/scaffold-allow-scripts.js +76 -0
- package/build/src/lib/scaffold-allow-scripts.js.map +1 -0
- package/build/src/lib/scaffold.d.ts +3 -2
- package/build/src/lib/scaffold.d.ts.map +1 -1
- package/build/src/lib/scaffold.js +177 -33
- package/build/src/lib/scaffold.js.map +1 -1
- package/build/src/lib/transpile.d.ts.map +1 -1
- package/build/src/lib/transpile.js +6 -5
- package/build/src/lib/transpile.js.map +1 -1
- package/build/src/lib/type-check.d.ts +3 -1
- package/build/src/lib/type-check.d.ts.map +1 -1
- package/build/src/lib/type-check.js +22 -6
- package/build/src/lib/type-check.js.map +1 -1
- package/build/src/lib/utility.d.ts.map +1 -1
- package/build/src/lib/utility.js +0 -7
- package/build/src/lib/utility.js.map +1 -1
- package/build/src/lib/version-contract.d.ts +7 -0
- package/build/src/lib/version-contract.d.ts.map +1 -0
- package/build/src/lib/version-contract.js +80 -0
- package/build/src/lib/version-contract.js.map +1 -0
- package/build/src/lib/version-strategy-migration.d.ts +6 -0
- package/build/src/lib/version-strategy-migration.d.ts.map +1 -0
- package/build/src/lib/version-strategy-migration.js +208 -0
- package/build/src/lib/version-strategy-migration.js.map +1 -0
- package/build/src/lib/workflow-templates.d.ts.map +1 -1
- package/build/src/lib/workflow-templates.js +22 -1
- package/build/src/lib/workflow-templates.js.map +1 -1
- package/build/src/presets/eslint/dx-ignore.d.ts.map +1 -1
- package/build/src/presets/eslint/dx-ignore.js +7 -0
- package/build/src/presets/eslint/dx-ignore.js.map +1 -1
- package/build/src/types/api/app-store-connect.d.ts +427 -0
- package/build/src/types/api/google-play-console.d.ts +146 -0
- package/build/src/types/cli/generate/github/workflows-blueprint-validate.d.ts +61 -0
- package/build/src/types/cli/generate/github/workflows-blueprint.d.ts +90 -12
- package/build/src/types/cli/index.d.ts +8 -0
- package/build/src/types/cli/integration/app-store-connect.d.ts +353 -0
- package/build/src/types/cli/integration/discord-developer-portal.d.ts +36 -0
- package/build/src/types/cli/integration/google-play-console.d.ts +145 -0
- package/build/src/types/cli/integration/index.d.ts +31 -0
- package/build/src/types/cli/recipe/package-json/normalize-tooling.d.ts +16 -0
- package/build/src/types/cli/recipe/package-json/sync-identity.d.ts +9 -0
- package/build/src/types/cli/utility/changelog.d.ts +149 -0
- package/build/src/types/cli/utility/configure.d.ts +122 -3
- package/build/src/types/lib/docker-packaging.d.ts +447 -47
- package/build/src/types/lib/integration.d.ts +264 -0
- package/build/src/types/lib/nova-config.d.ts +9 -0
- package/build/src/types/lib/package-scripts.d.ts +2 -0
- package/build/src/types/lib/release-history.d.ts +15 -0
- package/build/src/types/lib/run-workspaces.d.ts +117 -0
- package/build/src/types/lib/scaffold-allow-scripts.d.ts +54 -0
- package/build/src/types/lib/scaffold.d.ts +108 -2
- package/build/src/types/lib/transpile.d.ts +2 -0
- package/build/src/types/lib/type-check.d.ts +28 -0
- package/build/src/types/lib/utility.d.ts +0 -13
- package/build/src/types/lib/version-contract.d.ts +84 -0
- package/build/src/types/lib/version-strategy-migration.d.ts +207 -0
- package/build/src/types/shared.d.ts +456 -1
- package/build/src/types/tests/cli/generate/github/workflows-blueprint-validate.test.d.ts +49 -0
- package/build/src/types/tests/cli/generate/github/workflows-version-contract.test.d.ts +65 -0
- package/build/src/types/tests/cli/generate/must-haves/agent-conventions.test.d.ts +4 -0
- package/build/src/types/tests/cli/integration.test.d.ts +97 -0
- package/build/src/types/tests/cli/recipe/package-json/normalize-tooling.test.d.ts +21 -0
- package/build/src/types/tests/cli/recipe/package-json/sync-identity-version-contract.test.d.ts +57 -0
- package/build/src/types/tests/cli/scaffold/app/android.test.d.ts +8 -0
- package/build/src/types/tests/cli/scaffold/app/apple.test.d.ts +6 -0
- package/build/src/types/tests/cli/scaffold/app/expressjs.test.d.ts +4 -0
- package/build/src/types/tests/cli/utility/changelog-android.test.d.ts +48 -0
- package/build/src/types/tests/cli/utility/changelog-apple.test.d.ts +72 -0
- package/build/src/types/tests/cli/utility/changelog.test.d.ts +16 -12
- package/build/src/types/tests/cli/utility/configure.test.d.ts +88 -0
- package/build/src/types/tests/cli/utility/run-scripts.test.d.ts +2 -0
- package/build/src/types/tests/cli/utility/run-workspaces.test.d.ts +48 -0
- package/build/src/types/tests/lib/docker-packaging.test.d.ts +169 -27
- package/build/src/types/tests/lib/ignore-files.test.d.ts +2 -0
- package/build/src/types/tests/lib/integration.test.d.ts +60 -0
- package/build/src/types/tests/lib/nova-config.test.d.ts +17 -0
- package/build/src/types/tests/lib/scaffold-allow-scripts.test.d.ts +14 -0
- package/build/src/types/tests/lib/scaffold-version-contract.test.d.ts +59 -0
- package/build/src/types/tests/lib/scaffold.test.d.ts +14 -0
- package/build/src/types/tests/lib/type-check.test.d.ts +26 -0
- package/build/src/types/tests/lib/utility.test.d.ts +21 -0
- package/build/src/types/tests/lib/version-contract.test.d.ts +66 -0
- package/build/src/types/tests/lib/version-strategy-migration.test.d.ts +85 -0
- package/build/src/types/tests/lib/workflow-templates.test.d.ts +4 -0
- package/build/src/types/tests/presets/eslint/dx-ignore.test.d.ts +14 -0
- package/build/src/types/tests/scaffold-output-contract.test.d.ts +10 -0
- package/build/templates/generators/must-haves/agent-conventions/PROJECT_RULES.md +107 -196
- package/build/templates/generators/must-haves/agent-conventions/VISION.md +91 -22
- package/build/templates/generators/must-haves/agent-conventions/conventions/docker.md +4 -4
- package/build/templates/generators/must-haves/agent-conventions/conventions/documentation.md +4 -2
- package/build/templates/scaffold/app/android/package.json +2 -2
- package/build/templates/scaffold/app/android/scripts/run-gradle.mjs +21 -4
- package/build/templates/scaffold/app/apple/package.json +2 -2
- package/build/templates/scaffold/app/apple/project.yml +1 -1
- package/build/templates/scaffold/app/astro/package.json +2 -2
- package/build/templates/scaffold/app/discord-bot/package.json +2 -2
- package/build/templates/scaffold/app/express/package.json +2 -2
- package/build/templates/scaffold/app/nextjs/package.json +2 -2
- package/build/templates/scaffold/app/vite/package.json +2 -2
- package/build/templates/scaffold/docs/docusaurus/docusaurus.config.ts +2 -1
- package/build/templates/scaffold/docs/docusaurus/eslint.config.mts +61 -3
- package/build/templates/scaffold/docs/docusaurus/package.json +6 -4
- package/build/templates/scaffold/docs/docusaurus/src/pages/index.tsx +2 -2
- package/build/templates/scaffold/docs/docusaurus/src/tests/dotenv.test.ts +27 -0
- package/build/templates/scaffold/docs/docusaurus/src/tests/frontmatter.test.ts +1 -1
- package/build/templates/scaffold/docs/docusaurus/src/tests/link.test.ts +1 -1
- package/build/templates/scaffold/docs/docusaurus/src/tests/markdown-table.test.ts +1 -1
- package/build/templates/scaffold/docs/docusaurus/src/tests/terminology.test.ts +1 -1
- package/build/templates/scaffold/docs/docusaurus/src/tests/type-declarations.test.ts +1 -1
- package/build/templates/scaffold/docs/docusaurus/src/types/pages/index.d.ts +2 -2
- package/build/templates/scaffold/docs/docusaurus/tsconfig.app.json +33 -0
- package/build/templates/scaffold/docs/docusaurus/tsconfig.config.json +21 -0
- package/build/templates/scaffold/docs/docusaurus/tsconfig.json +11 -17
- package/build/templates/scaffold/docs/docusaurus/tsconfig.tests.json +28 -0
- package/build/templates/scaffold/docs/docusaurus/vitest.config.mts +1 -14
- package/build/templates/scaffold/docs/docusaurus/vitest.setup.ts +3 -3
- package/build/templates/scaffold/package/github-action/package.json +2 -2
- package/build/templates/scaffold/package/homebridge/bin/repl.mjs +5 -2
- package/build/templates/scaffold/package/homebridge/bin/test-api.mjs +5 -2
- package/build/templates/scaffold/package/homebridge/package.json +2 -2
- package/build/templates/scaffold/package/pfsense/package.json +2 -2
- package/build/templates/scaffold/starter/base/assets/README.md +7 -0
- package/build/templates/scaffold-options/app/android-native/app/build.gradle.kts +1 -1
- package/build/templates/scaffold-options/app/android-native/gradlew.bat +84 -84
- package/build/templates/scaffold-options/app/apple-store-connect-root/assets/app-store-connect/[__WORKSPACE_NAME__]/creative-assets/README.md +10 -0
- package/build/templates/scaffold-options/app/apple-store-connect-root/assets/app-store-connect/[__WORKSPACE_NAME__]/metadata/ios/en-US.json +8 -0
- package/build/templates/scaffold-options/app/apple-store-connect-root/assets/app-store-connect/[__WORKSPACE_NAME__]/metadata/macos/en-US.json +8 -0
- package/build/templates/scaffold-options/app/apple-store-connect-root/assets/app-store-connect/[__WORKSPACE_NAME__]/screenshots/README.md +13 -0
- package/build/templates/scaffold-options/app/google-play-console-root/assets/google-play-console/[__WORKSPACE_NAME__]/graphic-assets/README.md +12 -0
- package/build/templates/scaffold-options/app/google-play-console-root/assets/google-play-console/[__WORKSPACE_NAME__]/metadata/android/en-US.json +6 -0
- package/build/templates/scaffold-options/app/google-play-console-root/assets/google-play-console/[__WORKSPACE_NAME__]/screenshots/README.md +13 -0
- package/build/templates/scaffold-options/docker-image/common/Dockerfile +82 -0
- package/build/templates/scaffold-options/docker-image/common/compose.yml +21 -0
- package/build/templates/scaffold-options/docker-image/common/dockerignore +38 -0
- package/build/templates/scaffold-options/package/node-cli-core/bin/cli.mjs +5 -2
- package/build/templates/scaffold-options/tool/serverless/cloudflare-workers/package.json +2 -2
- package/build/templates/scaffold-options/tool/serverless/vercel-functions/package.json +2 -2
- package/package.json +3 -2
- package/build/templates/scaffold-options/docker-image/astro-node/Dockerfile +0 -27
- package/build/templates/scaffold-options/docker-image/astro-node/compose.yml +0 -12
- package/build/templates/scaffold-options/docker-image/background-service/compose.yml +0 -10
- package/build/templates/scaffold-options/docker-image/container-native/Dockerfile +0 -10
- package/build/templates/scaffold-options/docker-image/container-native/compose.yml +0 -8
- package/build/templates/scaffold-options/docker-image/http-service/compose.yml +0 -11
- package/build/templates/scaffold-options/docker-image/nextjs-standalone/Dockerfile +0 -26
- package/build/templates/scaffold-options/docker-image/nextjs-standalone/compose.yml +0 -12
- package/build/templates/scaffold-options/docker-image/node/Dockerfile +0 -23
- package/build/templates/scaffold-options/docker-image/static-site/Dockerfile +0 -18
- package/build/templates/scaffold-options/docker-image/static-site/compose.yml +0 -8
|
@@ -1,116 +1,1088 @@
|
|
|
1
1
|
import { promises as fs } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
2
|
+
import { basename, dirname, join, relative, sep, } from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { Runner as LibCorepack } from './corepack.js';
|
|
4
5
|
import { renderIgnoreFile } from './ignore-files.js';
|
|
5
|
-
import {
|
|
6
|
+
import { libItemAllowedRecipes } from './item.js';
|
|
7
|
+
import { normalizeNovaConfigTopLevelOrder } from './nova-config-order.js';
|
|
8
|
+
import { LIB_REGEX_PATTERN_DOCKER_RUNTIME_PATH, LIB_REGEX_PATTERN_SLUG_SIMPLE, } from './regex.js';
|
|
6
9
|
import { applyScaffoldVersionReplacements } from './scaffold-versions.js';
|
|
7
|
-
import { isPlainObject, saveGeneratedFile, } from './utility.js';
|
|
10
|
+
import { isPlainObject, pathExists, saveGeneratedFile, } from './utility.js';
|
|
11
|
+
const dockerAssemblyRelativePath = 'packages/docker';
|
|
12
|
+
const dockerConfigWorkspacePath = './packages/docker';
|
|
13
|
+
const dockerManifestSchemaVersion = 1;
|
|
14
|
+
const dockerProtectedWritablePaths = [
|
|
15
|
+
'/bin',
|
|
16
|
+
'/dev',
|
|
17
|
+
'/etc',
|
|
18
|
+
'/lib',
|
|
19
|
+
'/lib64',
|
|
20
|
+
'/proc',
|
|
21
|
+
'/run',
|
|
22
|
+
'/sbin',
|
|
23
|
+
'/sys',
|
|
24
|
+
'/usr',
|
|
25
|
+
];
|
|
26
|
+
const dockerReservedServiceNames = new Set([
|
|
27
|
+
'base',
|
|
28
|
+
'fix-attrs',
|
|
29
|
+
'legacy-cont-init',
|
|
30
|
+
'legacy-services',
|
|
31
|
+
'nova-container-init',
|
|
32
|
+
's6rc-oneshot-runner',
|
|
33
|
+
'top',
|
|
34
|
+
'user',
|
|
35
|
+
'user2',
|
|
36
|
+
]);
|
|
8
37
|
export class Runner {
|
|
9
38
|
static async generateForTarget(options) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
||
|
|
15
|
-
||
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
39
|
+
const projectDirectory = options['projectDirectory'];
|
|
40
|
+
const workspaceDirectory = options['workspaceDirectory'];
|
|
41
|
+
const workspacePathValue = relative(projectDirectory, workspaceDirectory).split(sep).join('/');
|
|
42
|
+
if (workspacePathValue === ''
|
|
43
|
+
|| workspacePathValue === '..'
|
|
44
|
+
|| workspacePathValue.startsWith('../') === true) {
|
|
45
|
+
throw new Error(`The Docker workspace "${workspaceDirectory}" must be inside project root "${projectDirectory}".`);
|
|
46
|
+
}
|
|
47
|
+
const assemblyDirectory = join(projectDirectory, dockerAssemblyRelativePath);
|
|
48
|
+
const manifestPath = join(assemblyDirectory, 'manifest.json');
|
|
49
|
+
const rootPackagePath = join(projectDirectory, 'package.json');
|
|
50
|
+
const workspacePackagePath = join(workspaceDirectory, 'package.json');
|
|
51
|
+
const novaConfigPath = join(projectDirectory, 'nova.config.json');
|
|
52
|
+
const existingManifestValue = (await pathExists(manifestPath) === true) ? await Runner.readJsonObject(manifestPath) : undefined;
|
|
53
|
+
const rootPackage = await Runner.readJsonObject(rootPackagePath);
|
|
54
|
+
const workspacePackage = await Runner.readJsonObject(workspacePackagePath);
|
|
55
|
+
const novaConfig = await Runner.readJsonObject(novaConfigPath);
|
|
56
|
+
const workspacePackageNameValue = workspacePackage['name'];
|
|
57
|
+
if (typeof workspacePackageNameValue !== 'string' || workspacePackageNameValue.trim() === '') {
|
|
58
|
+
throw new Error(`The Docker workspace package manifest at "${workspacePackagePath}" must define a package name.`);
|
|
59
|
+
}
|
|
60
|
+
const projectValue = novaConfig['project'];
|
|
61
|
+
const projectNameValue = (isPlainObject(projectValue) === true) ? projectValue['name'] : undefined;
|
|
62
|
+
const projectSlugValue = (isPlainObject(projectNameValue) === true) ? projectNameValue['slug'] : undefined;
|
|
63
|
+
if (typeof projectSlugValue !== 'string' || LIB_REGEX_PATTERN_SLUG_SIMPLE.test(projectSlugValue) === false) {
|
|
64
|
+
throw new Error(`The Nova config at "${novaConfigPath}" must define a valid project.name.slug before Docker packaging can be generated.`);
|
|
65
|
+
}
|
|
66
|
+
const manifest = Runner.normalizeManifest(existingManifestValue);
|
|
67
|
+
const existingWorkspace = manifest['workspaces'].find((workspace) => workspace['path'] === workspacePathValue);
|
|
68
|
+
let runtimePaths = options['runtimePaths'];
|
|
69
|
+
if (runtimePaths === undefined && existingWorkspace !== undefined) {
|
|
70
|
+
runtimePaths = existingWorkspace['runtimePaths'];
|
|
71
|
+
}
|
|
72
|
+
const workspaceDefinition = {
|
|
73
|
+
buildDirectory: options['buildDirectory'] ?? 'build',
|
|
74
|
+
packageName: workspacePackageNameValue,
|
|
75
|
+
path: workspacePathValue,
|
|
76
|
+
profile: options['profile'],
|
|
77
|
+
runtimePaths: Runner.normalizeRuntimePaths(runtimePaths ?? [], workspacePathValue),
|
|
78
|
+
};
|
|
79
|
+
const requestedServices = Runner.buildRequestedServices(options, manifest);
|
|
80
|
+
const retainedServices = manifest['services'].filter((service) => service['workspace'] !== workspacePathValue);
|
|
81
|
+
for (const requestedService of requestedServices) {
|
|
82
|
+
const conflictingService = manifest['services'].find((service) => service['name'] === requestedService['name'] && service['workspace'] !== workspacePathValue);
|
|
83
|
+
if (conflictingService !== undefined) {
|
|
84
|
+
throw new Error(`Docker service "${requestedService['name']}" is already owned by workspace "${conflictingService['workspace']}".`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const retainedWorkspaces = manifest['workspaces'].filter((workspace) => workspace['path'] !== workspacePathValue);
|
|
88
|
+
const updatedManifest = {
|
|
89
|
+
schemaVersion: dockerManifestSchemaVersion,
|
|
90
|
+
services: [
|
|
91
|
+
...retainedServices,
|
|
92
|
+
...requestedServices,
|
|
93
|
+
].sort((firstService, secondService) => firstService['name'].localeCompare(secondService['name'])),
|
|
94
|
+
workspaces: [
|
|
95
|
+
...retainedWorkspaces,
|
|
96
|
+
workspaceDefinition,
|
|
97
|
+
].sort((firstWorkspace, secondWorkspace) => firstWorkspace['path'].localeCompare(secondWorkspace['path'])),
|
|
98
|
+
};
|
|
99
|
+
const availableServiceNames = new Set(updatedManifest['services'].map((service) => service['name']));
|
|
100
|
+
for (const service of updatedManifest['services']) {
|
|
101
|
+
for (const dependency of service['dependencies']) {
|
|
102
|
+
if (availableServiceNames.has(dependency) === false) {
|
|
103
|
+
throw new Error(`Docker service "${service['name']}" depends on unknown service "${dependency}".`);
|
|
104
|
+
}
|
|
105
|
+
if (dependency === service['name']) {
|
|
106
|
+
throw new Error(`Docker service "${service['name']}" cannot depend on itself.`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const servicesByName = new Map(updatedManifest['services'].map((service) => [
|
|
111
|
+
service['name'],
|
|
112
|
+
service,
|
|
113
|
+
]));
|
|
114
|
+
const visitedServices = new Set();
|
|
115
|
+
const visitingServices = new Set();
|
|
116
|
+
const visitService = (serviceName) => {
|
|
117
|
+
if (visitedServices.has(serviceName) === true) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (visitingServices.has(serviceName) === true) {
|
|
121
|
+
throw new Error(`Docker service dependency cycle includes "${serviceName}".`);
|
|
122
|
+
}
|
|
123
|
+
const service = servicesByName.get(serviceName);
|
|
124
|
+
if (service === undefined) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
visitingServices.add(serviceName);
|
|
128
|
+
for (const dependency of service['dependencies']) {
|
|
129
|
+
visitService(dependency);
|
|
130
|
+
}
|
|
131
|
+
visitingServices.delete(serviceName);
|
|
132
|
+
visitedServices.add(serviceName);
|
|
133
|
+
return;
|
|
134
|
+
};
|
|
135
|
+
for (const service of updatedManifest['services']) {
|
|
136
|
+
visitService(service['name']);
|
|
137
|
+
}
|
|
138
|
+
const workspacePackages = await Runner.collectWorkspacePackages(projectDirectory, updatedManifest);
|
|
139
|
+
const buildOrder = Runner.resolveBuildOrder(updatedManifest, workspacePackages);
|
|
140
|
+
const packageManagerDescriptor = LibCorepack.parsePackageManager(rootPackage['packageManager']);
|
|
141
|
+
const packageManager = (packageManagerDescriptor === undefined) ? 'npm' : packageManagerDescriptor['name'];
|
|
142
|
+
const packageManagerVersion = (packageManagerDescriptor === undefined) ? '' : packageManagerDescriptor['version'];
|
|
143
|
+
const isYarnClassic = packageManager === 'yarn' && packageManagerVersion.startsWith('1.');
|
|
144
|
+
const isYarnBerry = packageManager === 'yarn' && isYarnClassic === false;
|
|
145
|
+
const needsSyntheticWorkspaceManifests = packageManager === 'npm' || isYarnClassic === true;
|
|
146
|
+
const syntheticWorkspaceManifests = new Map();
|
|
147
|
+
if (needsSyntheticWorkspaceManifests === true) {
|
|
148
|
+
for (const workspacePackageValue of buildOrder.values()) {
|
|
149
|
+
const syntheticWorkspaceManifestPath = join(assemblyDirectory, 'workspace-manifests', workspacePackageValue['path'], 'package.json');
|
|
150
|
+
const syntheticWorkspacePackage = Runner.buildSyntheticWorkspacePackage(workspacePackageValue['packageJson'], buildOrder);
|
|
151
|
+
const syntheticWorkspaceManifestContent = `${JSON.stringify(syntheticWorkspacePackage, null, 2)}\n`;
|
|
152
|
+
syntheticWorkspaceManifests.set(syntheticWorkspaceManifestPath, syntheticWorkspaceManifestContent);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const templateRoot = fileURLToPath(new URL('../../templates/scaffold-options/docker-image/common/', import.meta.url));
|
|
23
156
|
const templateContents = await Promise.all([
|
|
24
|
-
fs.readFile(
|
|
25
|
-
fs.readFile(
|
|
26
|
-
fs.readFile(packageJsonPath, 'utf-8'),
|
|
157
|
+
fs.readFile(join(templateRoot, 'Dockerfile'), 'utf-8'),
|
|
158
|
+
fs.readFile(join(templateRoot, 'compose.yml'), 'utf-8'),
|
|
27
159
|
]);
|
|
28
|
-
const
|
|
160
|
+
const dockerfileContent = Runner.buildDockerfile(templateContents[0] ?? '', updatedManifest, buildOrder, rootPackage);
|
|
161
|
+
const composeContent = Runner.buildCompose(templateContents[1] ?? '', updatedManifest);
|
|
162
|
+
const ignoreFilesValue = novaConfig['ignoreFiles'];
|
|
163
|
+
const configuredIgnoreFileEntry = (isPlainObject(ignoreFilesValue) === true) ? ignoreFilesValue['./.dockerignore'] : undefined;
|
|
164
|
+
const ignoreFileEntry = options['ignoreFileEntry'] ?? ((isPlainObject(configuredIgnoreFileEntry) === true) ? configuredIgnoreFileEntry : {
|
|
29
165
|
bundles: ['nova'],
|
|
30
166
|
patterns: [],
|
|
31
167
|
});
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const reportFiles = options['reportFiles'] !== false;
|
|
64
|
-
if (isDryRun === true) {
|
|
65
|
-
return;
|
|
168
|
+
const dockerignoreContent = await renderIgnoreFile('./.dockerignore', ignoreFileEntry);
|
|
169
|
+
const gitAttributesContent = 'rootfs/** text eol=lf\n';
|
|
170
|
+
const assemblyPackageName = `${projectSlugValue}-tool-docker`;
|
|
171
|
+
const assemblyPackage = Runner.buildWorkspacePackage(projectSlugValue);
|
|
172
|
+
const containerBuildPackage = Runner.buildContainerPackage(rootPackage, assemblyPackageName, buildOrder);
|
|
173
|
+
const pnpmWorkspaceLines = [
|
|
174
|
+
'packages:',
|
|
175
|
+
...[...buildOrder.values()].map((workspacePackageValue) => ` - '${workspacePackageValue['path']}'`),
|
|
176
|
+
'',
|
|
177
|
+
];
|
|
178
|
+
const pnpmWorkspaceContent = pnpmWorkspaceLines.join('\n');
|
|
179
|
+
const yarnConfigContent = [
|
|
180
|
+
'enableGlobalCache: false',
|
|
181
|
+
'nodeLinker: pnp',
|
|
182
|
+
'pnpEnableEsmLoader: true',
|
|
183
|
+
'',
|
|
184
|
+
].join('\n');
|
|
185
|
+
const updatedRootPackage = Runner.buildRootPackage(rootPackage, assemblyPackageName);
|
|
186
|
+
const updatedNovaConfig = Runner.registerProjectConfig(novaConfig, assemblyPackageName, ignoreFileEntry);
|
|
187
|
+
const result = {
|
|
188
|
+
assemblyDirectory,
|
|
189
|
+
composePath: join(projectDirectory, 'compose.yml'),
|
|
190
|
+
dockerfilePath: join(projectDirectory, 'Dockerfile'),
|
|
191
|
+
dockerignorePath: join(projectDirectory, '.dockerignore'),
|
|
192
|
+
manifestPath,
|
|
193
|
+
projectDirectory,
|
|
194
|
+
serviceNames: updatedManifest['services'].map((service) => service['name']),
|
|
195
|
+
workspacePath: workspacePathValue,
|
|
196
|
+
};
|
|
197
|
+
if (options['dryRun'] === true) {
|
|
198
|
+
return result;
|
|
66
199
|
}
|
|
200
|
+
const rootfsDirectory = join(assemblyDirectory, 'rootfs');
|
|
201
|
+
const workspaceManifestsDirectory = join(assemblyDirectory, 'workspace-manifests');
|
|
202
|
+
const yarnConfigPath = join(assemblyDirectory, 'yarnrc.yml');
|
|
203
|
+
const reportFiles = options['reportFiles'] !== false;
|
|
204
|
+
await fs.mkdir(assemblyDirectory, { recursive: true });
|
|
205
|
+
await Promise.all([
|
|
206
|
+
fs.rm(rootfsDirectory, {
|
|
207
|
+
force: true,
|
|
208
|
+
recursive: true,
|
|
209
|
+
}),
|
|
210
|
+
fs.rm(workspaceManifestsDirectory, {
|
|
211
|
+
force: true,
|
|
212
|
+
recursive: true,
|
|
213
|
+
}),
|
|
214
|
+
fs.rm(yarnConfigPath, { force: true }),
|
|
215
|
+
]);
|
|
67
216
|
await Promise.all([
|
|
68
|
-
saveGeneratedFile(
|
|
217
|
+
saveGeneratedFile(result['dockerfilePath'], dockerfileContent, true, undefined, reportFiles),
|
|
218
|
+
saveGeneratedFile(result['composePath'], composeContent, true, undefined, reportFiles),
|
|
219
|
+
saveGeneratedFile(result['dockerignorePath'], dockerignoreContent, true, {
|
|
69
220
|
command: 'nova generate must-haves ignore-files',
|
|
70
221
|
docsSlug: 'cli/generators/must-haves/ignore-files',
|
|
71
222
|
mode: 'strict',
|
|
72
223
|
}, reportFiles),
|
|
73
|
-
saveGeneratedFile(join(
|
|
74
|
-
saveGeneratedFile(join(
|
|
75
|
-
saveGeneratedFile(
|
|
224
|
+
saveGeneratedFile(join(assemblyDirectory, '.gitattributes'), gitAttributesContent, true, undefined, reportFiles),
|
|
225
|
+
saveGeneratedFile(join(assemblyDirectory, 'build-package.json'), `${JSON.stringify(containerBuildPackage, null, 2)}\n`, true, undefined, reportFiles),
|
|
226
|
+
saveGeneratedFile(join(assemblyDirectory, 'package.json'), `${JSON.stringify(assemblyPackage, null, 2)}\n`, true, undefined, reportFiles),
|
|
227
|
+
saveGeneratedFile(join(assemblyDirectory, 'pnpm-workspace.yaml'), pnpmWorkspaceContent, true, undefined, reportFiles),
|
|
228
|
+
...((isYarnBerry === true) ? [saveGeneratedFile(yarnConfigPath, yarnConfigContent, true, undefined, reportFiles)] : []),
|
|
229
|
+
...[...syntheticWorkspaceManifests].map((syntheticWorkspaceManifest) => saveGeneratedFile(syntheticWorkspaceManifest[0], syntheticWorkspaceManifest[1], true, undefined, reportFiles)),
|
|
230
|
+
saveGeneratedFile(manifestPath, `${JSON.stringify(updatedManifest, null, 2)}\n`, true, undefined, reportFiles),
|
|
231
|
+
saveGeneratedFile(rootPackagePath, `${JSON.stringify(updatedRootPackage, null, 2)}\n`, true, undefined, false),
|
|
232
|
+
saveGeneratedFile(novaConfigPath, `${JSON.stringify(updatedNovaConfig, null, 2)}\n`, true, undefined, false),
|
|
233
|
+
]);
|
|
234
|
+
await Runner.writeRootfs(rootfsDirectory, updatedManifest);
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
static async readJsonObject(targetPath) {
|
|
238
|
+
const rawContent = await fs.readFile(targetPath, 'utf-8');
|
|
239
|
+
const parsedContent = JSON.parse(rawContent);
|
|
240
|
+
if (isPlainObject(parsedContent) === false) {
|
|
241
|
+
throw new Error(`The JSON file at "${targetPath}" must contain an object.`);
|
|
242
|
+
}
|
|
243
|
+
return parsedContent;
|
|
244
|
+
}
|
|
245
|
+
static normalizeManifest(value) {
|
|
246
|
+
if (value === undefined) {
|
|
247
|
+
return {
|
|
248
|
+
schemaVersion: dockerManifestSchemaVersion,
|
|
249
|
+
services: [],
|
|
250
|
+
workspaces: [],
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (value['schemaVersion'] !== dockerManifestSchemaVersion
|
|
254
|
+
|| Array.isArray(value['services']) === false
|
|
255
|
+
|| Array.isArray(value['workspaces']) === false) {
|
|
256
|
+
throw new Error('The Docker assembly manifest is not compatible with this Nova version.');
|
|
257
|
+
}
|
|
258
|
+
const manifest = value;
|
|
259
|
+
const serviceNames = new Set();
|
|
260
|
+
for (const service of manifest['services']) {
|
|
261
|
+
Runner.validateServiceName(service['name']);
|
|
262
|
+
if (serviceNames.has(service['name']) === true) {
|
|
263
|
+
throw new Error(`Docker service name "${service['name']}" is declared more than once in the assembly manifest.`);
|
|
264
|
+
}
|
|
265
|
+
serviceNames.add(service['name']);
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
...manifest,
|
|
269
|
+
workspaces: manifest['workspaces'].map((workspace) => ({
|
|
270
|
+
...workspace,
|
|
271
|
+
runtimePaths: Runner.normalizeRuntimePaths(workspace['runtimePaths'] ?? [], workspace['path']),
|
|
272
|
+
})),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
static normalizeRuntimePaths(value, workspacePath) {
|
|
276
|
+
if (Array.isArray(value) === false) {
|
|
277
|
+
throw new Error(`Docker runtime paths for workspace "${workspacePath}" must be an array.`);
|
|
278
|
+
}
|
|
279
|
+
const runtimePaths = [];
|
|
280
|
+
for (const runtimePathValue of value) {
|
|
281
|
+
if (typeof runtimePathValue !== 'string') {
|
|
282
|
+
throw new Error(`Docker runtime paths for workspace "${workspacePath}" must contain only strings.`);
|
|
283
|
+
}
|
|
284
|
+
const pathParts = runtimePathValue.split('/');
|
|
285
|
+
if (runtimePathValue === ''
|
|
286
|
+
|| runtimePathValue.startsWith('/') === true
|
|
287
|
+
|| runtimePathValue.endsWith('/') === true
|
|
288
|
+
|| LIB_REGEX_PATTERN_DOCKER_RUNTIME_PATH.test(runtimePathValue) === false
|
|
289
|
+
|| pathParts.includes('') === true
|
|
290
|
+
|| pathParts.includes('.') === true
|
|
291
|
+
|| pathParts.includes('..') === true) {
|
|
292
|
+
throw new Error(`Docker runtime path "${runtimePathValue}" for workspace "${workspacePath}" is not a safe, specific relative path.`);
|
|
293
|
+
}
|
|
294
|
+
runtimePaths.push(runtimePathValue);
|
|
295
|
+
}
|
|
296
|
+
return [...new Set(runtimePaths)].sort((firstPath, secondPath) => firstPath.localeCompare(secondPath));
|
|
297
|
+
}
|
|
298
|
+
static buildRequestedServices(options, manifest) {
|
|
299
|
+
const workspacePath = relative(options['projectDirectory'], options['workspaceDirectory']).split(sep).join('/');
|
|
300
|
+
const defaultName = options['workspaceName'] ?? basename(workspacePath);
|
|
301
|
+
const serviceInputs = options['services'] ?? [{ name: defaultName }];
|
|
302
|
+
const existingServices = manifest['services'];
|
|
303
|
+
const requestedServices = [];
|
|
304
|
+
for (const serviceInput of serviceInputs) {
|
|
305
|
+
if (requestedServices.some((service) => service['name'] === serviceInput['name']) === true) {
|
|
306
|
+
throw new Error(`Docker service name "${serviceInput['name']}" is declared more than once for workspace "${workspacePath}".`);
|
|
307
|
+
}
|
|
308
|
+
requestedServices.push(Runner.buildService(options, serviceInput, existingServices, requestedServices));
|
|
309
|
+
}
|
|
310
|
+
return requestedServices;
|
|
311
|
+
}
|
|
312
|
+
static buildService(options, input, existingServices, requestedServices) {
|
|
313
|
+
const name = input['name'];
|
|
314
|
+
Runner.validateServiceName(name);
|
|
315
|
+
const workspacePath = relative(options['projectDirectory'], options['workspaceDirectory']).split(sep).join('/');
|
|
316
|
+
const previousService = existingServices.find((service) => service['name'] === name && service['workspace'] === workspacePath);
|
|
317
|
+
const previousPort = (previousService === undefined) ? undefined : previousService['port'];
|
|
318
|
+
let preferredPort = undefined;
|
|
319
|
+
if (options['profile'] === 'astro-node') {
|
|
320
|
+
preferredPort = 4321;
|
|
321
|
+
}
|
|
322
|
+
else if (options['profile'] === 'static-site') {
|
|
323
|
+
preferredPort = 8080;
|
|
324
|
+
}
|
|
325
|
+
else if (options['profile'] === 'http-service' || options['profile'] === 'nextjs-standalone') {
|
|
326
|
+
preferredPort = 3000;
|
|
327
|
+
}
|
|
328
|
+
let port = input['port'] ?? previousPort;
|
|
329
|
+
if (port === undefined) {
|
|
330
|
+
port = preferredPort;
|
|
331
|
+
}
|
|
332
|
+
const occupiedPorts = new Set();
|
|
333
|
+
for (const service of existingServices) {
|
|
334
|
+
if (service['workspace'] !== workspacePath && service['port'] !== undefined) {
|
|
335
|
+
occupiedPorts.add(service['port']);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
for (const service of requestedServices) {
|
|
339
|
+
if (service['port'] !== undefined) {
|
|
340
|
+
occupiedPorts.add(service['port']);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (input['port'] !== undefined && occupiedPorts.has(input['port']) === true) {
|
|
344
|
+
throw new Error(`Docker service "${name}" requests port ${input['port']}, but another service already uses it.`);
|
|
345
|
+
}
|
|
346
|
+
while (port !== undefined && occupiedPorts.has(port) === true) {
|
|
347
|
+
port += 1;
|
|
348
|
+
}
|
|
349
|
+
const kind = input['kind'] ?? 'longrun';
|
|
350
|
+
const environment = { ...(input['environment'] ?? {}) };
|
|
351
|
+
if (port !== undefined) {
|
|
352
|
+
Reflect.set(environment, 'PORT', `${port}`);
|
|
353
|
+
}
|
|
354
|
+
if (options['profile'] === 'astro-node') {
|
|
355
|
+
Reflect.set(environment, 'HOST', '0.0.0.0');
|
|
356
|
+
}
|
|
357
|
+
if (options['profile'] === 'nextjs-standalone') {
|
|
358
|
+
Reflect.set(environment, 'HOSTNAME', '0.0.0.0');
|
|
359
|
+
}
|
|
360
|
+
let command = input['command'] ?? 'node build/index.js';
|
|
361
|
+
if (input['command'] === undefined) {
|
|
362
|
+
if (options['profile'] === 'astro-node') {
|
|
363
|
+
command = 'node build/server/entry.mjs';
|
|
364
|
+
}
|
|
365
|
+
else if (options['profile'] === 'container-native') {
|
|
366
|
+
command = '/command/s6-pause';
|
|
367
|
+
}
|
|
368
|
+
else if (options['profile'] === 'nextjs-standalone') {
|
|
369
|
+
command = 'node server.js';
|
|
370
|
+
}
|
|
371
|
+
else if (options['profile'] === 'static-site') {
|
|
372
|
+
command = `httpd -f -p ${port ?? 8080} -h /app/sites/${name}`;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const writablePaths = [...(input['writablePaths'] ?? [])];
|
|
376
|
+
for (const writablePath of writablePaths) {
|
|
377
|
+
const pathParts = writablePath.split('/');
|
|
378
|
+
const isProtectedWritablePath = dockerProtectedWritablePaths.some((protectedPath) => (writablePath === protectedPath
|
|
379
|
+
|| writablePath.startsWith(`${protectedPath}/`) === true));
|
|
380
|
+
if (writablePath.startsWith('/') === false
|
|
381
|
+
|| writablePath === '/'
|
|
382
|
+
|| pathParts.includes('..') === true
|
|
383
|
+
|| pathParts.includes('.') === true
|
|
384
|
+
|| isProtectedWritablePath === true) {
|
|
385
|
+
throw new Error(`Docker writable path "${writablePath}" is not a safe, specific absolute path.`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
const service = {
|
|
389
|
+
command,
|
|
390
|
+
critical: input['critical'] ?? false,
|
|
391
|
+
dependencies: [...new Set(input['dependencies'] ?? [])].sort((firstDependency, secondDependency) => firstDependency.localeCompare(secondDependency)),
|
|
392
|
+
environment,
|
|
393
|
+
kind: (kind === 'oneshot') ? 'oneshot' : 'longrun',
|
|
394
|
+
name,
|
|
395
|
+
requiredForHealth: input['requiredForHealth'] ?? kind !== 'oneshot',
|
|
396
|
+
runAsRoot: input['runAsRoot'] ?? false,
|
|
397
|
+
workspace: workspacePath,
|
|
398
|
+
writablePaths,
|
|
399
|
+
};
|
|
400
|
+
const healthCommand = input['healthCommand'] ?? ((port === undefined) ? undefined : `wget --spider --quiet http://127.0.0.1:${port}/`);
|
|
401
|
+
if (healthCommand !== undefined) {
|
|
402
|
+
service.healthCommand = healthCommand;
|
|
403
|
+
}
|
|
404
|
+
if (port !== undefined) {
|
|
405
|
+
service.port = port;
|
|
406
|
+
}
|
|
407
|
+
return service;
|
|
408
|
+
}
|
|
409
|
+
static async collectWorkspacePackages(projectDirectory, manifest) {
|
|
410
|
+
const workspacePaths = new Set(manifest['workspaces'].map((workspace) => workspace['path']));
|
|
411
|
+
for (const workspaceGroup of [
|
|
412
|
+
'apps',
|
|
413
|
+
'packages',
|
|
414
|
+
]) {
|
|
415
|
+
const groupDirectory = join(projectDirectory, workspaceGroup);
|
|
416
|
+
if (await pathExists(groupDirectory) === false) {
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
const directoryEntries = await fs.readdir(groupDirectory, { withFileTypes: true });
|
|
420
|
+
for (const directoryEntry of directoryEntries) {
|
|
421
|
+
if (directoryEntry.isDirectory() === false) {
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (workspaceGroup === 'packages' && directoryEntry.name === 'docker') {
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
workspacePaths.add(`${workspaceGroup}/${directoryEntry.name}`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
const workspacePackages = new Map();
|
|
431
|
+
for (const workspacePath of workspacePaths) {
|
|
432
|
+
const packagePath = join(projectDirectory, workspacePath, 'package.json');
|
|
433
|
+
if (await pathExists(packagePath) === false) {
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
const packageJson = await Runner.readJsonObject(packagePath);
|
|
437
|
+
const packageName = packageJson['name'];
|
|
438
|
+
if (typeof packageName === 'string' && packageName.trim() !== '') {
|
|
439
|
+
workspacePackages.set(packageName, {
|
|
440
|
+
packageJson,
|
|
441
|
+
path: workspacePath,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return workspacePackages;
|
|
446
|
+
}
|
|
447
|
+
static resolveBuildOrder(manifest, workspacePackages) {
|
|
448
|
+
const orderedPackages = new Map();
|
|
449
|
+
const visitingPackages = new Set();
|
|
450
|
+
const visitPackage = (packageName) => {
|
|
451
|
+
if (orderedPackages.has(packageName) === true) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (visitingPackages.has(packageName) === true) {
|
|
455
|
+
throw new Error(`Docker workspace dependency cycle includes "${packageName}".`);
|
|
456
|
+
}
|
|
457
|
+
const workspacePackage = workspacePackages.get(packageName);
|
|
458
|
+
if (workspacePackage === undefined) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
visitingPackages.add(packageName);
|
|
462
|
+
for (const dependencyGroupName of [
|
|
463
|
+
'dependencies',
|
|
464
|
+
'devDependencies',
|
|
465
|
+
'optionalDependencies',
|
|
466
|
+
'peerDependencies',
|
|
467
|
+
]) {
|
|
468
|
+
const dependencyGroup = workspacePackage['packageJson'][dependencyGroupName];
|
|
469
|
+
if (isPlainObject(dependencyGroup) === true) {
|
|
470
|
+
for (const dependencyName of Object.keys(dependencyGroup).sort((firstDependency, secondDependency) => firstDependency.localeCompare(secondDependency))) {
|
|
471
|
+
if (workspacePackages.has(dependencyName) === true) {
|
|
472
|
+
visitPackage(dependencyName);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
visitingPackages.delete(packageName);
|
|
478
|
+
orderedPackages.set(packageName, workspacePackage);
|
|
479
|
+
return;
|
|
480
|
+
};
|
|
481
|
+
for (const workspace of manifest['workspaces']) {
|
|
482
|
+
visitPackage(workspace['packageName']);
|
|
483
|
+
}
|
|
484
|
+
return orderedPackages;
|
|
485
|
+
}
|
|
486
|
+
static buildSyntheticWorkspacePackage(packageJson, buildOrder) {
|
|
487
|
+
const syntheticPackage = structuredClone(packageJson);
|
|
488
|
+
for (const dependencyGroupName of [
|
|
489
|
+
'dependencies',
|
|
490
|
+
'devDependencies',
|
|
491
|
+
'optionalDependencies',
|
|
492
|
+
'peerDependencies',
|
|
493
|
+
]) {
|
|
494
|
+
const dependencyGroup = syntheticPackage[dependencyGroupName];
|
|
495
|
+
if (isPlainObject(dependencyGroup) === false) {
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
for (const dependencyEntry of Object.entries(dependencyGroup)) {
|
|
499
|
+
const internalWorkspace = buildOrder.get(dependencyEntry[0]);
|
|
500
|
+
const dependencyValue = dependencyEntry[1];
|
|
501
|
+
if (internalWorkspace === undefined
|
|
502
|
+
|| typeof dependencyValue !== 'string'
|
|
503
|
+
|| dependencyValue.startsWith('workspace:') === false) {
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
const workspaceRange = dependencyValue.slice('workspace:'.length);
|
|
507
|
+
let normalizedDependencyValue = workspaceRange;
|
|
508
|
+
if (workspaceRange === '*'
|
|
509
|
+
|| workspaceRange === '^'
|
|
510
|
+
|| workspaceRange === '~') {
|
|
511
|
+
const internalVersionValue = internalWorkspace['packageJson']['version'];
|
|
512
|
+
if (typeof internalVersionValue !== 'string' || internalVersionValue.trim() === '') {
|
|
513
|
+
throw new Error(`Docker workspace package "${dependencyEntry[0]}" must define a version before "${dependencyValue}" can be normalized for the container build.`);
|
|
514
|
+
}
|
|
515
|
+
normalizedDependencyValue = (workspaceRange === '*') ? internalVersionValue : `${workspaceRange}${internalVersionValue}`;
|
|
516
|
+
}
|
|
517
|
+
Reflect.set(dependencyGroup, dependencyEntry[0], normalizedDependencyValue);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return syntheticPackage;
|
|
521
|
+
}
|
|
522
|
+
static buildDockerfile(template, manifest, buildOrder, rootPackage) {
|
|
523
|
+
const packageManagerValue = rootPackage['packageManager'];
|
|
524
|
+
const packageManagerDescriptor = LibCorepack.parsePackageManager(packageManagerValue);
|
|
525
|
+
const packageManager = (packageManagerDescriptor === undefined) ? 'npm' : packageManagerDescriptor['name'];
|
|
526
|
+
const packageManagerVersion = (packageManagerDescriptor === undefined) ? '' : packageManagerDescriptor['version'];
|
|
527
|
+
const isYarnClassic = packageManager === 'yarn' && packageManagerVersion.startsWith('1.');
|
|
528
|
+
const needsSyntheticWorkspaceManifests = packageManager === 'npm' || isYarnClassic === true;
|
|
529
|
+
const packageManagerConfigCopies = (packageManager === 'yarn' && isYarnClassic === false) ? 'COPY packages/docker/yarnrc.yml ./.yarnrc.yml' : '# This package manager does not need generated build configuration.';
|
|
530
|
+
let installCommand = 'RUN corepack enable npm && npm install';
|
|
531
|
+
let pruneCommand = 'RUN npm prune --omit=dev && npm cache clean --force';
|
|
532
|
+
const buildCommands = [];
|
|
533
|
+
if (packageManager === 'pnpm') {
|
|
534
|
+
installCommand = 'RUN corepack enable pnpm && pnpm install';
|
|
535
|
+
pruneCommand = 'RUN pnpm install --prod';
|
|
536
|
+
}
|
|
537
|
+
else if (packageManager === 'yarn') {
|
|
538
|
+
installCommand = 'RUN corepack enable yarn && yarn install';
|
|
539
|
+
pruneCommand = (isYarnClassic === true) ? 'RUN yarn install --production && yarn cache clean' : 'RUN yarn workspaces focus --all --production';
|
|
540
|
+
}
|
|
541
|
+
for (const workspacePackageEntry of buildOrder) {
|
|
542
|
+
const packageName = workspacePackageEntry[0];
|
|
543
|
+
const packageJson = workspacePackageEntry[1]['packageJson'];
|
|
544
|
+
const scriptsValue = packageJson['scripts'];
|
|
545
|
+
const buildScriptValue = (isPlainObject(scriptsValue) === true) ? scriptsValue['build'] : undefined;
|
|
546
|
+
if (typeof buildScriptValue !== 'string') {
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
const quotedPackageName = Runner.shellQuote(packageName);
|
|
550
|
+
if (packageManager === 'pnpm') {
|
|
551
|
+
buildCommands.push(`RUN pnpm --filter ${quotedPackageName} run build`);
|
|
552
|
+
}
|
|
553
|
+
else if (packageManager === 'yarn') {
|
|
554
|
+
buildCommands.push(`RUN yarn workspace ${quotedPackageName} build`);
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
buildCommands.push(`RUN npm run build --workspace=${quotedPackageName}`);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
const workspaceManifestCopyLines = [];
|
|
561
|
+
const workspaceManifestRestoreLines = [];
|
|
562
|
+
const workspaceSourceCopyLines = [];
|
|
563
|
+
const runtimeAssemblyCommands = [];
|
|
564
|
+
const runtimeCopyLines = new Set();
|
|
565
|
+
const needsNodeRuntime = manifest['workspaces'].some((workspace) => [
|
|
566
|
+
'astro-node',
|
|
567
|
+
'background-service',
|
|
568
|
+
'http-service',
|
|
569
|
+
'nextjs-standalone',
|
|
570
|
+
].includes(workspace['profile']));
|
|
571
|
+
for (const workspacePackageEntry of buildOrder) {
|
|
572
|
+
const workspacePackage = workspacePackageEntry[1];
|
|
573
|
+
const workspaceManifestSourcePath = (needsSyntheticWorkspaceManifests === true) ? `packages/docker/workspace-manifests/${workspacePackage['path']}/package.json` : `${workspacePackage['path']}/package.json`;
|
|
574
|
+
workspaceManifestCopyLines.push(`COPY ${JSON.stringify([
|
|
575
|
+
workspaceManifestSourcePath,
|
|
576
|
+
`${workspacePackage['path']}/package.json`,
|
|
577
|
+
])}`);
|
|
578
|
+
if (needsSyntheticWorkspaceManifests === true) {
|
|
579
|
+
workspaceManifestRestoreLines.push(`COPY ${JSON.stringify([
|
|
580
|
+
workspaceManifestSourcePath,
|
|
581
|
+
`${workspacePackage['path']}/package.json`,
|
|
582
|
+
])}`);
|
|
583
|
+
}
|
|
584
|
+
workspaceSourceCopyLines.push(`COPY ${JSON.stringify([
|
|
585
|
+
workspacePackage['path'],
|
|
586
|
+
workspacePackage['path'],
|
|
587
|
+
])}`);
|
|
588
|
+
}
|
|
589
|
+
if (needsNodeRuntime === true) {
|
|
590
|
+
runtimeAssemblyCommands.push('mkdir -p /runtime', 'cp -a . /runtime/');
|
|
591
|
+
runtimeCopyLines.add('COPY --from=build /runtime/ /app/');
|
|
592
|
+
}
|
|
593
|
+
for (const workspace of manifest['workspaces']) {
|
|
594
|
+
const runtimeWorkspacePath = `/app/${workspace['path']}`;
|
|
595
|
+
if (needsNodeRuntime === true && workspace['profile'] === 'static-site') {
|
|
596
|
+
const runtimeAssemblyWorkspaceServices = manifest['services'].filter((manifestService) => manifestService['workspace'] === workspace['path']);
|
|
597
|
+
for (const service of runtimeAssemblyWorkspaceServices) {
|
|
598
|
+
const runtimeSitePath = `/runtime/sites/${service['name']}`;
|
|
599
|
+
runtimeAssemblyCommands.push(`mkdir -p ${Runner.shellQuote(runtimeSitePath)}`, `cp -a ${Runner.shellQuote(`/workspace/${workspace['path']}/${workspace['buildDirectory']}/.`)} ${Runner.shellQuote(`${runtimeSitePath}/`)}`);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
else if (needsNodeRuntime === true && workspace['profile'] === 'nextjs-standalone') {
|
|
603
|
+
const runtimeAssemblyWorkspacePath = `/runtime/${workspace['path']}`;
|
|
604
|
+
runtimeAssemblyCommands.push(`cp -a ${Runner.shellQuote(`/workspace/${workspace['path']}/${workspace['buildDirectory']}/standalone/.`)} ${Runner.shellQuote(`${runtimeAssemblyWorkspacePath}/`)}`);
|
|
605
|
+
}
|
|
606
|
+
else if (needsNodeRuntime === true) {
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
else if (workspace['profile'] === 'static-site') {
|
|
610
|
+
const workspaceServices = manifest['services'].filter((manifestService) => manifestService['workspace'] === workspace['path']);
|
|
611
|
+
for (const service of workspaceServices) {
|
|
612
|
+
runtimeCopyLines.add(`COPY --from=build /workspace/${workspace['path']}/${workspace['buildDirectory']} /app/sites/${service['name']}`);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
else if (workspace['profile'] === 'container-native') {
|
|
616
|
+
runtimeCopyLines.add(`COPY --from=build /workspace/${workspace['path']} ${runtimeWorkspacePath}`);
|
|
617
|
+
}
|
|
618
|
+
else if (workspace['profile'] === 'nextjs-standalone') {
|
|
619
|
+
runtimeCopyLines.add(`COPY --from=build /workspace/${workspace['path']}/${workspace['buildDirectory']}/standalone ${runtimeWorkspacePath}`);
|
|
620
|
+
runtimeCopyLines.add(`COPY --from=build /workspace/${workspace['path']}/public ${runtimeWorkspacePath}/public`);
|
|
621
|
+
runtimeCopyLines.add(`COPY --from=build /workspace/${workspace['path']}/${workspace['buildDirectory']}/static ${runtimeWorkspacePath}/${workspace['buildDirectory']}/static`);
|
|
622
|
+
}
|
|
623
|
+
else {
|
|
624
|
+
runtimeCopyLines.add(`COPY --from=build /workspace/${workspace['path']}/package.json ${runtimeWorkspacePath}/package.json`);
|
|
625
|
+
runtimeCopyLines.add(`COPY --from=build /workspace/${workspace['path']}/${workspace['buildDirectory']} ${runtimeWorkspacePath}/${workspace['buildDirectory']}`);
|
|
626
|
+
}
|
|
627
|
+
if (workspace['profile'] !== 'container-native') {
|
|
628
|
+
for (const runtimePath of workspace['runtimePaths']) {
|
|
629
|
+
runtimeCopyLines.add(`COPY --from=build /workspace/${workspace['path']}/${runtimePath} ${runtimeWorkspacePath}/${runtimePath}`);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if (needsNodeRuntime === false) {
|
|
634
|
+
for (const workspacePackageEntry of buildOrder) {
|
|
635
|
+
const runtimeWorkspacePackage = workspacePackageEntry[1];
|
|
636
|
+
const isSelectedWorkspace = manifest['workspaces'].some((workspace) => workspace['path'] === runtimeWorkspacePackage['path']);
|
|
637
|
+
if (isSelectedWorkspace === false) {
|
|
638
|
+
runtimeCopyLines.add(`COPY --from=build /workspace/${runtimeWorkspacePackage['path']} /app/${runtimeWorkspacePackage['path']}`);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
const portSet = new Set();
|
|
643
|
+
for (const service of manifest['services']) {
|
|
644
|
+
if (service['port'] !== undefined) {
|
|
645
|
+
portSet.add(service['port']);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
const ports = [...portSet].sort((firstPort, secondPort) => firstPort - secondPort);
|
|
649
|
+
const exposeDirectives = ports.map((port) => `EXPOSE ${port}`).join('\n');
|
|
650
|
+
const runtimeBase = (needsNodeRuntime === true) ? 'node:[__SCAFFOLD_VERSION_DOCKER_NODE__]' : 'debian:[__SCAFFOLD_VERSION_DOCKER_DEBIAN__]';
|
|
651
|
+
const writablePaths = [...new Set(manifest['services'].flatMap((service) => service['writablePaths']))].sort((firstPath, secondPath) => firstPath.localeCompare(secondPath));
|
|
652
|
+
const writableDirectories = (writablePaths.length === 0) ? '# No project writable paths are declared.' : `RUN mkdir -p ${writablePaths.map((writablePath) => Runner.shellQuote(writablePath)).join(' ')}`;
|
|
653
|
+
const runtimeAssembly = (runtimeAssemblyCommands.length === 0) ? '# This appliance does not need a Node.js runtime assembly.' : `RUN ${runtimeAssemblyCommands.join([
|
|
654
|
+
' \\',
|
|
655
|
+
' && ',
|
|
656
|
+
].join('\n'))}`;
|
|
657
|
+
const replacements = {
|
|
658
|
+
'[__DOCKER_BUILD_COMMANDS__]': (buildCommands.length === 0) ? '# No selected workspace declares a build script.' : buildCommands.join('\n'),
|
|
659
|
+
'[__DOCKER_EXPOSE_DIRECTIVES__]': (exposeDirectives === '') ? '# This appliance does not expose a network port.' : exposeDirectives,
|
|
660
|
+
'[__DOCKER_INSTALL_COMMAND__]': installCommand,
|
|
661
|
+
'[__DOCKER_PACKAGE_MANAGER_CONFIG_COPIES__]': packageManagerConfigCopies,
|
|
662
|
+
'[__DOCKER_PRUNE_COMMAND__]': pruneCommand,
|
|
663
|
+
'[__DOCKER_RUNTIME_ASSEMBLY__]': runtimeAssembly,
|
|
664
|
+
'[__DOCKER_RUNTIME_BASE__]': runtimeBase,
|
|
665
|
+
'[__DOCKER_RUNTIME_COPIES__]': [...runtimeCopyLines].join('\n'),
|
|
666
|
+
'[__DOCKER_WORKSPACE_MANIFEST_COPIES__]': workspaceManifestCopyLines.join('\n'),
|
|
667
|
+
'[__DOCKER_WORKSPACE_MANIFEST_RESTORES__]': (workspaceManifestRestoreLines.length === 0) ? '# Workspace manifests already use this package manager\'s native protocol.' : workspaceManifestRestoreLines.join('\n'),
|
|
668
|
+
'[__DOCKER_WORKSPACE_SOURCE_COPIES__]': workspaceSourceCopyLines.join('\n'),
|
|
669
|
+
'[__DOCKER_WRITABLE_DIRECTORIES__]': writableDirectories,
|
|
670
|
+
};
|
|
671
|
+
let content = applyScaffoldVersionReplacements(template);
|
|
672
|
+
for (const replacementEntry of Object.entries(replacements)) {
|
|
673
|
+
content = content.split(replacementEntry[0]).join(replacementEntry[1]);
|
|
674
|
+
}
|
|
675
|
+
return applyScaffoldVersionReplacements(content);
|
|
676
|
+
}
|
|
677
|
+
static buildCompose(template, manifest) {
|
|
678
|
+
const environmentFiles = manifest['workspaces']
|
|
679
|
+
.filter((workspace) => workspace['profile'] === 'background-service')
|
|
680
|
+
.map((workspace) => ` - ./${workspace['path']}/.env`);
|
|
681
|
+
const portSet = new Set();
|
|
682
|
+
for (const service of manifest['services']) {
|
|
683
|
+
if (service['port'] !== undefined) {
|
|
684
|
+
portSet.add(service['port']);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
const ports = [...portSet].sort((firstPort, secondPort) => firstPort - secondPort);
|
|
688
|
+
const portLines = ports.map((port) => ` - "${port}:${port}"`);
|
|
689
|
+
const hasContainerNativeService = manifest['workspaces'].some((workspace) => workspace['profile'] === 'container-native');
|
|
690
|
+
const environmentFileBlock = (environmentFiles.length === 0) ? '' : [
|
|
691
|
+
' env_file:',
|
|
692
|
+
...environmentFiles,
|
|
693
|
+
].join('\n');
|
|
694
|
+
const interactiveBlock = (hasContainerNativeService === true) ? [
|
|
695
|
+
' stdin_open: true',
|
|
696
|
+
' tty: true',
|
|
697
|
+
].join('\n') : '';
|
|
698
|
+
const portBlock = (portLines.length === 0) ? '' : [
|
|
699
|
+
' ports:',
|
|
700
|
+
...portLines,
|
|
701
|
+
].join('\n');
|
|
702
|
+
const replacements = {
|
|
703
|
+
'[__DOCKER_COMPOSE_ENV_FILES__]': environmentFileBlock,
|
|
704
|
+
'[__DOCKER_COMPOSE_INTERACTIVE__]': interactiveBlock,
|
|
705
|
+
'[__DOCKER_COMPOSE_PORTS__]': portBlock,
|
|
706
|
+
};
|
|
707
|
+
let content = template;
|
|
708
|
+
for (const replacementEntry of Object.entries(replacements)) {
|
|
709
|
+
content = content.split(replacementEntry[0]).join(replacementEntry[1]);
|
|
710
|
+
}
|
|
711
|
+
return content;
|
|
712
|
+
}
|
|
713
|
+
static async writeRootfs(rootfsDirectory, manifest) {
|
|
714
|
+
const s6DatabaseDirectory = join(rootfsDirectory, 'etc', 's6-overlay', 's6-rc.d');
|
|
715
|
+
const userBundleDirectory = join(rootfsDirectory, 'etc', 's6-overlay', 'user-bundles.d', 'user', 'contents.d');
|
|
716
|
+
const helperDirectory = join(rootfsDirectory, 'usr', 'local', 'libexec', 'nova-docker');
|
|
717
|
+
const serviceHelperDirectory = join(helperDirectory, 'services');
|
|
718
|
+
const novaConfigDirectory = join(rootfsDirectory, 'etc', 'nova-docker');
|
|
719
|
+
const initServiceDirectory = join(s6DatabaseDirectory, 'nova-container-init');
|
|
720
|
+
const initDependenciesDirectory = join(initServiceDirectory, 'dependencies.d');
|
|
721
|
+
const writablePaths = [...new Set(manifest['services'].flatMap((service) => service['writablePaths']))].sort((firstPath, secondPath) => firstPath.localeCompare(secondPath));
|
|
722
|
+
const shellVariableMarker = '$';
|
|
723
|
+
const criticalFinishScript = [
|
|
724
|
+
'#!/command/with-contenv sh',
|
|
725
|
+
'set -eu',
|
|
726
|
+
`if [ "${shellVariableMarker}{1:-0}" -ne 0 ] || [ "${shellVariableMarker}{2:-0}" -ne 0 ]; then`,
|
|
727
|
+
' exec /run/s6/basedir/bin/halt',
|
|
728
|
+
'fi',
|
|
729
|
+
'exit 0',
|
|
730
|
+
'',
|
|
731
|
+
].join('\n');
|
|
732
|
+
await Promise.all([
|
|
733
|
+
fs.mkdir(userBundleDirectory, { recursive: true }),
|
|
734
|
+
fs.mkdir(serviceHelperDirectory, { recursive: true }),
|
|
735
|
+
fs.mkdir(novaConfigDirectory, { recursive: true }),
|
|
736
|
+
fs.mkdir(initDependenciesDirectory, { recursive: true }),
|
|
76
737
|
]);
|
|
738
|
+
await Promise.all([
|
|
739
|
+
fs.writeFile(join(initServiceDirectory, 'type'), 'oneshot\n', 'utf-8'),
|
|
740
|
+
fs.writeFile(join(initServiceDirectory, 'up'), '/usr/local/libexec/nova-docker/init-user\n', 'utf-8'),
|
|
741
|
+
fs.writeFile(join(initDependenciesDirectory, 'base'), '', 'utf-8'),
|
|
742
|
+
fs.writeFile(join(userBundleDirectory, 'nova-container-init'), '', 'utf-8'),
|
|
743
|
+
Runner.writeExecutable(join(helperDirectory, 'init-user'), Runner.buildInitUser()),
|
|
744
|
+
Runner.writeExecutable(join(helperDirectory, 'healthcheck'), Runner.buildHealthcheck(manifest)),
|
|
745
|
+
fs.writeFile(join(novaConfigDirectory, 'writable-paths'), (writablePaths.length === 0) ? '' : `${writablePaths.join('\n')}\n`, 'utf-8'),
|
|
746
|
+
]);
|
|
747
|
+
for (const service of manifest['services']) {
|
|
748
|
+
const serviceDirectory = join(s6DatabaseDirectory, service['name']);
|
|
749
|
+
const dependenciesDirectory = join(serviceDirectory, 'dependencies.d');
|
|
750
|
+
await fs.mkdir(dependenciesDirectory, { recursive: true });
|
|
751
|
+
await Promise.all([
|
|
752
|
+
fs.writeFile(join(serviceDirectory, 'type'), `${service['kind']}\n`, 'utf-8'),
|
|
753
|
+
fs.writeFile(join(dependenciesDirectory, 'nova-container-init'), '', 'utf-8'),
|
|
754
|
+
fs.writeFile(join(userBundleDirectory, service['name']), '', 'utf-8'),
|
|
755
|
+
]);
|
|
756
|
+
for (const dependency of service['dependencies']) {
|
|
757
|
+
await fs.writeFile(join(dependenciesDirectory, dependency), '', 'utf-8');
|
|
758
|
+
}
|
|
759
|
+
if (service['kind'] === 'oneshot') {
|
|
760
|
+
await Promise.all([
|
|
761
|
+
Runner.writeExecutable(join(serviceHelperDirectory, service['name']), Runner.buildRunScript(service)),
|
|
762
|
+
fs.writeFile(join(serviceDirectory, 'up'), `/usr/local/libexec/nova-docker/services/${service['name']}\n`, 'utf-8'),
|
|
763
|
+
]);
|
|
764
|
+
}
|
|
765
|
+
else {
|
|
766
|
+
await Runner.writeExecutable(join(serviceDirectory, 'run'), Runner.buildRunScript(service));
|
|
767
|
+
if (service['critical'] === true) {
|
|
768
|
+
await Runner.writeExecutable(join(serviceDirectory, 'finish'), criticalFinishScript);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}
|
|
77
772
|
return;
|
|
78
773
|
}
|
|
79
|
-
static
|
|
80
|
-
|
|
81
|
-
|
|
774
|
+
static buildRunScript(service) {
|
|
775
|
+
const lines = [
|
|
776
|
+
'#!/command/with-contenv sh',
|
|
777
|
+
'set -eu',
|
|
778
|
+
];
|
|
779
|
+
const shellVariableMarker = '$';
|
|
780
|
+
lines.push('if [ -f /app/.pnp.cjs ]; then', ` export NODE_OPTIONS="--require=/app/.pnp.cjs${shellVariableMarker}{NODE_OPTIONS:+ ${shellVariableMarker}{NODE_OPTIONS}}"`, 'fi', 'if [ -f /app/.pnp.loader.mjs ]; then', ` export NODE_OPTIONS="--experimental-loader=/app/.pnp.loader.mjs${shellVariableMarker}{NODE_OPTIONS:+ ${shellVariableMarker}{NODE_OPTIONS}}"`, 'fi');
|
|
781
|
+
if (service['command'].includes('/app/sites/') === false) {
|
|
782
|
+
lines.push(`cd ${Runner.shellQuote(`/app/${service['workspace']}`)}`);
|
|
783
|
+
}
|
|
784
|
+
for (const environmentEntry of Object.entries(service['environment']).sort((firstEntry, secondEntry) => firstEntry[0].localeCompare(secondEntry[0]))) {
|
|
785
|
+
lines.push(`export ${environmentEntry[0]}=${Runner.shellQuote(environmentEntry[1])}`);
|
|
82
786
|
}
|
|
787
|
+
if (service['runAsRoot'] === true) {
|
|
788
|
+
lines.push(`exec ${service['command']}`);
|
|
789
|
+
}
|
|
790
|
+
else {
|
|
791
|
+
lines.push(`exec /command/s6-applyuidgid -u "\${PUID:-1000}" -g "\${PGID:-1000}" -G "\${PGID:-1000}" ${service['command']}`);
|
|
792
|
+
}
|
|
793
|
+
return `${lines.join('\n')}\n`;
|
|
794
|
+
}
|
|
795
|
+
static buildInitUser() {
|
|
796
|
+
const shellVariableMarker = '$';
|
|
797
|
+
const protectedWritablePatterns = dockerProtectedWritablePaths.flatMap((protectedPath) => [
|
|
798
|
+
protectedPath,
|
|
799
|
+
`${protectedPath}/*`,
|
|
800
|
+
]).join('|');
|
|
801
|
+
return [
|
|
802
|
+
'#!/command/with-contenv sh',
|
|
803
|
+
'set -eu',
|
|
804
|
+
'',
|
|
805
|
+
`PUID_VALUE="${shellVariableMarker}{PUID:-1000}"`,
|
|
806
|
+
`PGID_VALUE="${shellVariableMarker}{PGID:-1000}"`,
|
|
807
|
+
`TZ_VALUE="${shellVariableMarker}{TZ:-UTC}"`,
|
|
808
|
+
'',
|
|
809
|
+
`case "${shellVariableMarker}{PUID_VALUE}" in`,
|
|
810
|
+
' \'\'|*[!0-9]*) echo \'PUID must be a positive integer.\' >&2; exit 1 ;;',
|
|
811
|
+
'esac',
|
|
812
|
+
`case "${shellVariableMarker}{PGID_VALUE}" in`,
|
|
813
|
+
' \'\'|*[!0-9]*) echo \'PGID must be a positive integer.\' >&2; exit 1 ;;',
|
|
814
|
+
'esac',
|
|
815
|
+
`if [ "${shellVariableMarker}{PUID_VALUE}" -le 0 ] || [ "${shellVariableMarker}{PUID_VALUE}" -gt 2147483647 ]; then`,
|
|
816
|
+
' echo \'PUID must be between 1 and 2147483647.\' >&2',
|
|
817
|
+
' exit 1',
|
|
818
|
+
'fi',
|
|
819
|
+
`if [ "${shellVariableMarker}{PGID_VALUE}" -le 0 ] || [ "${shellVariableMarker}{PGID_VALUE}" -gt 2147483647 ]; then`,
|
|
820
|
+
' echo \'PGID must be between 1 and 2147483647.\' >&2',
|
|
821
|
+
' exit 1',
|
|
822
|
+
'fi',
|
|
823
|
+
'',
|
|
824
|
+
`case "${shellVariableMarker}{TZ_VALUE}" in`,
|
|
825
|
+
' \'\'|/*|*..*) echo \'TZ must name an installed IANA timezone.\' >&2; exit 1 ;;',
|
|
826
|
+
'esac',
|
|
827
|
+
`if [ ! -f "/usr/share/zoneinfo/${shellVariableMarker}{TZ_VALUE}" ]; then`,
|
|
828
|
+
` echo "Unknown timezone: ${shellVariableMarker}{TZ_VALUE}" >&2`,
|
|
829
|
+
' exit 1',
|
|
830
|
+
'fi',
|
|
831
|
+
'',
|
|
832
|
+
'while IFS= read -r writable_path; do',
|
|
833
|
+
` [ -n "${shellVariableMarker}{writable_path}" ] || continue`,
|
|
834
|
+
` case "${shellVariableMarker}{writable_path}" in`,
|
|
835
|
+
' /*) ;;',
|
|
836
|
+
` *) echo "Writable path must be absolute: ${shellVariableMarker}{writable_path}" >&2; exit 1 ;;`,
|
|
837
|
+
' esac',
|
|
838
|
+
` case "${shellVariableMarker}{writable_path}" in`,
|
|
839
|
+
` /|${protectedWritablePatterns}|*/../*|*/./*)`,
|
|
840
|
+
` echo "Unsafe writable path: ${shellVariableMarker}{writable_path}" >&2`,
|
|
841
|
+
' exit 1',
|
|
842
|
+
' ;;',
|
|
843
|
+
' esac',
|
|
844
|
+
` mkdir -p -- "${shellVariableMarker}{writable_path}"`,
|
|
845
|
+
` chown "${shellVariableMarker}{PUID_VALUE}:${shellVariableMarker}{PGID_VALUE}" -- "${shellVariableMarker}{writable_path}"`,
|
|
846
|
+
'done < /etc/nova-docker/writable-paths',
|
|
847
|
+
'',
|
|
848
|
+
].join('\n');
|
|
849
|
+
}
|
|
850
|
+
static buildHealthcheck(manifest) {
|
|
83
851
|
const lines = [
|
|
84
|
-
'
|
|
85
|
-
'
|
|
86
|
-
'
|
|
852
|
+
'#!/bin/sh',
|
|
853
|
+
'set -eu',
|
|
854
|
+
'if [ -x /etc/nova-docker/healthcheck ]; then',
|
|
855
|
+
' exec /etc/nova-docker/healthcheck',
|
|
856
|
+
'fi',
|
|
87
857
|
];
|
|
88
|
-
|
|
858
|
+
const requiredServices = manifest['services'].filter((service) => service['requiredForHealth'] === true);
|
|
859
|
+
for (const service of requiredServices) {
|
|
860
|
+
if (service['kind'] === 'longrun') {
|
|
861
|
+
lines.push(`/command/s6-svstat -u /run/service/${service['name']} >/dev/null`);
|
|
862
|
+
}
|
|
863
|
+
if (service['healthCommand'] !== undefined) {
|
|
864
|
+
lines.push(service['healthCommand']);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
lines.push('exit 0');
|
|
868
|
+
return `${lines.join('\n')}\n`;
|
|
869
|
+
}
|
|
870
|
+
static async writeExecutable(targetPath, content) {
|
|
871
|
+
await fs.mkdir(dirname(targetPath), { recursive: true });
|
|
872
|
+
await fs.writeFile(targetPath, content, 'utf-8');
|
|
873
|
+
await fs.chmod(targetPath, parseInt('755', 8));
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
static buildWorkspacePackage(slug) {
|
|
877
|
+
return {
|
|
878
|
+
name: `${slug}-tool-docker`,
|
|
879
|
+
private: true,
|
|
880
|
+
scripts: {
|
|
881
|
+
check: 'docker build --check --file ../../Dockerfile ../..',
|
|
882
|
+
build: 'docker compose --file ../../compose.yml --project-directory ../.. build',
|
|
883
|
+
},
|
|
884
|
+
type: 'module',
|
|
885
|
+
version: '0.0.0',
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
static buildContainerPackage(rootPackage, assemblyPackageName, buildOrder) {
|
|
889
|
+
const containerPackage = {
|
|
890
|
+
name: `${assemblyPackageName}-build`,
|
|
891
|
+
private: true,
|
|
892
|
+
version: '0.0.0',
|
|
893
|
+
workspaces: [...buildOrder.values()].map((workspacePackage) => workspacePackage['path']),
|
|
894
|
+
};
|
|
895
|
+
for (const inheritedField of [
|
|
896
|
+
'engines',
|
|
897
|
+
'overrides',
|
|
898
|
+
'packageManager',
|
|
899
|
+
'resolutions',
|
|
900
|
+
]) {
|
|
901
|
+
const inheritedValue = rootPackage[inheritedField];
|
|
902
|
+
if (inheritedValue !== undefined) {
|
|
903
|
+
Reflect.set(containerPackage, inheritedField, inheritedValue);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return containerPackage;
|
|
907
|
+
}
|
|
908
|
+
static buildRootPackage(rootPackage, assemblyPackageName) {
|
|
909
|
+
const scriptsValue = rootPackage['scripts'];
|
|
910
|
+
const scripts = {};
|
|
911
|
+
if (scriptsValue !== undefined && isPlainObject(scriptsValue) === false) {
|
|
912
|
+
throw new Error('The root package.json scripts field must contain an object.');
|
|
913
|
+
}
|
|
914
|
+
if (isPlainObject(scriptsValue) === true) {
|
|
915
|
+
for (const scriptEntry of Object.entries(scriptsValue)) {
|
|
916
|
+
if (typeof scriptEntry[1] !== 'string') {
|
|
917
|
+
throw new Error('Every root package.json script must be a string.');
|
|
918
|
+
}
|
|
919
|
+
Reflect.set(scripts, scriptEntry[0], scriptEntry[1]);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
Reflect.set(rootPackage, 'scripts', Runner.mergeScripts(scripts));
|
|
923
|
+
const workspacesValue = rootPackage['workspaces'];
|
|
924
|
+
let isCovered = false;
|
|
925
|
+
if (Array.isArray(workspacesValue) === true) {
|
|
926
|
+
for (const workspacePattern of workspacesValue) {
|
|
927
|
+
const isDockerWorkspace = workspacePattern === dockerAssemblyRelativePath || workspacePattern === dockerConfigWorkspacePath;
|
|
928
|
+
const isPackagesWildcard = workspacePattern === 'packages/*' || workspacePattern === './packages/*';
|
|
929
|
+
if (isDockerWorkspace === true || isPackagesWildcard === true) {
|
|
930
|
+
isCovered = true;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
if (isCovered === false) {
|
|
934
|
+
workspacesValue.push(dockerAssemblyRelativePath);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
else if (isPlainObject(workspacesValue) === true && Array.isArray(workspacesValue['packages']) === true) {
|
|
938
|
+
const packageWorkspaces = workspacesValue['packages'];
|
|
939
|
+
for (const workspacePattern of packageWorkspaces) {
|
|
940
|
+
const packageIsDockerWorkspace = workspacePattern === dockerAssemblyRelativePath || workspacePattern === dockerConfigWorkspacePath;
|
|
941
|
+
const packageIsPackagesWildcard = workspacePattern === 'packages/*' || workspacePattern === './packages/*';
|
|
942
|
+
if (packageIsDockerWorkspace === true || packageIsPackagesWildcard === true) {
|
|
943
|
+
isCovered = true;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
if (isCovered === false) {
|
|
947
|
+
packageWorkspaces.push(dockerAssemblyRelativePath);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
else {
|
|
951
|
+
Reflect.set(rootPackage, 'workspaces', [dockerAssemblyRelativePath]);
|
|
952
|
+
}
|
|
953
|
+
const assemblyDependencyValue = rootPackage['name'];
|
|
954
|
+
if (typeof assemblyDependencyValue === 'string' && assemblyDependencyValue === assemblyPackageName) {
|
|
955
|
+
throw new Error('The root package name conflicts with the private Docker assembly package name.');
|
|
956
|
+
}
|
|
957
|
+
return rootPackage;
|
|
958
|
+
}
|
|
959
|
+
static registerProjectConfig(novaConfig, assemblyPackageName, ignoreFileEntry) {
|
|
960
|
+
const projectValue = novaConfig['project'];
|
|
961
|
+
if (isPlainObject(projectValue) === false) {
|
|
962
|
+
throw new Error('The root nova.config.json project field must contain an object.');
|
|
963
|
+
}
|
|
964
|
+
const platformsValue = projectValue['platforms'];
|
|
965
|
+
const platforms = [];
|
|
966
|
+
if (Array.isArray(platformsValue) === true) {
|
|
967
|
+
for (const platform of platformsValue) {
|
|
968
|
+
if (typeof platform === 'string') {
|
|
969
|
+
platforms.push(platform);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
if (platforms.includes('docker') === false) {
|
|
974
|
+
platforms.push('docker');
|
|
975
|
+
}
|
|
976
|
+
Reflect.set(projectValue, 'platforms', platforms);
|
|
977
|
+
const workspacesValue = novaConfig['workspaces'];
|
|
978
|
+
if (workspacesValue !== undefined && isPlainObject(workspacesValue) === false) {
|
|
979
|
+
throw new Error('The root nova.config.json workspaces field must contain an object.');
|
|
980
|
+
}
|
|
981
|
+
const workspaces = (isPlainObject(workspacesValue) === true) ? workspacesValue : {};
|
|
982
|
+
Reflect.set(workspaces, dockerConfigWorkspacePath, {
|
|
983
|
+
name: assemblyPackageName,
|
|
984
|
+
policy: 'freezable',
|
|
985
|
+
role: 'tool',
|
|
986
|
+
});
|
|
987
|
+
Reflect.set(novaConfig, 'workspaces', workspaces);
|
|
988
|
+
const ignoreFilesValue = novaConfig['ignoreFiles'];
|
|
989
|
+
if (ignoreFilesValue !== undefined && isPlainObject(ignoreFilesValue) === false) {
|
|
990
|
+
throw new Error('The root nova.config.json ignoreFiles field must contain an object.');
|
|
991
|
+
}
|
|
992
|
+
const ignoreFiles = (isPlainObject(ignoreFilesValue) === true) ? ignoreFilesValue : {};
|
|
993
|
+
Reflect.set(ignoreFiles, './.dockerignore', ignoreFileEntry);
|
|
994
|
+
Reflect.set(novaConfig, 'ignoreFiles', ignoreFiles);
|
|
995
|
+
const recipesValue = novaConfig['recipes'];
|
|
996
|
+
if (recipesValue !== undefined && isPlainObject(recipesValue) === false) {
|
|
997
|
+
throw new Error('The root nova.config.json recipes field must contain an object.');
|
|
998
|
+
}
|
|
999
|
+
const recipes = (isPlainObject(recipesValue) === true) ? recipesValue : {};
|
|
1000
|
+
const packageJsonRecipesValue = recipes['package-json'];
|
|
1001
|
+
if (packageJsonRecipesValue !== undefined && isPlainObject(packageJsonRecipesValue) === false) {
|
|
1002
|
+
throw new Error('The root nova.config.json recipes.package-json field must contain an object.');
|
|
1003
|
+
}
|
|
1004
|
+
const packageJsonRecipes = (isPlainObject(packageJsonRecipesValue) === true) ? packageJsonRecipesValue : {};
|
|
1005
|
+
Reflect.set(packageJsonRecipes, dockerConfigWorkspacePath, Runner.buildPackageJsonRecipes());
|
|
1006
|
+
Reflect.set(recipes, 'package-json', packageJsonRecipes);
|
|
1007
|
+
Reflect.set(novaConfig, 'recipes', recipes);
|
|
1008
|
+
const environmentValue = novaConfig['environment'];
|
|
1009
|
+
if (environmentValue !== undefined && isPlainObject(environmentValue) === false) {
|
|
1010
|
+
throw new Error('The root nova.config.json environment field must contain an object.');
|
|
1011
|
+
}
|
|
1012
|
+
const environment = (isPlainObject(environmentValue) === true) ? environmentValue : {};
|
|
1013
|
+
const environmentWorkspacesValue = environment['workspaces'];
|
|
1014
|
+
if (environmentWorkspacesValue !== undefined && isPlainObject(environmentWorkspacesValue) === false) {
|
|
1015
|
+
throw new Error('The root nova.config.json environment.workspaces field must contain an object.');
|
|
1016
|
+
}
|
|
1017
|
+
const environmentWorkspaces = (isPlainObject(environmentWorkspacesValue) === true) ? environmentWorkspacesValue : {};
|
|
1018
|
+
Reflect.set(environmentWorkspaces, dockerConfigWorkspacePath, { prefix: 'DOCKER_' });
|
|
1019
|
+
Reflect.set(environment, 'workspaces', environmentWorkspaces);
|
|
1020
|
+
Reflect.set(novaConfig, 'environment', environment);
|
|
1021
|
+
return normalizeNovaConfigTopLevelOrder(novaConfig);
|
|
1022
|
+
}
|
|
1023
|
+
static buildPackageJsonRecipes() {
|
|
1024
|
+
const recipes = {};
|
|
1025
|
+
for (const recipeName of libItemAllowedRecipes) {
|
|
1026
|
+
Reflect.set(recipes, recipeName, { enabled: true });
|
|
1027
|
+
}
|
|
1028
|
+
Reflect.set(recipes, 'cleanup', {
|
|
1029
|
+
enabled: true,
|
|
1030
|
+
settings: {
|
|
1031
|
+
removeUnknownKeys: true,
|
|
1032
|
+
reorderKeys: true,
|
|
1033
|
+
},
|
|
1034
|
+
});
|
|
1035
|
+
Reflect.set(recipes, 'normalize-dependencies', {
|
|
1036
|
+
enabled: true,
|
|
1037
|
+
settings: {
|
|
1038
|
+
pinDependencyVersions: true,
|
|
1039
|
+
pinDevDependencyVersions: true,
|
|
1040
|
+
},
|
|
1041
|
+
});
|
|
1042
|
+
Reflect.set(recipes, 'sync-environment', {
|
|
1043
|
+
enabled: true,
|
|
1044
|
+
settings: {
|
|
1045
|
+
trackNodeLtsVersions: true,
|
|
1046
|
+
},
|
|
1047
|
+
});
|
|
1048
|
+
return recipes;
|
|
89
1049
|
}
|
|
90
1050
|
static mergeScripts(scripts) {
|
|
91
1051
|
const entries = Object.entries(scripts).filter((scriptEntry) => scriptEntry[0] !== 'deploy' && scriptEntry[0].startsWith('deploy:') === false);
|
|
92
1052
|
const deployEntries = Object.entries(scripts).filter((scriptEntry) => scriptEntry[0] !== 'deploy:container' && scriptEntry[0].startsWith('deploy:') === true);
|
|
93
1053
|
const merged = {};
|
|
94
1054
|
let isDeployInserted = false;
|
|
1055
|
+
const insertDeployScripts = () => {
|
|
1056
|
+
Reflect.set(merged, 'deploy', 'nova utility run-scripts --sequential --node-env production "deploy:*"');
|
|
1057
|
+
Reflect.set(merged, 'deploy:container', 'docker compose up --build --detach');
|
|
1058
|
+
for (const deployEntry of deployEntries) {
|
|
1059
|
+
Reflect.set(merged, deployEntry[0], deployEntry[1]);
|
|
1060
|
+
}
|
|
1061
|
+
isDeployInserted = true;
|
|
1062
|
+
return;
|
|
1063
|
+
};
|
|
95
1064
|
for (const scriptEntry of entries) {
|
|
96
1065
|
if (scriptEntry[0] === 'clean' && isDeployInserted === false) {
|
|
97
|
-
|
|
98
|
-
Reflect.set(merged, 'deploy:container', 'docker compose up --build --detach');
|
|
99
|
-
for (const deployEntry of deployEntries) {
|
|
100
|
-
Reflect.set(merged, deployEntry[0], deployEntry[1]);
|
|
101
|
-
}
|
|
102
|
-
isDeployInserted = true;
|
|
1066
|
+
insertDeployScripts();
|
|
103
1067
|
}
|
|
104
1068
|
Reflect.set(merged, scriptEntry[0], scriptEntry[1]);
|
|
105
1069
|
}
|
|
106
1070
|
if (isDeployInserted === false) {
|
|
107
|
-
|
|
108
|
-
Reflect.set(merged, 'deploy:container', 'docker compose up --build --detach');
|
|
109
|
-
for (const deployEntry of deployEntries) {
|
|
110
|
-
Reflect.set(merged, deployEntry[0], deployEntry[1]);
|
|
111
|
-
}
|
|
1071
|
+
insertDeployScripts();
|
|
112
1072
|
}
|
|
113
1073
|
return merged;
|
|
114
1074
|
}
|
|
1075
|
+
static shellQuote(value) {
|
|
1076
|
+
return `'${value.split('\'').join('\'"\'"\'')}'`;
|
|
1077
|
+
}
|
|
1078
|
+
static validateServiceName(name) {
|
|
1079
|
+
if (LIB_REGEX_PATTERN_SLUG_SIMPLE.test(name) === false) {
|
|
1080
|
+
throw new Error(`Docker service name "${name}" must be a lowercase slug.`);
|
|
1081
|
+
}
|
|
1082
|
+
if (dockerReservedServiceNames.has(name) === true) {
|
|
1083
|
+
throw new Error(`Docker service name "${name}" is reserved for Nova or s6-overlay internals.`);
|
|
1084
|
+
}
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
115
1087
|
}
|
|
116
1088
|
//# sourceMappingURL=docker-packaging.js.map
|