Skip to content

Commit 0ab7d06

Browse files
authored
feat(run-e2e): pipe runtime logs to parent process (#662)
2 parents df591d2 + a358387 commit 0ab7d06

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

automation/run-e2e/lib/docker-utils.mjs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { execSync } from "node:child_process";
1+
import { execSync, spawn } from "node:child_process";
22
import p from "node:path";
33
import { fileURLToPath } from "node:url";
44
import fetch from "node-fetch";
@@ -102,24 +102,39 @@ export async function startRuntime(mxruntimeImage, mendixVersion, ip, freePort)
102102
console.log(`Start mxruntime image`);
103103

104104
const dockerDir = fileURLToPath(new URL("../docker", import.meta.url));
105+
const labelPrefix = "e2e.mxruntime";
106+
const labelValue = Math.round(Math.random() * (999 - 100)) + 100;
107+
const containerLabel = `${labelPrefix}=${labelValue}`;
105108
const args = [
109+
`run`,
106110
`--tty`,
107-
// Spin mxruntime in background, we will kill it later.
108-
`--detach`,
109-
`--workdir /source`,
110-
`--publish ${freePort}:8080`,
111-
`--env MENDIX_VERSION=${mendixVersion}`,
112-
`--entrypoint /bin/bash`,
113-
`--volume ${process.cwd()}:/source`,
111+
[`--workdir`, `/source`],
112+
[`--publish`, `${freePort}:8080`],
113+
[`--env`, `MENDIX_VERSION=${mendixVersion}`],
114+
[`--entrypoint`, `/bin/bash`],
115+
[`--volume`, `${process.cwd()}:/source`],
114116
// shared dir should contain two files:
115117
// runtime.sh
116118
// m2ee.yaml
117-
`--volume ${dockerDir}:/shared:ro`,
119+
[`--volume`, `${dockerDir}:/shared:ro`],
120+
[`--label`, `${containerLabel}`],
118121
mxruntimeImage,
119122
`/shared/runtime.sh`
120123
];
121-
const command = [`docker run`, ...args].join(" ");
122-
const runtimeContainerId = execSync(command, { encoding: "utf-8" }).trim();
124+
125+
spawn("docker", args.flat(), { stdio: "inherit" });
126+
127+
let runtimeContainerId = "";
128+
for (let attempts = 100; attempts > 0; --attempts) {
129+
runtimeContainerId = getContainerId(containerLabel);
130+
if (runtimeContainerId) {
131+
break;
132+
}
133+
}
134+
135+
if (runtimeContainerId === "") {
136+
throw new Error("Failed to get runtime container id. Probably container didn't started.");
137+
}
123138

124139
let attempts = 60;
125140
for (; attempts > 0; --attempts) {
@@ -135,11 +150,9 @@ export async function startRuntime(mxruntimeImage, mendixVersion, ip, freePort)
135150
}
136151

137152
if (attempts === 0) {
138-
console.log("Runtime didn't start, printing docker logs...");
139-
execSync(`docker logs ${runtimeContainerId}`, { stdio: "inherit" });
153+
console.log("Runtime didn't start");
140154
console.log("Print runtime.log...");
141155
console.log(cat("results/runtime.log").toString());
142-
execSync(`docker rm ${runtimeContainerId}`, { stdio: "inherit" });
143156
throw new Error("Runtime didn't start in time, exiting now...");
144157
}
145158

@@ -175,3 +188,7 @@ export function startCypress(ip, freePort) {
175188

176189
execSync(command, { stdio: "inherit" });
177190
}
191+
192+
export function getContainerId(containerLabel) {
193+
return execSync(`docker ps --quiet --filter 'label=${containerLabel}'`, { encoding: "utf-8" }).trim();
194+
}

automation/run-e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web-widgets/run-e2e",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"private": true,
55
"license": "Apache-2.0",
66
"copyright": "© Mendix Technology BV 2023. All rights reserved.",

0 commit comments

Comments
 (0)