@molecule/api-staging-docker-compose 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,115 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship.
43
+
44
+ "Contribution" shall mean any work of authorship, including the
45
+ original version of the Work and any modifications or additions
46
+ to that Work, that is intentionally submitted to the Licensor for
47
+ inclusion in the Work by the copyright owner or by an individual or
48
+ Legal Entity authorized to submit on behalf of the copyright owner.
49
+
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by the Licensor and
52
+ subsequently incorporated within the Work.
53
+
54
+ 2. Grant of Copyright License. Subject to the terms and conditions of
55
+ this License, each Contributor hereby grants to You a perpetual,
56
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
57
+ copyright license to reproduce, prepare Derivative Works of,
58
+ publicly display, publicly perform, sublicense, and distribute the
59
+ Work and such Derivative Works in Source or Object form.
60
+
61
+ 3. Grant of Patent License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution. You may reproduce and distribute copies of the
68
+ Work or Derivative Works thereof in any medium, with or without
69
+ modifications, and in Source or Object form, provided that You
70
+ meet the following conditions:
71
+
72
+ (a) You must give any other recipients of the Work or
73
+ Derivative Works a copy of this License; and
74
+
75
+ (b) You must cause any modified files to carry prominent notices
76
+ stating that You changed the files; and
77
+
78
+ (c) You must retain, in the Source form of any Derivative Works
79
+ that You distribute, all copyright, patent, trademark, and
80
+ attribution notices from the Source form of the Work,
81
+ excluding those notices that do not pertain to any part of
82
+ the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its
85
+ distribution, then any Derivative Works that You distribute must
86
+ include a readable copy of the attribution notices contained
87
+ within such NOTICE file.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ 6. Trademarks. This License does not grant permission to use the trade
92
+ names, trademarks, service marks, or product names of the Licensor.
93
+
94
+ 7. Disclaimer of Warranty. Unless required by applicable law or
95
+ agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
+
98
+ 8. Limitation of Liability. In no event and under no legal theory shall
99
+ any Contributor be liable to You for damages.
100
+
101
+ 9. Accepting Warranty or Additional Liability.
102
+
103
+ Copyright 2026 Molecule Dev, Inc.
104
+
105
+ Licensed under the Apache License, Version 2.0 (the "License");
106
+ you may not use this file except in compliance with the License.
107
+ You may obtain a copy of the License at
108
+
109
+ http://www.apache.org/licenses/LICENSE-2.0
110
+
111
+ Unless required by applicable law or agreed to in writing, software
112
+ distributed under the License is distributed on an "AS IS" BASIS,
113
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
+ See the License for the specific language governing permissions and
115
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=browser-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-guard.d.ts","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Browser guard — `@molecule/api-staging-docker-compose` is SERVER-ONLY.
3
+ *
4
+ * Generated by scripts/gen-browser-guards.mjs (workspace root) — edit THAT, not this.
5
+ * Evaluating a server package in a browser bundle is always an import-graph mistake
6
+ * (node APIs, secrets); without this guard it surfaces as a cryptic downstream crash
7
+ * ("Buffer is not defined") far from the culprit. Throwing here names the package and
8
+ * the fix at the exact moment the client bundle evaluates it. jsdom tests and SSR are
9
+ * unaffected: the throw requires browser globals AND the absence of a node runtime.
10
+ */
11
+ const g = globalThis;
12
+ if (g.window !== undefined && g.document !== undefined && !g.process?.versions?.node) {
13
+ throw new Error('@molecule/api-staging-docker-compose is SERVER-ONLY: it was bundled into browser/client code. Import it only ' +
14
+ 'from server code (a server route/function or your API), or dynamic-import it inside ' +
15
+ 'the server handler — never from components or shared client modules, and never ' +
16
+ 'polyfill Buffer/process to silence this.');
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=browser-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-guard.js","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,GAAG,UAIT,CAAA;AACD,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACrF,MAAM,IAAI,KAAK,CACb,+GAA+G;QAC7G,sFAAsF;QACtF,iFAAiF;QACjF,0CAA0C,CAC7C,CAAA;AACH,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Docker Compose YAML generator for staging environments.
3
+ *
4
+ * Generates a `docker-compose.staging-{slug}.yml` file tailored to
5
+ * the branch-specific environment.
6
+ *
7
+ * @module
8
+ */
9
+ import type { StagingEnvironment } from '@molecule/api-staging';
10
+ /**
11
+ * Configuration for Docker Compose file generation.
12
+ */
13
+ export interface ComposeGeneratorConfig {
14
+ /** Allocated API port on the host. */
15
+ apiPort: number;
16
+ /** Allocated App port on the host. */
17
+ appPort: number;
18
+ /** Allocated database port on the host. */
19
+ dbPort: number;
20
+ /** Relative path from compose file to the API project root. */
21
+ apiContext?: string;
22
+ /** Relative path from compose file to the App project root. */
23
+ appContext?: string;
24
+ /** Path to generated Dockerfiles directory, relative to the compose file. */
25
+ dockerfilePath?: string;
26
+ }
27
+ /**
28
+ * Generates a Docker Compose YAML string for a staging environment.
29
+ *
30
+ * The API service uses runtime env_file layering (Node.js reads process.env).
31
+ * The App service uses Docker build args for VITE_* variables (Vite inlines
32
+ * them at build time; runtime env vars have no effect on the served bundle).
33
+ *
34
+ * Requires Docker Compose v2.24+ (long-syntax `env_file` with `required:
35
+ * false` — the base `.env` / `.env.staging` layers are OPTIONAL; short syntax
36
+ * hard-fails `up` on any project that doesn't have both files) and BuildKit
37
+ * (`additional_contexts`, which lets the app image copy the generated
38
+ * `nginx.conf` from the staging directory — it is NOT inside the app build
39
+ * context).
40
+ *
41
+ * The `api` and `app` services each define a `healthcheck:` (previously only
42
+ * `db` did) so `health()` can read the real `Health` field from `docker
43
+ * compose ps` instead of treating container `State === 'running'` as
44
+ * healthy — a process that is up but never came up serving (or is
45
+ * crash-looping between polls) used to read as a fully healthy environment.
46
+ * `api`'s probe hits the `/health` route every molecule-scaffolded API
47
+ * server exposes (`server.ts` — this driver already assumes that shape via
48
+ * the hardcoded `node dist/server.js` Dockerfile CMD); `app`'s probe hits the
49
+ * Nginx root, which always serves the built `index.html`.
50
+ *
51
+ * @param env - The staging environment descriptor.
52
+ * @param config - Port and path configuration.
53
+ * @returns A Docker Compose YAML string.
54
+ */
55
+ export declare function generateComposeFile(env: StagingEnvironment, config: ComposeGeneratorConfig): string;
56
+ //# sourceMappingURL=compose-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose-generator.d.ts","sourceRoot":"","sources":["../src/compose-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE/D;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAA;IAEf,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAA;IAEf,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAA;IAEd,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,6EAA6E;IAC7E,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,kBAAkB,EACvB,MAAM,EAAE,sBAAsB,GAC7B,MAAM,CAiGR"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Docker Compose YAML generator for staging environments.
3
+ *
4
+ * Generates a `docker-compose.staging-{slug}.yml` file tailored to
5
+ * the branch-specific environment.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Generates a Docker Compose YAML string for a staging environment.
11
+ *
12
+ * The API service uses runtime env_file layering (Node.js reads process.env).
13
+ * The App service uses Docker build args for VITE_* variables (Vite inlines
14
+ * them at build time; runtime env vars have no effect on the served bundle).
15
+ *
16
+ * Requires Docker Compose v2.24+ (long-syntax `env_file` with `required:
17
+ * false` — the base `.env` / `.env.staging` layers are OPTIONAL; short syntax
18
+ * hard-fails `up` on any project that doesn't have both files) and BuildKit
19
+ * (`additional_contexts`, which lets the app image copy the generated
20
+ * `nginx.conf` from the staging directory — it is NOT inside the app build
21
+ * context).
22
+ *
23
+ * The `api` and `app` services each define a `healthcheck:` (previously only
24
+ * `db` did) so `health()` can read the real `Health` field from `docker
25
+ * compose ps` instead of treating container `State === 'running'` as
26
+ * healthy — a process that is up but never came up serving (or is
27
+ * crash-looping between polls) used to read as a fully healthy environment.
28
+ * `api`'s probe hits the `/health` route every molecule-scaffolded API
29
+ * server exposes (`server.ts` — this driver already assumes that shape via
30
+ * the hardcoded `node dist/server.js` Dockerfile CMD); `app`'s probe hits the
31
+ * Nginx root, which always serves the built `index.html`.
32
+ *
33
+ * @param env - The staging environment descriptor.
34
+ * @param config - Port and path configuration.
35
+ * @returns A Docker Compose YAML string.
36
+ */
37
+ export function generateComposeFile(env, config) {
38
+ const network = `staging-${env.slug}`;
39
+ const volume = `staging-${env.slug}-db`;
40
+ const apiContext = config.apiContext ?? '../../api';
41
+ const appContext = config.appContext ?? '../../app';
42
+ const dockerfilePath = config.dockerfilePath ?? '.';
43
+ return `# Generated by @molecule/api-staging-docker-compose
44
+ # Branch: ${env.branch}
45
+ # Slug: ${env.slug}
46
+ # Created: ${env.createdAt}
47
+
48
+ services:
49
+ api:
50
+ build:
51
+ context: ${apiContext}
52
+ dockerfile: ${dockerfilePath}/Dockerfile.api
53
+ ports:
54
+ - "${config.apiPort}:4000"
55
+ env_file:
56
+ # Base layers are optional — most projects have no .env/.env.staging and
57
+ # docker compose would otherwise refuse to start ("env file ... not found").
58
+ - path: ../../.env
59
+ required: false
60
+ - path: ../../.env.staging
61
+ required: false
62
+ - path: ../../.env.staging.${env.slug}
63
+ required: true
64
+ environment:
65
+ - DATABASE_URL=postgresql://dev:dev@db:5432/molecule
66
+ # PORT must stay 4000 INSIDE the container (the host port mapping and the
67
+ # Dockerfile EXPOSE both target 4000). The branch env file sets
68
+ # PORT=${config.apiPort} for HOST-side tooling; without this override the
69
+ # env_file would make the API listen on ${config.apiPort} inside the
70
+ # container and the "${config.apiPort}:4000" mapping would point at nothing.
71
+ - PORT=4000
72
+ - NODE_ENV=staging
73
+ - STAGING_SLUG=${env.slug}
74
+ - STAGING_BRANCH=${env.branch}
75
+ depends_on:
76
+ db:
77
+ condition: service_healthy
78
+ healthcheck:
79
+ test: ["CMD-SHELL", "wget -qO- http://localhost:4000/health || exit 1"]
80
+ interval: 5s
81
+ timeout: 5s
82
+ retries: 5
83
+ start_period: 10s
84
+ networks:
85
+ - ${network}
86
+
87
+ app:
88
+ build:
89
+ context: ${appContext}
90
+ dockerfile: ${dockerfilePath}/Dockerfile.app
91
+ # The generated nginx.conf lives in the staging dir, NOT in the app build
92
+ # context — expose it as a named context for the Dockerfile's COPY.
93
+ additional_contexts:
94
+ staging: ${dockerfilePath}
95
+ args:
96
+ VITE_API_URL: http://localhost:${config.apiPort}/api
97
+ ports:
98
+ - "${config.appPort}:80"
99
+ healthcheck:
100
+ test: ["CMD-SHELL", "wget -qO- http://localhost:80/ || exit 1"]
101
+ interval: 5s
102
+ timeout: 5s
103
+ retries: 5
104
+ start_period: 5s
105
+ networks:
106
+ - ${network}
107
+
108
+ db:
109
+ image: postgres:16
110
+ ports:
111
+ - "${config.dbPort}:5432"
112
+ environment:
113
+ - POSTGRES_USER=dev
114
+ - POSTGRES_PASSWORD=dev
115
+ - POSTGRES_DB=molecule
116
+ volumes:
117
+ - ${volume}:/var/lib/postgresql/data
118
+ healthcheck:
119
+ test: ["CMD-SHELL", "pg_isready -U dev"]
120
+ interval: 5s
121
+ timeout: 5s
122
+ retries: 5
123
+ networks:
124
+ - ${network}
125
+
126
+ volumes:
127
+ ${volume}:
128
+
129
+ networks:
130
+ ${network}:
131
+ name: ${network}
132
+ `;
133
+ }
134
+ //# sourceMappingURL=compose-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose-generator.js","sourceRoot":"","sources":["../src/compose-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA2BH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAuB,EACvB,MAA8B;IAE9B,MAAM,OAAO,GAAG,WAAW,GAAG,CAAC,IAAI,EAAE,CAAA;IACrC,MAAM,MAAM,GAAG,WAAW,GAAG,CAAC,IAAI,KAAK,CAAA;IACvC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,WAAW,CAAA;IACnD,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,WAAW,CAAA;IACnD,MAAM,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,GAAG,CAAA;IAEnD,OAAO;YACG,GAAG,CAAC,MAAM;UACZ,GAAG,CAAC,IAAI;aACL,GAAG,CAAC,SAAS;;;;;iBAKT,UAAU;oBACP,cAAc;;WAEvB,MAAM,CAAC,OAAO;;;;;;;;mCAQU,GAAG,CAAC,IAAI;;;;;;eAM5B,MAAM,CAAC,OAAO;gDACmB,MAAM,CAAC,OAAO;6BACjC,MAAM,CAAC,OAAO;;;uBAGpB,GAAG,CAAC,IAAI;yBACN,GAAG,CAAC,MAAM;;;;;;;;;;;UAWzB,OAAO;;;;iBAIA,UAAU;oBACP,cAAc;;;;mBAIf,cAAc;;yCAEQ,MAAM,CAAC,OAAO;;WAE5C,MAAM,CAAC,OAAO;;;;;;;;UAQf,OAAO;;;;;WAKN,MAAM,CAAC,MAAM;;;;;;UAMd,MAAM;;;;;;;UAON,OAAO;;;IAGb,MAAM;;;IAGN,OAAO;YACC,OAAO;CAClB,CAAA;AACD,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Dockerfile and Nginx config generators for staging environments.
3
+ *
4
+ * Generates multi-stage Dockerfiles for both API (Node.js) and App
5
+ * (Vite build → Nginx serve) containers, plus an SPA-compatible
6
+ * Nginx configuration.
7
+ *
8
+ * @module
9
+ */
10
+ /**
11
+ * Generates a multi-stage Dockerfile for the API server.
12
+ *
13
+ * Stage 1 (build): installs all deps, compiles TypeScript.
14
+ * Stage 2 (runtime): copies compiled output, installs production deps only.
15
+ *
16
+ * @returns Dockerfile content as a string.
17
+ */
18
+ export declare function generateApiDockerfile(): string;
19
+ /**
20
+ * Generates a multi-stage Dockerfile for the frontend app.
21
+ *
22
+ * Stage 1 (build): installs deps, injects Vite env vars via Docker ARG,
23
+ * then runs the Vite build. ARG → ENV ensures \`process.env.VITE_*\` is
24
+ * available to Vite at build time (takes precedence over .env files).
25
+ *
26
+ * Stage 2 (serve): copies built static assets into Nginx. The nginx.conf is
27
+ * copied from the \`staging\` named build context (the \`.molecule/staging/\`
28
+ * directory, wired via \`additional_contexts\` in the generated compose file) —
29
+ * NOT from the app build context: the app project has no nginx.conf of its
30
+ * own, so a plain \`COPY nginx.conf\` would fail every build with
31
+ * "not found in build context".
32
+ *
33
+ * @param envVars - Build-time environment variables to inject (e.g. \`{ VITE_API_URL: '...' }\`).
34
+ * @returns Dockerfile content as a string.
35
+ */
36
+ export declare function generateAppDockerfile(envVars?: Record<string, string>): string;
37
+ /**
38
+ * Generates an SPA-compatible Nginx configuration.
39
+ *
40
+ * Uses \`try_files\` to serve \`index.html\` for all routes, which is
41
+ * required for client-side routing (React Router, Vue Router, etc.).
42
+ *
43
+ * @returns Nginx config content as a string.
44
+ */
45
+ export declare function generateNginxConf(): string;
46
+ //# sourceMappingURL=dockerfile-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dockerfile-generator.d.ts","sourceRoot":"","sources":["../src/dockerfile-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAiB9C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,MAAM,CAuBlF;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAmB1C"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Dockerfile and Nginx config generators for staging environments.
3
+ *
4
+ * Generates multi-stage Dockerfiles for both API (Node.js) and App
5
+ * (Vite build → Nginx serve) containers, plus an SPA-compatible
6
+ * Nginx configuration.
7
+ *
8
+ * @module
9
+ */
10
+ /**
11
+ * Generates a multi-stage Dockerfile for the API server.
12
+ *
13
+ * Stage 1 (build): installs all deps, compiles TypeScript.
14
+ * Stage 2 (runtime): copies compiled output, installs production deps only.
15
+ *
16
+ * @returns Dockerfile content as a string.
17
+ */
18
+ export function generateApiDockerfile() {
19
+ return `# Generated by @molecule/api-staging-docker-compose
20
+ FROM node:20-alpine AS build
21
+ WORKDIR /app
22
+ COPY package*.json ./
23
+ RUN npm ci
24
+ COPY . .
25
+ RUN npm run build
26
+
27
+ FROM node:20-alpine
28
+ WORKDIR /app
29
+ COPY --from=build /app/package*.json ./
30
+ RUN npm ci --omit=dev
31
+ COPY --from=build /app/dist ./dist
32
+ EXPOSE 4000
33
+ CMD ["node", "dist/server.js"]
34
+ `;
35
+ }
36
+ /**
37
+ * Generates a multi-stage Dockerfile for the frontend app.
38
+ *
39
+ * Stage 1 (build): installs deps, injects Vite env vars via Docker ARG,
40
+ * then runs the Vite build. ARG → ENV ensures \`process.env.VITE_*\` is
41
+ * available to Vite at build time (takes precedence over .env files).
42
+ *
43
+ * Stage 2 (serve): copies built static assets into Nginx. The nginx.conf is
44
+ * copied from the \`staging\` named build context (the \`.molecule/staging/\`
45
+ * directory, wired via \`additional_contexts\` in the generated compose file) —
46
+ * NOT from the app build context: the app project has no nginx.conf of its
47
+ * own, so a plain \`COPY nginx.conf\` would fail every build with
48
+ * "not found in build context".
49
+ *
50
+ * @param envVars - Build-time environment variables to inject (e.g. \`{ VITE_API_URL: '...' }\`).
51
+ * @returns Dockerfile content as a string.
52
+ */
53
+ export function generateAppDockerfile(envVars = {}) {
54
+ const argLines = Object.keys(envVars)
55
+ .map((key) => `ARG ${key}`)
56
+ .join('\n');
57
+ const envLines = Object.keys(envVars)
58
+ .map((key) => `ENV ${key}=$${key}`)
59
+ .join('\n');
60
+ return `# Generated by @molecule/api-staging-docker-compose
61
+ FROM node:20-alpine AS build
62
+ WORKDIR /app
63
+ COPY package*.json ./
64
+ RUN npm ci
65
+ COPY . .
66
+ ${argLines}
67
+ ${envLines}
68
+ RUN npm run build
69
+
70
+ FROM nginx:alpine
71
+ COPY --from=build /app/dist /usr/share/nginx/html
72
+ COPY --from=staging nginx.conf /etc/nginx/conf.d/default.conf
73
+ EXPOSE 80
74
+ `;
75
+ }
76
+ /**
77
+ * Generates an SPA-compatible Nginx configuration.
78
+ *
79
+ * Uses \`try_files\` to serve \`index.html\` for all routes, which is
80
+ * required for client-side routing (React Router, Vue Router, etc.).
81
+ *
82
+ * @returns Nginx config content as a string.
83
+ */
84
+ export function generateNginxConf() {
85
+ return `# Generated by @molecule/api-staging-docker-compose
86
+ server {
87
+ listen 80;
88
+ server_name localhost;
89
+ root /usr/share/nginx/html;
90
+ index index.html;
91
+
92
+ location / {
93
+ try_files $uri $uri/ /index.html;
94
+ }
95
+
96
+ # Cache static assets
97
+ location ~* \\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
98
+ expires 1y;
99
+ add_header Cache-Control "public, immutable";
100
+ }
101
+ }
102
+ `;
103
+ }
104
+ //# sourceMappingURL=dockerfile-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dockerfile-generator.js","sourceRoot":"","sources":["../src/dockerfile-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO;;;;;;;;;;;;;;;CAeR,CAAA;AACD,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,qBAAqB,CAAC,UAAkC,EAAE;IACxE,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;SAClC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC;SAC1B,IAAI,CAAC,IAAI,CAAC,CAAA;IACb,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;SAClC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,GAAG,EAAE,CAAC;SAClC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,OAAO;;;;;;EAMP,QAAQ;EACR,QAAQ;;;;;;;CAOT,CAAA;AACD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO;;;;;;;;;;;;;;;;;CAiBR,CAAA;AACD,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Docker Compose staging driver for molecule.dev.
3
+ *
4
+ * Manages ephemeral staging environments using Docker Compose.
5
+ * Each feature branch gets isolated API, App, and database containers
6
+ * with unique port allocations and networking.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { setProvider } from '@molecule/api-staging'
11
+ * import { provider } from '@molecule/api-staging-docker-compose'
12
+ *
13
+ * setProvider(provider)
14
+ * ```
15
+ *
16
+ * @remarks
17
+ * - Requires Docker Compose v2.24+ and BuildKit: the generated compose file
18
+ * uses long-syntax `env_file` (`required: false` — a project without `.env`
19
+ * or `.env.staging` must still stage) and a named `additional_contexts`
20
+ * build context (the generated `nginx.conf` lives in `.molecule/staging/`,
21
+ * outside the app build context). `checkPrerequisites()` parses `docker
22
+ * compose version` and names `'docker-compose >= 2.24 (found X.Y)'` in
23
+ * `missing` when the installed engine predates this — before `up()` hits
24
+ * the engine's opaque compose parse error.
25
+ * - Inside the containers the API always listens on port 4000 and Postgres on
26
+ * 5432; the allocated `driverMeta` ports (`apiPort`, `appPort`, `dbPort`)
27
+ * are HOST-side mappings only. The branch env file
28
+ * (`.env.staging.<slug>`) intentionally holds the host-side values for
29
+ * tooling run outside Docker — the compose `environment:` block overrides
30
+ * `PORT`/`DATABASE_URL` back to the in-container values.
31
+ * - When `env.driverMeta` has no port overrides (direct provider callers
32
+ * only — `mlcl stage up` always allocates real ports via `allocatePort()`),
33
+ * `up()` derives `apiPort`/`appPort`/`dbPort` deterministically from
34
+ * `env.slug` (`fallbackPort()`) instead of three fixed ports, so two
35
+ * concurrently-staged slugs don't collide on identical ports.
36
+ * - `health()` reads the REAL `Health` field from `docker compose ps` for the
37
+ * `api` and `app` services (both now define a `healthcheck:` hitting
38
+ * `/health` and `/` respectively) — a booted-but-not-yet-serving or
39
+ * crash-looping container no longer reads as healthy just because its
40
+ * process state is `running`. `logs()` still needs a look for WHY an
41
+ * unhealthy service is unhealthy.
42
+ * - `logs({ follow: true })` throws — this provider returns a single
43
+ * `Promise<EnvironmentLogs>` snapshot, not a stream, so `follow` cannot be
44
+ * honored; it is rejected explicitly instead of silently returning a
45
+ * static tail.
46
+ * - Environments live on the machine that ran `up()` (containers + state are
47
+ * local) — running this driver on an ephemeral CI runner produces an
48
+ * environment that dies with the job.
49
+ *
50
+ * @module
51
+ */
52
+ export * from './browser-guard.js';
53
+ export * from './compose-generator.js';
54
+ export * from './dockerfile-generator.js';
55
+ export * from './provider.js';
56
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAGH,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AAGzC,cAAc,eAAe,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Docker Compose staging driver for molecule.dev.
3
+ *
4
+ * Manages ephemeral staging environments using Docker Compose.
5
+ * Each feature branch gets isolated API, App, and database containers
6
+ * with unique port allocations and networking.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { setProvider } from '@molecule/api-staging'
11
+ * import { provider } from '@molecule/api-staging-docker-compose'
12
+ *
13
+ * setProvider(provider)
14
+ * ```
15
+ *
16
+ * @remarks
17
+ * - Requires Docker Compose v2.24+ and BuildKit: the generated compose file
18
+ * uses long-syntax `env_file` (`required: false` — a project without `.env`
19
+ * or `.env.staging` must still stage) and a named `additional_contexts`
20
+ * build context (the generated `nginx.conf` lives in `.molecule/staging/`,
21
+ * outside the app build context). `checkPrerequisites()` parses `docker
22
+ * compose version` and names `'docker-compose >= 2.24 (found X.Y)'` in
23
+ * `missing` when the installed engine predates this — before `up()` hits
24
+ * the engine's opaque compose parse error.
25
+ * - Inside the containers the API always listens on port 4000 and Postgres on
26
+ * 5432; the allocated `driverMeta` ports (`apiPort`, `appPort`, `dbPort`)
27
+ * are HOST-side mappings only. The branch env file
28
+ * (`.env.staging.<slug>`) intentionally holds the host-side values for
29
+ * tooling run outside Docker — the compose `environment:` block overrides
30
+ * `PORT`/`DATABASE_URL` back to the in-container values.
31
+ * - When `env.driverMeta` has no port overrides (direct provider callers
32
+ * only — `mlcl stage up` always allocates real ports via `allocatePort()`),
33
+ * `up()` derives `apiPort`/`appPort`/`dbPort` deterministically from
34
+ * `env.slug` (`fallbackPort()`) instead of three fixed ports, so two
35
+ * concurrently-staged slugs don't collide on identical ports.
36
+ * - `health()` reads the REAL `Health` field from `docker compose ps` for the
37
+ * `api` and `app` services (both now define a `healthcheck:` hitting
38
+ * `/health` and `/` respectively) — a booted-but-not-yet-serving or
39
+ * crash-looping container no longer reads as healthy just because its
40
+ * process state is `running`. `logs()` still needs a look for WHY an
41
+ * unhealthy service is unhealthy.
42
+ * - `logs({ follow: true })` throws — this provider returns a single
43
+ * `Promise<EnvironmentLogs>` snapshot, not a stream, so `follow` cannot be
44
+ * honored; it is rejected explicitly instead of silently returning a
45
+ * static tail.
46
+ * - Environments live on the machine that ran `up()` (containers + state are
47
+ * local) — running this driver on an ephemeral CI runner produces an
48
+ * environment that dies with the job.
49
+ *
50
+ * @module
51
+ */
52
+ // Compose generator
53
+ export * from './browser-guard.js';
54
+ export * from './compose-generator.js';
55
+ export * from './dockerfile-generator.js';
56
+ // Provider exports
57
+ export * from './provider.js';
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,oBAAoB;AACpB,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AAEzC,mBAAmB;AACnB,cAAc,eAAe,CAAA"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Docker Compose staging driver.
3
+ *
4
+ * Implements the `StagingDriver` interface using Docker Compose to manage
5
+ * local ephemeral staging environments. Each branch gets isolated containers,
6
+ * networking, and database volumes.
7
+ *
8
+ * @module
9
+ */
10
+ import type { StagingDriver } from '@molecule/api-staging';
11
+ /**
12
+ * Parses a major.minor pair out of `docker compose version` output (e.g.
13
+ * `'Docker Compose version v2.24.5'` or the bare `'2.24.5'` from `--short`).
14
+ * Exported for testing — no need to shell out to `docker` to verify the
15
+ * parsing logic against every version-string shape Compose has printed.
16
+ *
17
+ * @param output - Raw stdout from `docker compose version`.
18
+ * @returns The parsed `{ major, minor }`, or `null` if no version substring is found.
19
+ */
20
+ export declare function parseComposeVersion(output: string): {
21
+ major: number;
22
+ minor: number;
23
+ } | null;
24
+ /**
25
+ * Checks a parsed Compose version against {@link REQUIRED_COMPOSE_VERSION}.
26
+ *
27
+ * @param version - A parsed `{ major, minor }` version.
28
+ * @returns `true` if the version meets or exceeds the minimum this driver requires.
29
+ */
30
+ export declare function isComposeVersionSufficient(version: {
31
+ major: number;
32
+ minor: number;
33
+ }): boolean;
34
+ /**
35
+ * Deterministically derives a fallback host port from an environment slug so
36
+ * that TWO environments falling back to this path (no `driverMeta` — direct
37
+ * provider callers only; `mlcl stage up` always allocates real ports via
38
+ * `allocatePort()`) don't collide on the SAME fixed port. Uses FNV-1a, a
39
+ * stable, dependency-free 32-bit hash — the same slug always maps to the same
40
+ * port across repeated `up()` calls, so redeploying an existing slug doesn't
41
+ * relocate it.
42
+ *
43
+ * @param base - The base port for this role (api/app/db).
44
+ * @param slug - The environment slug to derive an offset from.
45
+ * @param range - Width of the offset window (default 100 — kept narrow enough
46
+ * that api/app/db's offset windows never overlap each other).
47
+ * @returns `base` plus a slug-derived offset in `[0, range)`.
48
+ */
49
+ export declare function fallbackPort(base: number, slug: string, range?: number): number;
50
+ /** A single service row parsed from `docker compose ps --format json`. */
51
+ export interface ComposeContainerStatus {
52
+ Service: string;
53
+ State: string;
54
+ Health: string;
55
+ }
56
+ /**
57
+ * Determines whether a parsed `docker compose ps` container row counts as
58
+ * healthy. `generateComposeFile()` now defines a `healthcheck:` for the `api`
59
+ * AND `app` services (it always did for `db`), so `Health` is populated for
60
+ * both — `State === 'running'` alone used to be treated as healthy, which is
61
+ * also true of a process that is up but never came up serving (or is
62
+ * crash-looping between polls). Falls back to `State === 'running'` only for
63
+ * a container with NO healthcheck (an environment staged with a compose file
64
+ * generated before this fix, or a hand-edited one) — an empty `Health`
65
+ * string is how `docker compose ps` reports "no healthcheck defined".
66
+ *
67
+ * @param container - The parsed container row, or `undefined` if the service wasn't found.
68
+ * @returns `true` if the container is healthy.
69
+ */
70
+ export declare function isContainerHealthy(container?: ComposeContainerStatus): boolean;
71
+ /**
72
+ * Returns the human-readable status for a parsed `docker compose ps`
73
+ * container row — the `Health` value when a healthcheck is defined,
74
+ * otherwise the raw container `State`, or `'not found'` when the service
75
+ * isn't running at all.
76
+ *
77
+ * @param container - The parsed container row, or `undefined` if the service wasn't found.
78
+ * @returns The status string.
79
+ */
80
+ export declare function containerStatus(container?: ComposeContainerStatus): string;
81
+ /**
82
+ * Docker Compose staging driver implementation.
83
+ */
84
+ export declare const provider: StagingDriver;
85
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,OAAO,KAAK,EAIV,aAAa,EAGd,MAAM,uBAAuB,CAAA;AAgB9B;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAI3F;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAK7F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,MAAY,GAAG,MAAM,CAOpF;AAED,0EAA0E;AAC1E,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAK9E;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,SAAS,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAE1E;AA+CD;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,aAiQtB,CAAA"}
@@ -0,0 +1,351 @@
1
+ /**
2
+ * Docker Compose staging driver.
3
+ *
4
+ * Implements the `StagingDriver` interface using Docker Compose to manage
5
+ * local ephemeral staging environments. Each branch gets isolated containers,
6
+ * networking, and database volumes.
7
+ *
8
+ * @module
9
+ */
10
+ import { exec } from 'node:child_process';
11
+ import { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
12
+ import { join } from 'node:path';
13
+ import { promisify } from 'node:util';
14
+ import { generateComposeFile } from './compose-generator.js';
15
+ import { generateApiDockerfile, generateAppDockerfile, generateNginxConf, } from './dockerfile-generator.js';
16
+ const execAsync = promisify(exec);
17
+ const STAGING_DIR = '.molecule/staging';
18
+ /** Minimum Docker Compose version this driver's generated files require. */
19
+ const REQUIRED_COMPOSE_VERSION = { major: 2, minor: 24 };
20
+ /**
21
+ * Parses a major.minor pair out of `docker compose version` output (e.g.
22
+ * `'Docker Compose version v2.24.5'` or the bare `'2.24.5'` from `--short`).
23
+ * Exported for testing — no need to shell out to `docker` to verify the
24
+ * parsing logic against every version-string shape Compose has printed.
25
+ *
26
+ * @param output - Raw stdout from `docker compose version`.
27
+ * @returns The parsed `{ major, minor }`, or `null` if no version substring is found.
28
+ */
29
+ export function parseComposeVersion(output) {
30
+ const match = output.match(/v?(\d+)\.(\d+)\.(\d+)/);
31
+ if (!match)
32
+ return null;
33
+ return { major: Number(match[1]), minor: Number(match[2]) };
34
+ }
35
+ /**
36
+ * Checks a parsed Compose version against {@link REQUIRED_COMPOSE_VERSION}.
37
+ *
38
+ * @param version - A parsed `{ major, minor }` version.
39
+ * @returns `true` if the version meets or exceeds the minimum this driver requires.
40
+ */
41
+ export function isComposeVersionSufficient(version) {
42
+ if (version.major !== REQUIRED_COMPOSE_VERSION.major) {
43
+ return version.major > REQUIRED_COMPOSE_VERSION.major;
44
+ }
45
+ return version.minor >= REQUIRED_COMPOSE_VERSION.minor;
46
+ }
47
+ /**
48
+ * Deterministically derives a fallback host port from an environment slug so
49
+ * that TWO environments falling back to this path (no `driverMeta` — direct
50
+ * provider callers only; `mlcl stage up` always allocates real ports via
51
+ * `allocatePort()`) don't collide on the SAME fixed port. Uses FNV-1a, a
52
+ * stable, dependency-free 32-bit hash — the same slug always maps to the same
53
+ * port across repeated `up()` calls, so redeploying an existing slug doesn't
54
+ * relocate it.
55
+ *
56
+ * @param base - The base port for this role (api/app/db).
57
+ * @param slug - The environment slug to derive an offset from.
58
+ * @param range - Width of the offset window (default 100 — kept narrow enough
59
+ * that api/app/db's offset windows never overlap each other).
60
+ * @returns `base` plus a slug-derived offset in `[0, range)`.
61
+ */
62
+ export function fallbackPort(base, slug, range = 100) {
63
+ let hash = 0x811c9dc5;
64
+ for (let i = 0; i < slug.length; i++) {
65
+ hash ^= slug.charCodeAt(i);
66
+ hash = Math.imul(hash, 0x01000193);
67
+ }
68
+ return base + ((hash >>> 0) % range);
69
+ }
70
+ /**
71
+ * Determines whether a parsed `docker compose ps` container row counts as
72
+ * healthy. `generateComposeFile()` now defines a `healthcheck:` for the `api`
73
+ * AND `app` services (it always did for `db`), so `Health` is populated for
74
+ * both — `State === 'running'` alone used to be treated as healthy, which is
75
+ * also true of a process that is up but never came up serving (or is
76
+ * crash-looping between polls). Falls back to `State === 'running'` only for
77
+ * a container with NO healthcheck (an environment staged with a compose file
78
+ * generated before this fix, or a hand-edited one) — an empty `Health`
79
+ * string is how `docker compose ps` reports "no healthcheck defined".
80
+ *
81
+ * @param container - The parsed container row, or `undefined` if the service wasn't found.
82
+ * @returns `true` if the container is healthy.
83
+ */
84
+ export function isContainerHealthy(container) {
85
+ return (container !== undefined &&
86
+ (container.Health ? container.Health === 'healthy' : container.State === 'running'));
87
+ }
88
+ /**
89
+ * Returns the human-readable status for a parsed `docker compose ps`
90
+ * container row — the `Health` value when a healthcheck is defined,
91
+ * otherwise the raw container `State`, or `'not found'` when the service
92
+ * isn't running at all.
93
+ *
94
+ * @param container - The parsed container row, or `undefined` if the service wasn't found.
95
+ * @returns The status string.
96
+ */
97
+ export function containerStatus(container) {
98
+ return container === undefined ? 'not found' : container.Health || container.State;
99
+ }
100
+ /**
101
+ * Returns the compose file path for an environment.
102
+ *
103
+ * @param projectPath - Absolute project root path.
104
+ * @param slug - Environment slug.
105
+ * @returns Absolute path to the compose file.
106
+ */
107
+ function composeFilePath(projectPath, slug) {
108
+ return join(projectPath, STAGING_DIR, `docker-compose.staging-${slug}.yml`);
109
+ }
110
+ /**
111
+ * Returns the Docker Compose project name for an environment.
112
+ *
113
+ * @param slug - Environment slug.
114
+ * @returns The project name.
115
+ */
116
+ function projectName(slug) {
117
+ return `molecule-staging-${slug}`;
118
+ }
119
+ /**
120
+ * Runs a docker compose command for a staging environment.
121
+ *
122
+ * @param projectPath - Absolute project root path.
123
+ * @param slug - Environment slug.
124
+ * @param command - The docker compose subcommand (e.g. 'up -d', 'down').
125
+ * @returns The command output.
126
+ */
127
+ async function compose(projectPath, slug, command) {
128
+ const file = composeFilePath(projectPath, slug);
129
+ return execAsync(`docker compose -f "${file}" -p "${projectName(slug)}" ${command}`, {
130
+ cwd: projectPath,
131
+ // exec's default maxBuffer is 1 MB — a cold `up -d --build` (npm ci + vite
132
+ // build inside the images) easily exceeds that, and exceeding it KILLS the
133
+ // child mid-build with "maxBuffer length exceeded", which reads like a
134
+ // build failure. Give compose output generous headroom.
135
+ maxBuffer: 64 * 1024 * 1024,
136
+ });
137
+ }
138
+ /**
139
+ * Docker Compose staging driver implementation.
140
+ */
141
+ export const provider = {
142
+ name: 'docker-compose',
143
+ async checkPrerequisites() {
144
+ const missing = [];
145
+ try {
146
+ await execAsync('docker --version');
147
+ }
148
+ catch (_error) {
149
+ // docker not found — prerequisite check adds it to missing list
150
+ missing.push('docker');
151
+ }
152
+ try {
153
+ const { stdout } = await execAsync('docker compose version');
154
+ const version = parseComposeVersion(stdout);
155
+ // An unparseable version string is NOT treated as insufficient — the
156
+ // command succeeded (the plugin exists), and failing open avoids a
157
+ // false-positive block on an unexpected output format. A genuinely too
158
+ // old engine parses fine (Compose has always printed a semver) and is
159
+ // named explicitly here so `up`'s opaque compose parse error (from the
160
+ // long-syntax `env_file` + BuildKit `additional_contexts` this driver's
161
+ // generated files require) never has to be the first signal.
162
+ if (version && !isComposeVersionSufficient(version)) {
163
+ missing.push(`docker-compose >= ${REQUIRED_COMPOSE_VERSION.major}.${REQUIRED_COMPOSE_VERSION.minor} (found ${version.major}.${version.minor})`);
164
+ }
165
+ }
166
+ catch (_error) {
167
+ // docker compose plugin not found — prerequisite check adds it to missing list
168
+ missing.push('docker-compose');
169
+ }
170
+ return { met: missing.length === 0, missing };
171
+ },
172
+ async up(env, config) {
173
+ const stagingDir = join(config.projectPath, STAGING_DIR);
174
+ await mkdir(stagingDir, { recursive: true });
175
+ // Determine ports from environment driverMeta, or derive a fallback
176
+ // deterministically from the slug — see fallbackPort() for why this beats
177
+ // a fixed default (every direct-caller environment used to collide on
178
+ // literally the same three ports).
179
+ const apiPort = env.driverMeta?.apiPort ?? fallbackPort(4001, env.slug);
180
+ const appPort = env.driverMeta?.appPort ?? fallbackPort(5174, env.slug);
181
+ const dbPort = env.driverMeta?.dbPort ?? fallbackPort(5433, env.slug);
182
+ // Generate Dockerfiles and nginx config in .molecule/staging/
183
+ await writeFile(join(stagingDir, 'Dockerfile.api'), generateApiDockerfile());
184
+ await writeFile(join(stagingDir, 'Dockerfile.app'), generateAppDockerfile({ VITE_API_URL: `http://localhost:${apiPort}/api` }));
185
+ await writeFile(join(stagingDir, 'nginx.conf'), generateNginxConf());
186
+ // Generate compose file (references the generated Dockerfiles)
187
+ const composeContent = generateComposeFile(env, {
188
+ apiPort,
189
+ appPort,
190
+ dbPort,
191
+ dockerfilePath: stagingDir,
192
+ });
193
+ await writeFile(composeFilePath(config.projectPath, env.slug), composeContent);
194
+ // Generate branch-specific .env file (API runtime vars only — Vite vars
195
+ // are injected as Docker build args, not runtime env vars).
196
+ // PORT/DATABASE_URL here are the HOST-side view (host port mapping, host
197
+ // dbPort) for tooling run outside Docker (migrations, smoke scripts). The
198
+ // same file is also layered into the api container via env_file, so the
199
+ // compose file's `environment:` block overrides both back to the
200
+ // in-container values (PORT=4000, DATABASE_URL=...@db:5432) — compose
201
+ // gives `environment:` precedence over `env_file:`.
202
+ const envContent = [
203
+ `# Auto-generated by mlcl stage up`,
204
+ `# Branch: ${env.branch}`,
205
+ `# Slug: ${env.slug}`,
206
+ `NODE_ENV=staging`,
207
+ `PORT=${apiPort}`,
208
+ `DATABASE_URL=postgresql://dev:dev@localhost:${dbPort}/molecule`,
209
+ `STAGING_SLUG=${env.slug}`,
210
+ `STAGING_BRANCH=${env.branch}`,
211
+ '',
212
+ ].join('\n');
213
+ await writeFile(join(config.projectPath, `.env.staging.${env.slug}`), envContent);
214
+ // Start containers
215
+ await compose(config.projectPath, env.slug, 'up -d --build');
216
+ return {
217
+ api: `http://localhost:${apiPort}`,
218
+ app: `http://localhost:${appPort}`,
219
+ };
220
+ },
221
+ async down(env, config) {
222
+ try {
223
+ await compose(config.projectPath, env.slug, 'down -v');
224
+ }
225
+ catch (_error) {
226
+ // Containers may already be stopped — not an error
227
+ }
228
+ const stagingDir = join(config.projectPath, STAGING_DIR);
229
+ // Clean up this environment's own files (best-effort)
230
+ const filesToRemove = [
231
+ composeFilePath(config.projectPath, env.slug),
232
+ join(config.projectPath, `.env.staging.${env.slug}`),
233
+ ];
234
+ // Dockerfile.api / Dockerfile.app / nginx.conf are SHARED by every
235
+ // environment's compose file — deleting them while another environment is
236
+ // still up breaks that environment's next rebuild. Only remove them once
237
+ // no other environment's compose file remains.
238
+ let composeFilesLeft = [];
239
+ try {
240
+ const { readdir } = await import('node:fs/promises');
241
+ composeFilesLeft = (await readdir(stagingDir)).filter((f) => f.startsWith('docker-compose.staging-') &&
242
+ f.endsWith('.yml') &&
243
+ f !== `docker-compose.staging-${env.slug}.yml`);
244
+ }
245
+ catch (_error) {
246
+ // Staging dir already gone — nothing shared left to preserve
247
+ }
248
+ if (composeFilesLeft.length === 0) {
249
+ filesToRemove.push(join(stagingDir, 'Dockerfile.api'), join(stagingDir, 'Dockerfile.app'), join(stagingDir, 'nginx.conf'));
250
+ }
251
+ for (const filePath of filesToRemove) {
252
+ try {
253
+ await rm(filePath);
254
+ }
255
+ catch (_error) {
256
+ // File may not exist — safe to ignore
257
+ }
258
+ }
259
+ },
260
+ async health(env, config) {
261
+ try {
262
+ const { stdout } = await compose(config.projectPath, env.slug, 'ps --format json');
263
+ // Parse container status
264
+ const containers = stdout
265
+ .trim()
266
+ .split('\n')
267
+ .filter(Boolean)
268
+ .map((line) => {
269
+ try {
270
+ return JSON.parse(line);
271
+ }
272
+ catch (_error) {
273
+ // Malformed JSON line from docker compose ps — skip it
274
+ return null;
275
+ }
276
+ })
277
+ .filter(Boolean);
278
+ const apiContainer = containers.find((c) => c.Service === 'api');
279
+ const appContainer = containers.find((c) => c.Service === 'app');
280
+ return {
281
+ healthy: isContainerHealthy(apiContainer) && isContainerHealthy(appContainer),
282
+ api: { status: containerStatus(apiContainer) },
283
+ app: { status: containerStatus(appContainer) },
284
+ };
285
+ }
286
+ catch (_error) {
287
+ // docker compose ps failed (e.g. no containers running) — return degraded health
288
+ return {
289
+ healthy: false,
290
+ api: { status: 'unreachable' },
291
+ app: { status: 'unreachable' },
292
+ };
293
+ }
294
+ },
295
+ async logs(env, config, options) {
296
+ if (options?.follow) {
297
+ // The core StagingDriver interface accepts `follow`, but this provider
298
+ // returns a single Promise<EnvironmentLogs> snapshot — there is no
299
+ // streaming channel to honor it on. Silently returning a static tail
300
+ // (the old behavior) left a caller who asked to follow logs staring at
301
+ // a snapshot with no signal that follow never happened. Reject
302
+ // explicitly instead so the unsupported option is a loud, named error
303
+ // rather than a silent downgrade.
304
+ throw new Error("@molecule/api-staging-docker-compose: logs({ follow: true }) is not supported — this driver returns a single log snapshot, not a stream. Omit 'follow' (or poll logs()) to get the current tail.");
305
+ }
306
+ const service = options?.service ?? 'all';
307
+ const tail = options?.tail ?? 100;
308
+ const serviceArg = service === 'all' ? '' : ` ${service}`;
309
+ const { stdout } = await compose(config.projectPath, env.slug, `logs --tail ${tail}${serviceArg}`);
310
+ return {
311
+ lines: stdout.split('\n').filter(Boolean),
312
+ service,
313
+ };
314
+ },
315
+ async list(config) {
316
+ const stagingDir = join(config.projectPath, STAGING_DIR);
317
+ const { readdir } = await import('node:fs/promises');
318
+ try {
319
+ await access(stagingDir);
320
+ }
321
+ catch (_error) {
322
+ // Staging directory does not exist yet — no environments to list
323
+ return [];
324
+ }
325
+ const files = await readdir(stagingDir);
326
+ const composeFiles = files.filter((f) => f.startsWith('docker-compose.staging-') && f.endsWith('.yml'));
327
+ const environments = [];
328
+ for (const file of composeFiles) {
329
+ const content = await readFile(join(stagingDir, file), 'utf-8');
330
+ const branchMatch = content.match(/^# Branch: (.+)$/m);
331
+ const slugMatch = content.match(/^# Slug: (.+)$/m);
332
+ const createdMatch = content.match(/^# Created: (.+)$/m);
333
+ // The filename is the authoritative slug (up() derives both from
334
+ // env.slug). Header comments are only metadata: if a user hand-edited
335
+ // the file and stripped them, the environment must NOT silently vanish
336
+ // from list() while its containers keep running.
337
+ const fileSlug = file.slice('docker-compose.staging-'.length, -'.yml'.length);
338
+ const slug = slugMatch?.[1] ?? fileSlug;
339
+ environments.push({
340
+ slug,
341
+ branch: branchMatch?.[1] ?? slug,
342
+ type: 'staging',
343
+ name: `staging-${slug}`,
344
+ createdAt: createdMatch?.[1] ?? '',
345
+ driver: 'docker-compose',
346
+ });
347
+ }
348
+ return environments;
349
+ },
350
+ };
351
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACzE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAA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AC,mBAAmB,CAAC,CAAA;YACtD,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;YAClD,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAA;YAExD,iEAAiE;YACjE,sEAAsE;YACtE,uEAAuE;YACvE,iDAAiD;YACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAC7E,MAAM,IAAI,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAA;YAEvC,YAAY,CAAC,IAAI,CAAC;gBAChB,IAAI;gBACJ,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI;gBAChC,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,WAAW,IAAI,EAAE;gBACvB,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE;gBAClC,MAAM,EAAE,gBAAgB;aACzB,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,YAAY,CAAA;IACrB,CAAC;CACF,CAAA"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@molecule/api-staging-docker-compose",
3
+ "version": "1.0.0",
4
+ "description": "Docker Compose staging driver for local ephemeral environments in molecule.dev",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "molecule",
24
+ "staging",
25
+ "docker",
26
+ "docker-compose"
27
+ ],
28
+ "license": "Apache-2.0",
29
+ "peerDependencies": {
30
+ "@molecule/api-staging": "^1.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@molecule/api-staging": "1.0.0",
34
+ "@types/node": "26.1.2",
35
+ "typescript": "6.0.3",
36
+ "vitest": "4.1.10"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/molecule-dev/molecule.git",
41
+ "directory": "packages/api/staging/docker-compose"
42
+ },
43
+ "homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/api/staging/docker-compose",
44
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
45
+ "publishConfig": {
46
+ "access": "public"
47
+ }
48
+ }