@infosupport/huddle-cli 0.0.0-experiment-137.147.1 → 0.0.0-experiment-137.148.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.
@@ -11,6 +11,7 @@ exports.readStatus = readStatus;
11
11
  exports.buildImages = buildImages;
12
12
  exports.startBackgroundBuild = startBackgroundBuild;
13
13
  exports.printStatus = printStatus;
14
+ exports.ensureImageForStart = ensureImageForStart;
14
15
  const child_process_1 = require("child_process");
15
16
  const fs_1 = __importDefault(require("fs"));
16
17
  const path_1 = __importDefault(require("path"));
@@ -160,3 +161,41 @@ function printStatus(rt, tag) {
160
161
  if (fs_1.default.existsSync(LOG_PATH))
161
162
  console.log((0, utils_1.dim)(`Log: ${LOG_PATH}`));
162
163
  }
164
+ const STALE_MS = 60 * 60 * 1000;
165
+ /**
166
+ * Called by `huddle start` before it asks the gateway to start a container.
167
+ * The gateway would otherwise block the request for the whole build and the
168
+ * CLI's HTTP call times out after 5 minutes. So: wait here for a running
169
+ * background build (with progress), or build in the foreground when nothing is
170
+ * building. Only for our own local images; a snapshot or custom image is left
171
+ * to the gateway.
172
+ */
173
+ async function ensureImageForStart(rt, ide, imageName) {
174
+ const m = /^localhost\/huddle\/base-devimage-[a-z]+:(.+)$/.exec(imageName);
175
+ if (!m || imageExists(rt, imageName))
176
+ return;
177
+ const tag = m[1];
178
+ let announced = false;
179
+ for (;;) {
180
+ const s = readStatus();
181
+ const building = s?.state === 'building' && Date.now() - Date.parse(s.updatedAt) < STALE_MS;
182
+ if (!building || imageExists(rt, imageName))
183
+ break;
184
+ if (!announced) {
185
+ console.log((0, utils_1.dim)(`Waiting for the base-image build to finish (${s?.image ?? imageName}); log: ${LOG_PATH}`));
186
+ announced = true;
187
+ }
188
+ else {
189
+ process.stdout.write((0, utils_1.dim)('.'));
190
+ }
191
+ await new Promise((r) => setTimeout(r, 10_000));
192
+ }
193
+ if (announced)
194
+ console.log();
195
+ if (imageExists(rt, imageName))
196
+ return;
197
+ console.log((0, utils_1.bold)(`Base image ${imageName} is missing; building it now (one-time, a few minutes).`));
198
+ if (!buildImages({ rt, tag, ides: [ide] })) {
199
+ throw new Error(`Could not build ${imageName}; see the output above or run "huddle images build"`);
200
+ }
201
+ }
package/dist/start.js CHANGED
@@ -8,6 +8,8 @@ const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const api_1 = require("./api");
10
10
  const utils_1 = require("./utils");
11
+ const base_images_1 = require("./base-images");
12
+ const runtime_1 = require("./runtime");
11
13
  async function runStart(opts) {
12
14
  const ide = parseIde(opts.ide);
13
15
  const hasMounts = !!opts.mounts && opts.mounts.length > 0;
@@ -73,6 +75,17 @@ async function runStart(opts) {
73
75
  else {
74
76
  body.workspaceDir = workspaceDir;
75
77
  }
78
+ // Our base images are built on this machine; make sure this one exists before the
79
+ // gateway starts the container (it would otherwise build it inside the request).
80
+ let rt;
81
+ try {
82
+ rt = (0, runtime_1.resolveRuntime)().name;
83
+ }
84
+ catch {
85
+ // No local container runtime (e.g. HUDDLE_URL points elsewhere): leave it to the gateway.
86
+ }
87
+ if (rt)
88
+ await (0, base_images_1.ensureImageForStart)(rt, ide, imageName);
76
89
  const result = await (0, api_1.post)('/api/docker/start', body);
77
90
  console.log((0, utils_1.green)(`[OK] Container started: ${result.containerName} (${result.id.slice(0, 12)})`));
78
91
  console.log();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infosupport/huddle-cli",
3
- "version": "0.0.0-experiment-137.147.1",
3
+ "version": "0.0.0-experiment-137.148.1",
4
4
  "description": "Huddle CLI — start devcontainers and manage firewall rules",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "author": "Info Support B.V.",