@magda/scripts 1.1.0-arm64.0 → 1.2.0-alpha.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.
@@ -70,6 +70,11 @@ const argv = yargs
70
70
  "A list of platform that the docker image build should target. Specify this value will enable multi-arch image build.",
71
71
  type: "string"
72
72
  },
73
+ noCache: {
74
+ description: "Disable the cache during the docker image build.",
75
+ type: "boolean",
76
+ default: false
77
+ },
73
78
  cacheFromVersion: {
74
79
  description:
75
80
  "Version to cache from when building, using the --cache-from field in docker. Will use the same repository and name. Using this options causes the image to be pulled before build.",
@@ -93,6 +98,11 @@ if (argv.platform && !argv.push) {
93
98
  process.exit(1);
94
99
  }
95
100
 
101
+ if (argv.noCache && argv.cacheFromVersion) {
102
+ console.log("When --noCache=true, --cacheFromVersion can't be specified.");
103
+ process.exit(1);
104
+ }
105
+
96
106
  const componentSrcDir = path.resolve(process.cwd());
97
107
  const dockerContextDir = fse.mkdtempSync(
98
108
  path.resolve(__dirname, "..", "docker-context-")
@@ -173,6 +183,7 @@ if (argv.build) {
173
183
  "build",
174
184
  ...tagArgs,
175
185
  ...cacheFromArgs,
186
+ ...(argv.noCache ? ["--no-cache"] : []),
176
187
  ...(argv.platform ? ["--platform", argv.platform, "--push"] : []),
177
188
  "-f",
178
189
  `./component/Dockerfile`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magda/scripts",
3
- "version": "1.1.0-arm64.0",
3
+ "version": "1.2.0-alpha.0",
4
4
  "description": "Scripts for building, running, and deploying MAGDA",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
package/retag-and-push.js CHANGED
@@ -56,6 +56,13 @@ const argv = yargs
56
56
  example: "data61/magda-ckan-connector",
57
57
  default: ""
58
58
  })
59
+ .option("copyFromRegistry", {
60
+ describe: `When \`copyFromRegistry\`=true, [regctl](https://github.com/regclient/regclient) will be used.
61
+ The image will be copied directly from remote registry to the destination registry rather than from a local image.
62
+ This allows copying multi-arch image from one registry to another registry.`,
63
+ type: "boolean",
64
+ default: false
65
+ })
59
66
  .option("toVersion", {
60
67
  describe: "The version for the tag to push to",
61
68
  type: "string",
@@ -66,29 +73,50 @@ const argv = yargs
66
73
  const fromTag =
67
74
  argv.fromPrefix + getName(argv.fromName) + ":" + argv.fromVersion;
68
75
 
69
- const pullProcess = childProcess.spawnSync("docker", ["pull", fromTag], {
70
- stdio: ["pipe", "inherit", "inherit"],
71
- env: env
72
- });
76
+ const toTag = argv.toPrefix + getName(argv.toName) + ":" + argv.toVersion;
73
77
 
74
- if (pullProcess.status !== 0) {
75
- process.exit(pullProcess.status);
76
- }
78
+ if (argv.copyFromRegistry) {
79
+ console.log(`Copying from \`${fromTag}\` to \`${toTag}\`...`);
80
+ const copyProcess = childProcess.spawn(
81
+ "regctl",
82
+ ["image", "copy", fromTag, toTag],
83
+ {
84
+ stdio: ["pipe", "pipe", "pipe"],
85
+ env: env
86
+ }
87
+ );
88
+ copyProcess.stderr.pipe(process.stderr);
89
+ copyProcess.stdout.pipe(process.stdout);
90
+ copyProcess.on("close", (code) => {
91
+ process.exit(code);
92
+ });
93
+ } else {
94
+ const pullProcess = childProcess.spawnSync("docker", ["pull", fromTag], {
95
+ stdio: ["pipe", "inherit", "inherit"],
96
+ env: env
97
+ });
77
98
 
78
- const toTag = argv.toPrefix + getName(argv.toName) + ":" + argv.toVersion;
99
+ if (pullProcess.status !== 0) {
100
+ process.exit(pullProcess.status);
101
+ }
79
102
 
80
- const tagProcess = childProcess.spawnSync("docker", ["tag", fromTag, toTag], {
81
- stdio: ["pipe", "inherit", "inherit"],
82
- env: env
83
- });
103
+ const tagProcess = childProcess.spawnSync(
104
+ "docker",
105
+ ["tag", fromTag, toTag],
106
+ {
107
+ stdio: ["pipe", "inherit", "inherit"],
108
+ env: env
109
+ }
110
+ );
84
111
 
85
- if (tagProcess.status !== 0) {
86
- process.exit(tagProcess.status);
87
- }
112
+ if (tagProcess.status !== 0) {
113
+ process.exit(tagProcess.status);
114
+ }
88
115
 
89
- const pushProcess = childProcess.spawnSync("docker", ["push", toTag], {
90
- stdio: ["pipe", "inherit", "inherit"],
91
- env: env
92
- });
116
+ const pushProcess = childProcess.spawnSync("docker", ["push", toTag], {
117
+ stdio: ["pipe", "inherit", "inherit"],
118
+ env: env
119
+ });
93
120
 
94
- process.exit(pushProcess.status);
121
+ process.exit(pushProcess.status);
122
+ }