cloudron 5.14.8 → 5.14.10

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/bin/cloudron CHANGED
@@ -10,7 +10,7 @@ const actions = require('../src/actions.js'),
10
10
  Command = require('commander').Command,
11
11
  safe = require('safetydance'),
12
12
  semver = require('semver'),
13
- superagent = require('../src/superagent.js'),
13
+ superagent = require('@cloudron/superagent'),
14
14
  util = require('util');
15
15
 
16
16
  const version = require('../package.json').version;
@@ -168,6 +168,7 @@ program.command('install')
168
168
  .option('-l, --location <domain>', 'Subdomain or full domain')
169
169
  .option('-s, --secondary-domains [DOMAIN=domain,...]', 'Set secondary domains')
170
170
  .option('-a, --alias-domains [domain,...]', 'Alias domains')
171
+ .option('-m, --memory-limit [domain,...]', 'Memory Limit (e.g 1.5G, 512M)')
171
172
  .option('--appstore-id <appid[@version]>', 'Use app from the store')
172
173
  .option('--no-sso', 'Disable Cloudron SSO [false]')
173
174
  .option('--debug [cmd...]', 'Enable debug mode', false)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudron",
3
- "version": "5.14.8",
3
+ "version": "5.14.10",
4
4
  "license": "MIT",
5
5
  "description": "Cloudron Commandline Tool",
6
6
  "main": "main.js",
@@ -17,7 +17,8 @@
17
17
  },
18
18
  "author": "Cloudron Developers <support@cloudron.io>",
19
19
  "dependencies": {
20
- "cloudron-manifestformat": "^5.27.0",
20
+ "@cloudron/manifest-format": "^5.27.0",
21
+ "@cloudron/superagent": "^1.0.0",
21
22
  "commander": "^13.1.0",
22
23
  "debug": "^4.4.0",
23
24
  "easy-table": "^1.2.0",
package/src/actions.js CHANGED
@@ -7,14 +7,14 @@ const assert = require('assert'),
7
7
  { EventSource } = require('eventsource'),
8
8
  fs = require('fs'),
9
9
  https = require('https'),
10
- manifestFormat = require('cloudron-manifestformat'),
10
+ manifestFormat = require('@cloudron/manifest-format'),
11
11
  os = require('os'),
12
12
  path = require('path'),
13
13
  readline = require('./readline.js'),
14
14
  safe = require('safetydance'),
15
15
  spawn = require('child_process').spawn,
16
16
  semver = require('semver'),
17
- superagent = require('./superagent.js'),
17
+ superagent = require('@cloudron/superagent'),
18
18
  Table = require('easy-table'),
19
19
  tar = require('tar-fs'),
20
20
  timers = require('timers/promises'),
@@ -544,6 +544,33 @@ async function getManifest(appstoreId) {
544
544
  return { manifest: result.manifest, manifestFilePath };
545
545
  }
546
546
 
547
+ function parseMemoryLimit(limit) {
548
+ assert.strictEqual(typeof limit, 'string');
549
+
550
+ const units = {
551
+ B: 1,
552
+ K: 1024,
553
+ KB: 1024,
554
+ M: 1024 ** 2,
555
+ MB: 1024 ** 2,
556
+ G: 1024 ** 3,
557
+ GB: 1024 ** 3,
558
+ T: 1024 ** 4,
559
+ TB: 1024 ** 4
560
+ };
561
+
562
+ const match = limit.trim().toUpperCase().match(/^([\d.]+)\s*([KMGT]?B?)$/);
563
+ if (!match) throw new Error(`Invalid size format: "${limit}"`);
564
+
565
+ const value = parseFloat(match[1]);
566
+ const unit = match[2] || 'B';
567
+
568
+ const multiplier = units[unit];
569
+ if (!multiplier) throw new Error(`Unknown unit: "${unit}"`);
570
+
571
+ return value * multiplier;
572
+ }
573
+
547
574
  async function install(localOptions, cmd) {
548
575
  const options = cmd.optsWithGlobals();
549
576
 
@@ -616,6 +643,8 @@ async function install(localOptions, cmd) {
616
643
 
617
644
  for (const port in ports) console.log(`Port ${port}: ${ports[port]}`);
618
645
 
646
+ const memoryLimit = options.memoryLimit ? parseMemoryLimit(options.memoryLimit) : 0;
647
+
619
648
  const data = {
620
649
  appStoreId: options.appstoreId || '', // note case change
621
650
  manifest: options.appstoreId ? null : manifest, // cloudron ignores manifest anyway if appStoreId is set
@@ -625,7 +654,8 @@ async function install(localOptions, cmd) {
625
654
  secondaryDomains,
626
655
  aliasDomains,
627
656
  ports,
628
- accessRestriction: null
657
+ accessRestriction: null,
658
+ memoryLimit
629
659
  };
630
660
 
631
661
  // the sso only applies for apps which allow optional sso
@@ -7,11 +7,11 @@ const assert = require('assert'),
7
7
  execSync = require('child_process').execSync,
8
8
  fs = require('fs'),
9
9
  { exit, locateManifest } = require('./helper.js'),
10
- manifestFormat = require('cloudron-manifestformat'),
10
+ manifestFormat = require('@cloudron/manifest-format'),
11
11
  path = require('path'),
12
12
  readline = require('./readline.js'),
13
13
  safe = require('safetydance'),
14
- superagent = require('./superagent.js'),
14
+ superagent = require('@cloudron/superagent'),
15
15
  Table = require('easy-table');
16
16
 
17
17
  exports = module.exports = {
@@ -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);
@@ -16,14 +16,14 @@ const assert = require('assert'),
16
16
  exit = require('./helper.js').exit,
17
17
  fs = require('fs'),
18
18
  helper = require('./helper.js'),
19
- manifestFormat = require('cloudron-manifestformat'),
19
+ manifestFormat = require('@cloudron/manifest-format'),
20
20
  micromatch = require('micromatch'),
21
21
  os = require('os'),
22
22
  path = require('path'),
23
23
  readline = require('./readline.js'),
24
24
  safe = require('safetydance'),
25
25
  stream = require('stream/promises'),
26
- superagent = require('./superagent.js'),
26
+ superagent = require('@cloudron/superagent'),
27
27
  tar = require('tar-fs'),
28
28
  url = require('url');
29
29
 
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); }