containerify 2.4.0 → 2.5.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/lib/cli.js CHANGED
@@ -18,6 +18,7 @@ const fse = require("fs-extra");
18
18
  const fs = require("fs");
19
19
  const registry_1 = require("./registry");
20
20
  const appLayerCreator_1 = require("./appLayerCreator");
21
+ const dockerExporter_1 = require("./dockerExporter");
21
22
  const tarExporter_1 = require("./tarExporter");
22
23
  const logger_1 = require("./logger");
23
24
  const utils_1 = require("./utils");
@@ -33,6 +34,7 @@ const possibleArgs = {
33
34
  "--toRegistry <registry url>": "Optional: URL of registry to push base image to - Default: https://registry-1.docker.io/v2/",
34
35
  "--toToken <token>": "Optional: Authentication token for target registry",
35
36
  "--toTar <path>": "Optional: Export to tar file",
37
+ "--toDocker": "Optional: Export to local docker registry",
36
38
  "--registry <path>": "Optional: Convenience argument for setting both from and to registry",
37
39
  "--platform <platform>": "Optional: Preferred platform, e.g. linux/amd64 or arm64",
38
40
  "--token <path>": "Optional: Convenience argument for setting token for both from and to registry",
@@ -168,8 +170,8 @@ if (options.token) {
168
170
  exitWithErrorIf(!options.folder, "--folder must be specified");
169
171
  exitWithErrorIf(!options.fromImage, "--fromImage must be specified");
170
172
  exitWithErrorIf(!options.toImage, "--toImage must be specified");
171
- exitWithErrorIf(!options.toRegistry && !options.toTar, "Must specify either --toTar or --toRegistry");
172
- exitWithErrorIf(!options.toRegistry && !options.toToken && !options.toTar, "A token must be given when uploading to docker hub");
173
+ exitWithErrorIf(!options.toRegistry && !options.toTar && !options.toDocker, "Must specify either --toTar, --toRegistry or --toDocker");
174
+ exitWithErrorIf(!!options.toRegistry && !options.toToken, "A token must be given when uploading to docker hub");
173
175
  if (options.toRegistry && !options.toRegistry.endsWith("/"))
174
176
  options.toRegistry += "/";
175
177
  if (options.fromRegistry && !options.fromRegistry.endsWith("/"))
@@ -211,6 +213,14 @@ function run(options) {
211
213
  : (0, registry_1.createDockerRegistry)(options.fromToken);
212
214
  yield fromRegistry.download(options.fromImage, fromdir, (0, utils_1.getPreferredPlatform)(options.platform), options.layerCacheFolder);
213
215
  yield appLayerCreator_1.default.addLayers(tmpdir, fromdir, todir, options);
216
+ if (options.toDocker) {
217
+ if (!(yield dockerExporter_1.default.isAvailable())) {
218
+ throw new Error("Docker executable not found on path. Unable to export to local docker registry.");
219
+ }
220
+ const dockerDir = path.join(tmpdir, "toDocker");
221
+ yield tarExporter_1.default.saveToTar(todir, tmpdir, dockerDir, [options.toImage], options);
222
+ yield dockerExporter_1.default.load(dockerDir);
223
+ }
214
224
  if (options.toTar) {
215
225
  yield tarExporter_1.default.saveToTar(todir, tmpdir, options.toTar, [options.toImage], options);
216
226
  }
@@ -0,0 +1,7 @@
1
+ declare function isAvailable(): Promise<boolean>;
2
+ declare function load(path: string): Promise<void>;
3
+ declare const _default: {
4
+ isAvailable: typeof isAvailable;
5
+ load: typeof load;
6
+ };
7
+ export default _default;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const node_util_1 = require("node:util");
13
+ const node_child_process_1 = require("node:child_process");
14
+ const logger_1 = require("./logger");
15
+ const execAsync = (0, node_util_1.promisify)(node_child_process_1.exec);
16
+ function isAvailable() {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ try {
19
+ yield execAsync("docker -v");
20
+ }
21
+ catch (e) {
22
+ return false;
23
+ }
24
+ return true;
25
+ });
26
+ }
27
+ function load(path) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ logger_1.default.info("Loading docker image from tarball...");
30
+ yield execAsync(`docker load -i ${path}`);
31
+ });
32
+ }
33
+ exports.default = {
34
+ isAvailable,
35
+ load,
36
+ };
package/lib/types.d.ts CHANGED
@@ -63,6 +63,7 @@ export type Options = {
63
63
  toRegistry?: string;
64
64
  toToken?: string;
65
65
  toTar?: string;
66
+ toDocker?: boolean;
66
67
  registry?: string;
67
68
  platform: string;
68
69
  token?: string;
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "2.4.0";
1
+ export declare const VERSION = "2.5.0";
package/lib/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "2.4.0";
4
+ exports.VERSION = "2.5.0";
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "containerify",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Build node.js docker images without docker",
5
5
  "main": "./lib/cli.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1",
8
7
  "prebuild": "node -p \"'export const VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
9
8
  "build": "tsc && chmod ugo+x lib/cli.js",
10
9
  "lint": "eslint . --ext .ts --fix --ignore-path .gitignore",