containerify 3.1.0 → 3.1.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.
package/README.md CHANGED
@@ -45,7 +45,7 @@ This will take the `nginx:alpine` image, and copy the files from `./dist/` into
45
45
 
46
46
  1. Create the repository in GitLab
47
47
  2. Login using your username and password, [CI-credentials](https://docs.gitlab.com/ee/ci/jobs/ci_job_token.html), or [obtain a token from GitLab](https://docs.gitlab.com/ee/api/container_registry.html#obtain-token-from-gitlab)
48
- 3. Example using CI-credentials `containerify --toToken "Basic $(echo -n '${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}' | base64)" --to registry.gitlab.com/<Gitlab organisation>/<repository>:<tag>`
48
+ 3. Example using CI-credentials `containerify --toToken "Basic $(echo -n "${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}" | base64)" --to registry.gitlab.com/<Gitlab organisation>/<repository>:<tag>`
49
49
 
50
50
  ### Command line options
51
51
 
package/lib/registry.js CHANGED
@@ -130,19 +130,12 @@ function processToken(registryBaseUrl, allowInsecure, imagePath, token) {
130
130
  return __awaiter(this, void 0, void 0, function* () {
131
131
  const { hostname } = URL.parse(registryBaseUrl);
132
132
  const image = (0, utils_1.parseImage)(imagePath);
133
- if ((hostname === null || hostname === void 0 ? void 0 : hostname.endsWith(".docker.io")) && !token) {
134
- const resp = yield (0, httpRequest_1.dlJson)(`https://auth.docker.io/token?service=registry.docker.io&scope=repository:${image.path}:pull`, {}, allowInsecure);
135
- return `Bearer ${resp.token}`;
136
- }
137
- if ((hostname === null || hostname === void 0 ? void 0 : hostname.endsWith(".gitlab.com")) && (token === null || token === void 0 ? void 0 : token.startsWith("Basic"))) {
138
- if (token === null || token === void 0 ? void 0 : token.includes(":")) {
139
- token = "Basic " + Buffer.from(token === null || token === void 0 ? void 0 : token.replace("Basic ", "")).toString("base64");
140
- }
141
- const resp = yield (0, httpRequest_1.dlJson)(`https://gitlab.com/jwt/auth?service=container_registry&scope=repository:${image.path}:pull,push`, { Authorization: token }, allowInsecure);
142
- return `Bearer ${resp.token}`;
143
- }
133
+ if ((hostname === null || hostname === void 0 ? void 0 : hostname.endsWith(".docker.io")) && !token)
134
+ return getDockerToken(image.path, allowInsecure);
144
135
  if (!token)
145
136
  return ""; //We allow to pull from tokenless registries
137
+ if ((hostname === null || hostname === void 0 ? void 0 : hostname.endsWith(".gitlab.com")) && token.startsWith("Basic "))
138
+ return getGitLabToken(token, image.path, allowInsecure);
146
139
  if (token.startsWith("Basic "))
147
140
  return token;
148
141
  if (token.startsWith("ghp_"))
@@ -150,6 +143,21 @@ function processToken(registryBaseUrl, allowInsecure, imagePath, token) {
150
143
  return "Bearer " + token;
151
144
  });
152
145
  }
146
+ function getDockerToken(imagePath, allowInsecure) {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ const resp = yield (0, httpRequest_1.dlJson)(`https://auth.docker.io/token?service=registry.docker.io&scope=repository:${imagePath}:pull`, {}, allowInsecure);
149
+ return `Bearer ${resp.token}`;
150
+ });
151
+ }
152
+ function getGitLabToken(token, imagePath, allowInsecure) {
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ if (token.includes(":")) {
155
+ token = "Basic " + Buffer.from(token === null || token === void 0 ? void 0 : token.replace("Basic ", "")).toString("base64");
156
+ }
157
+ const resp = yield (0, httpRequest_1.dlJson)(`https://gitlab.com/jwt/auth?service=container_registry&scope=repository:${imagePath}:pull,push`, { Authorization: token }, allowInsecure);
158
+ return `Bearer ${resp.token}`;
159
+ });
160
+ }
153
161
  function createRegistry(registryBaseUrl, imagePath, allowInsecure, auth, optimisticToRegistryCheck = false) {
154
162
  return __awaiter(this, void 0, void 0, function* () {
155
163
  const token = yield processToken(registryBaseUrl, allowInsecure, imagePath, auth);
@@ -173,8 +181,8 @@ function createRegistry(registryBaseUrl, imagePath, allowInsecure, auth, optimis
173
181
  const url = `${registryBaseUrl}${image.path}/blobs/uploads/${parameters.size > 0 ? "?" + parameters : ""}`;
174
182
  const options = URL.parse(url);
175
183
  options.method = "POST";
176
- if (auth)
177
- options.headers = { authorization: auth };
184
+ if (token)
185
+ options.headers = { authorization: token };
178
186
  (0, httpRequest_1.request)(options, allowInsecure, (res) => {
179
187
  logger_1.default.debug("POST", `${url}`, res.statusCode);
180
188
  if (res.statusCode == 202) {
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "3.1.0";
1
+ export declare const VERSION = "3.1.1";
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 = "3.1.0";
4
+ exports.VERSION = "3.1.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "containerify",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "Build node.js docker images without docker",
5
5
  "main": "./lib/cli.js",
6
6
  "scripts": {