@magda/scripts 1.1.0-alpha.0 → 1.1.0-alpha.4
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.
|
@@ -65,6 +65,16 @@ const argv = yargs
|
|
|
65
65
|
type: "boolean",
|
|
66
66
|
default: false
|
|
67
67
|
},
|
|
68
|
+
platform: {
|
|
69
|
+
description:
|
|
70
|
+
"A list of platform that the docker image build should target. Specify this value will enable multi-arch image build.",
|
|
71
|
+
type: "string"
|
|
72
|
+
},
|
|
73
|
+
noCache: {
|
|
74
|
+
description: "Disable the cache during the docker image build.",
|
|
75
|
+
type: "boolean",
|
|
76
|
+
default: false
|
|
77
|
+
},
|
|
68
78
|
cacheFromVersion: {
|
|
69
79
|
description:
|
|
70
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.",
|
|
@@ -81,6 +91,18 @@ if (!argv.build && !argv.output) {
|
|
|
81
91
|
process.exit(1);
|
|
82
92
|
}
|
|
83
93
|
|
|
94
|
+
if (argv.platform && !argv.push) {
|
|
95
|
+
console.log(
|
|
96
|
+
"When --platform is specified, --push must be specified as well as multi-arch image can only be pushed to remote registry."
|
|
97
|
+
);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (argv.noCache && argv.cacheFromVersion) {
|
|
102
|
+
console.log("When --noCache=true, --cacheFromVersion can't be specified.");
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
|
|
84
106
|
const componentSrcDir = path.resolve(process.cwd());
|
|
85
107
|
const dockerContextDir = fse.mkdtempSync(
|
|
86
108
|
path.resolve(__dirname, "..", "docker-context-")
|
|
@@ -157,9 +179,12 @@ if (argv.build) {
|
|
|
157
179
|
"docker",
|
|
158
180
|
[
|
|
159
181
|
...extraParameters,
|
|
182
|
+
...(argv.platform ? ["buildx"] : []),
|
|
160
183
|
"build",
|
|
161
184
|
...tagArgs,
|
|
162
185
|
...cacheFromArgs,
|
|
186
|
+
...(argv.noCache ? ["--no-cache"] : []),
|
|
187
|
+
...(argv.platform ? ["--platform", argv.platform, "--push"] : []),
|
|
163
188
|
"-f",
|
|
164
189
|
`./component/Dockerfile`,
|
|
165
190
|
"-"
|
|
@@ -175,7 +200,7 @@ if (argv.build) {
|
|
|
175
200
|
dockerProcess.on("close", (code) => {
|
|
176
201
|
fse.removeSync(dockerContextDir);
|
|
177
202
|
|
|
178
|
-
if (code === 0 && argv.push) {
|
|
203
|
+
if (code === 0 && argv.push && !argv.platform) {
|
|
179
204
|
if (tags.length === 0) {
|
|
180
205
|
console.error("Can not push an image without a tag.");
|
|
181
206
|
process.exit(1);
|
package/package.json
CHANGED
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
|
|
70
|
-
stdio: ["pipe", "inherit", "inherit"],
|
|
71
|
-
env: env
|
|
72
|
-
});
|
|
76
|
+
const toTag = argv.toPrefix + getName(argv.toName) + ":" + argv.toVersion;
|
|
73
77
|
|
|
74
|
-
if (
|
|
75
|
-
|
|
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
|
-
|
|
99
|
+
if (pullProcess.status !== 0) {
|
|
100
|
+
process.exit(pullProcess.status);
|
|
101
|
+
}
|
|
79
102
|
|
|
80
|
-
const tagProcess = childProcess.spawnSync(
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
87
|
-
}
|
|
112
|
+
if (tagProcess.status !== 0) {
|
|
113
|
+
process.exit(tagProcess.status);
|
|
114
|
+
}
|
|
88
115
|
|
|
89
|
-
const pushProcess = childProcess.spawnSync("docker", ["push", toTag], {
|
|
90
|
-
|
|
91
|
-
|
|
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
|
+
}
|