cloudron 5.14.8 → 5.14.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudron",
3
- "version": "5.14.8",
3
+ "version": "5.14.9",
4
4
  "license": "MIT",
5
5
  "description": "Cloudron Commandline Tool",
6
6
  "main": "main.js",
@@ -295,6 +295,23 @@ async function verifyManifest(localOptions, cmd) {
295
295
  if (error) return exit(error);
296
296
  }
297
297
 
298
+ async function checkDockerHub(dockerImage) {
299
+ // const [tagError, tagResponse] = await safe(superagent.get(`https://hub.docker.com/v2/repositories/${repo}/tags/${tag}`).ok(() => true));
300
+ // if (tagError || tagResponse.status !== 200) return exit(`Failed to find docker image in dockerhub. check https://hub.docker.com/r/${repo}/tags : ${tagError || requestError(tagResponse)}`);
301
+
302
+ const [repo, tag] = dockerImage.split(':');
303
+
304
+ const [error, response] = await safe(superagent.get(`https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull`).ok(() => true));
305
+ if (error || response.status !== 200) throw new Error(`Failed to get dockerhub token to validate image: ${error || requestError(response)}`);
306
+ const token = response.body.token;
307
+
308
+ const [error2, response2] = await safe(superagent.head(`https://registry-1.docker.io/v2/${repo}/manifests/${tag}`)
309
+ .set('Accept', 'application/vnd.docker.distribution.manifest.v2+json')
310
+ .set('Authorization', `Bearer ${token}`)
311
+ .ok(() => true));
312
+ if (error2 || response2.status !== 200) throw new Error(`Image not found on docker hub: ${error2 || requestError(response2)}`);
313
+ }
314
+
298
315
  async function upload(localOptions, cmd) {
299
316
  const options = cmd.optsWithGlobals();
300
317
  // try to find the manifest of this project
@@ -332,9 +349,8 @@ async function upload(localOptions, cmd) {
332
349
  const error = manifestFormat.checkAppstoreRequirements(manifest);
333
350
  if (error) return exit(error);
334
351
 
335
- const [repo, tag] = manifest.dockerImage.split(':');
336
- const [tagError, tagResponse] = await safe(superagent.get(`https://hub.docker.com/v2/repositories/${repo}/tags/${tag}`).ok(() => true));
337
- if (tagError || tagResponse.status !== 200) return exit(`Failed to find docker image in dockerhub. check https://hub.docker.com/r/${repo}/tags : ${tagError || requestError(tagResponse)}`);
352
+ const [imageError] = await safe(checkDockerHub(manifest.dockerImage));
353
+ if (imageError) return exit(error);
338
354
 
339
355
  // ensure the app is known on the appstore side
340
356
  const baseDir = path.dirname(manifestFilePath);
package/src/superagent.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  exports = module.exports = {
4
+ head,
4
5
  get,
5
6
  put,
6
7
  post,
@@ -214,6 +215,7 @@ class Request {
214
215
  }
215
216
  }
216
217
 
218
+ function head(url) { return new Request('HEAD', url); }
217
219
  function get(url) { return new Request('GET', url); }
218
220
  function put(url) { return new Request('PUT', url); }
219
221
  function post(url) { return new Request('POST', url); }