datagrok-tools 6.1.4 → 6.1.5

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.
@@ -52,7 +52,7 @@ function discoverDockerfiles(packageName, version, debug) {
52
52
  if (!_fs.default.existsSync(dockerfilePath)) continue;
53
53
  const cleanName = utils.removeScope(packageName).toLowerCase();
54
54
  const imageName = `${cleanName}-${entry.name.toLowerCase()}`;
55
- const imageTag = debug ? version : `${version}.X`;
55
+ const imageTag = version;
56
56
  results.push({
57
57
  imageName,
58
58
  imageTag,
@@ -68,17 +68,26 @@ function dockerCommand(args) {
68
68
  stdio: ['pipe', 'pipe', 'pipe']
69
69
  }).trim();
70
70
  }
71
- function localImageExists(fullName) {
71
+ function localImageExists(fullName, checkPlatform = true) {
72
72
  try {
73
73
  const output = dockerCommand(`images --format "{{.Repository}}:{{.Tag}}"`);
74
- return output.split('\n').some(line => line.trim() === fullName);
74
+ if (!output.split('\n').some(line => line.trim() === fullName)) return false;
75
+ if (checkPlatform) {
76
+ // Verify the image is linux/amd64 — ARM images won't run on Datagrok servers
77
+ const inspect = dockerCommand(`inspect --format "{{.Os}}/{{.Architecture}}" ${fullName}`);
78
+ if (inspect.trim() !== 'linux/amd64') {
79
+ color.warn(`Local image ${fullName} is ${inspect.trim()}, not linux/amd64 — treating as not found`);
80
+ return false;
81
+ }
82
+ }
83
+ return true;
75
84
  } catch {
76
85
  return false;
77
86
  }
78
87
  }
79
88
  function dockerLogin(registry, devKey) {
80
89
  try {
81
- dockerCommand(`login ${registry} -u ${devKey} -p ${devKey}`);
90
+ dockerCommand(`login ${registry} -u any -p ${devKey}`);
82
91
  return true;
83
92
  } catch (e) {
84
93
  color.warn(`Docker login to ${registry} failed: ${e.message || e}`);
@@ -106,10 +115,22 @@ function dockerPush(image) {
106
115
  return false;
107
116
  }
108
117
  }
109
- function dockerBuild(imageName, dockerfilePath, context) {
118
+ function isLocalhostRegistry(registry) {
119
+ return registry.startsWith('localhost') || registry.startsWith('127.0.0.1');
120
+ }
121
+ function dockerRemove(imageName) {
122
+ try {
123
+ dockerCommand(`rmi ${imageName}`);
124
+ return true;
125
+ } catch {
126
+ return false;
127
+ }
128
+ }
129
+ function dockerBuild(imageName, dockerfilePath, context, usePlatform = true) {
110
130
  try {
111
- color.log(`Building Docker image ${imageName}...`);
112
- execSync(`docker build -t ${imageName} -f ${dockerfilePath} ${context}`, {
131
+ const platformFlag = usePlatform ? '--platform linux/amd64 ' : '';
132
+ color.log(`Building Docker image ${imageName}${usePlatform ? ' (platform: linux/amd64)' : ''}...`);
133
+ execSync(`docker build ${platformFlag}-t ${imageName} -f ${dockerfilePath} ${context}`, {
113
134
  encoding: 'utf-8',
114
135
  stdio: 'inherit'
115
136
  });
@@ -233,62 +254,83 @@ async function processDockerImages(packageName, version, registry, devKey, host,
233
254
  if (dockerImages.length === 0) return;
234
255
  color.log(`Found ${dockerImages.length} Dockerfile(s)`);
235
256
  if (registry) dockerLogin(registry, devKey);
257
+ const needsPlatform = !!registry && !isLocalhostRegistry(registry);
236
258
  for (const img of dockerImages) {
237
259
  color.info(`Processing docker image ${img.fullLocalName}...`);
238
260
  let result;
239
261
  const dockerfileDir = _path.default.join('dockerfiles', img.dirName);
240
262
  const dockerfilePath = _path.default.join(dockerfileDir, 'Dockerfile');
241
263
  const contentHash = calculateFolderHash(_path.default.join(curDir, dockerfileDir));
242
- if (rebuildDocker) {
243
- if (dockerBuild(img.fullLocalName, dockerfilePath, dockerfileDir)) {
244
- result = pushImage(img, registry);
264
+
265
+ // In release mode, append short content hash to tag for cache-busting
266
+ const shortHash = contentHash.substring(0, 8);
267
+ const registryTag = debug ? img.imageTag : `${img.imageTag}.${shortHash}`;
268
+ const remoteFullName = `${img.imageName}:${registryTag}`;
269
+ const buildAndPush = () => {
270
+ if (dockerBuild(img.fullLocalName, dockerfilePath, dockerfileDir, needsPlatform)) {
271
+ if (registry) {
272
+ const remoteTag = `${registry}/datagrok/${remoteFullName}`;
273
+ dockerTag(img.fullLocalName, remoteTag);
274
+ }
245
275
  color.success(`Built and tagged ${img.fullLocalName}`);
246
- } else {
247
- result = await fallbackImage(img, host, devKey, registry, version, contentHash);
276
+ return pushImage(img.imageName, registryTag, registry);
248
277
  }
249
- } else if (localImageExists(img.fullLocalName)) {
250
- color.success(`Found local image ${img.fullLocalName}`);
251
- result = pushImage(img, registry);
278
+ return null;
279
+ };
280
+ if (rebuildDocker) {
281
+ // Delete old images before rebuilding
282
+ dockerRemove(img.fullLocalName);
283
+ if (registry) dockerRemove(`${registry}/datagrok/${remoteFullName}`);
284
+ result = buildAndPush() ?? (await fallbackImage(img, host, devKey, registry, version, contentHash));
252
285
  } else {
253
- color.warn(`Local image not found. Expected: ${img.fullLocalName}`);
254
- color.log(` Build it with: docker build -t ${img.fullLocalName} -f ${dockerfilePath} ${dockerfileDir}`);
255
- const fallback = await fallbackImage(img, host, devKey, registry, version, contentHash);
256
- if (fallback.serverError) {
257
- color.error(`Cannot resolve fallback: ${fallback.serverError}`);
258
- result = {
259
- image: null,
260
- fallback: true,
261
- requestedVersion: img.imageTag
262
- };
263
- } else if (fallback.image && fallback.hashMatch === true) {
264
- result = fallback;
265
- color.success(`Falling back to ${fallback.image} (dockerfile unchanged)`);
266
- } else if (fallback.image && fallback.hashMatch === false && !skipDockerRebuild) {
267
- color.warn(`Dockerfile folder has changed. Rebuilding image...`);
268
- if (dockerBuild(img.fullLocalName, dockerfilePath, dockerfileDir)) {
269
- result = pushImage(img, registry);
270
- color.success(`Built and tagged ${img.fullLocalName}`);
271
- } else {
272
- result = {
273
- image: fallback.image,
274
- fallback: true,
275
- requestedVersion: img.imageTag
276
- };
277
- color.warn(`Build failed. Falling back to ${fallback.image} (hash mismatch)`);
286
+ // Look for registry-qualified image first, then unqualified
287
+ let foundLocalName = null;
288
+ if (registry) {
289
+ const registryQualified = `${registry}/datagrok/${remoteFullName}`;
290
+ if (localImageExists(registryQualified, needsPlatform)) foundLocalName = registryQualified;
291
+ }
292
+ if (!foundLocalName && localImageExists(img.fullLocalName, needsPlatform)) foundLocalName = img.fullLocalName;
293
+ if (foundLocalName) {
294
+ color.success(`Found local image ${foundLocalName}`);
295
+ if (registry) {
296
+ const remoteTag = `${registry}/datagrok/${remoteFullName}`;
297
+ if (foundLocalName !== remoteTag) dockerTag(foundLocalName, remoteTag);
278
298
  }
299
+ result = pushImage(img.imageName, registryTag, registry);
279
300
  } else {
280
- // No fallback and no local image — must build
281
- color.warn(`No fallback available. Building ${img.fullLocalName}...`);
282
- if (dockerBuild(img.fullLocalName, dockerfilePath, dockerfileDir)) {
283
- result = pushImage(img, registry);
284
- color.success(`Built and tagged ${img.fullLocalName}`);
285
- } else {
301
+ color.warn(`Local image not found. Expected: ${img.fullLocalName}`);
302
+ color.log(` Build it with: docker build -t ${img.fullLocalName} -f ${dockerfilePath} ${dockerfileDir}`);
303
+ const fallback = await fallbackImage(img, host, devKey, registry, version, contentHash);
304
+ if (fallback.serverError) {
305
+ color.error(`Cannot resolve fallback: ${fallback.serverError}`);
286
306
  result = {
287
307
  image: null,
288
308
  fallback: true,
289
- requestedVersion: img.imageTag
309
+ requestedVersion: registryTag
310
+ };
311
+ } else if (fallback.image && fallback.hashMatch === true) {
312
+ result = fallback;
313
+ color.success(`Falling back to ${fallback.image} (dockerfile unchanged)`);
314
+ } else if (fallback.image && fallback.hashMatch === false && !skipDockerRebuild) {
315
+ color.warn(`Dockerfile folder has changed. Rebuilding image...`);
316
+ result = buildAndPush() ?? {
317
+ image: fallback.image,
318
+ fallback: true,
319
+ requestedVersion: registryTag
290
320
  };
291
- color.error(`Failed to build ${img.fullLocalName}. No container will be available.`);
321
+ if (!result || result.fallback) color.warn(`Build failed. Falling back to ${fallback.image} (hash mismatch)`);
322
+ } else {
323
+ // No fallback and no local image — must build
324
+ color.warn(`No fallback available. Building ${img.fullLocalName}...`);
325
+ const built = buildAndPush();
326
+ if (built) result = built;else {
327
+ result = {
328
+ image: null,
329
+ fallback: true,
330
+ requestedVersion: registryTag
331
+ };
332
+ color.error(`Failed to build ${img.fullLocalName}. No container will be available.`);
333
+ }
292
334
  }
293
335
  }
294
336
  }
@@ -300,11 +342,11 @@ async function processDockerImages(packageName, version, registry, devKey, host,
300
342
  color.log(`Added ${imageJsonPath}`);
301
343
  }
302
344
  }
303
- function pushImage(img, registry) {
304
- const canonicalImage = `datagrok/${img.fullLocalName}`;
345
+ function pushImage(imageName, tag, registry) {
346
+ const canonicalImage = `datagrok/${imageName}:${tag}`;
305
347
  if (registry) {
306
348
  const remoteTag = `${registry}/${canonicalImage}`;
307
- dockerTag(img.fullLocalName, remoteTag);
349
+ // Image should already be tagged from build or retag step
308
350
  if (dockerPush(remoteTag)) return {
309
351
  image: canonicalImage,
310
352
  fallback: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datagrok-tools",
3
- "version": "6.1.4",
3
+ "version": "6.1.5",
4
4
  "description": "Utility to upload and publish packages to Datagrok",
5
5
  "homepage": "https://github.com/datagrok-ai/public/tree/master/tools#readme",
6
6
  "dependencies": {