deploy.sh 0.2.0 → 2.0.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.
Files changed (147) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc +7 -9
  3. package/.github/workflows/ci.yml +48 -0
  4. package/.husky/pre-commit +5 -0
  5. package/{test/fixtures/unknown/.gitkeep → .prettierrc} +0 -0
  6. package/.release-it.json +5 -0
  7. package/CHANGELOG.md +26 -0
  8. package/README.md +5 -6
  9. package/__tests__/fixtures/unknown/.gitkeep +0 -0
  10. package/__tests__/lib/classifier.test.js +49 -0
  11. package/__tests__/lib/helpers/util.test.js +57 -0
  12. package/bin/deploy-delete.js +14 -0
  13. package/bin/deploy-deploy.js +34 -59
  14. package/bin/deploy-list.js +25 -52
  15. package/bin/deploy-login.js +36 -52
  16. package/bin/deploy-logout.js +9 -40
  17. package/bin/deploy-logs.js +22 -48
  18. package/bin/deploy-open.js +14 -37
  19. package/bin/deploy-register.js +37 -50
  20. package/bin/deploy-server.js +8 -5
  21. package/bin/deploy-whoami.js +8 -37
  22. package/bin/deploy.js +145 -19
  23. package/{test/fixtures → examples}/docker/Dockerfile +0 -0
  24. package/examples/docker/index.js +12 -0
  25. package/examples/node/index.js +8 -0
  26. package/{test/fixtures → examples}/node/package.json +0 -0
  27. package/examples/static/index.html +22 -0
  28. package/{test/fixtures → examples}/static/main.css +4 -2
  29. package/examples/static/out.gifcd +0 -0
  30. package/generate-docs.js +55 -0
  31. package/index.js +54 -55
  32. package/jsdoc.json +6 -3
  33. package/lib/classifier.js +24 -17
  34. package/lib/deploy.js +56 -64
  35. package/lib/helpers/cli.js +178 -207
  36. package/lib/helpers/util.js +94 -21
  37. package/lib/models/deployment.js +415 -474
  38. package/lib/models/request.js +77 -66
  39. package/lib/models/user.js +119 -144
  40. package/lib/server.js +187 -97
  41. package/lib/static/not-found.html +30 -0
  42. package/lib/static/page-could-not-load.html +30 -0
  43. package/lib/static/static-server.js +70 -0
  44. package/package.json +47 -34
  45. package/website/README.md +41 -0
  46. package/website/babel.config.js +3 -0
  47. package/website/docs/api/_category_.yml +1 -0
  48. package/website/docs/api/lib/classifier.js.md +11 -0
  49. package/website/docs/api/lib/deploy.js.md +13 -0
  50. package/website/docs/api/lib/helpers/cli.js.md +193 -0
  51. package/website/docs/api/lib/helpers/util.js.md +65 -0
  52. package/website/docs/api/lib/models/deployment.js.md +171 -0
  53. package/website/docs/api/lib/models/request.js.md +67 -0
  54. package/website/docs/api/lib/models/user.js.md +92 -0
  55. package/website/docs/api/lib/server.js.md +0 -0
  56. package/website/docs/api/lib/static/static-server.js.md +0 -0
  57. package/website/docs/intro.md +57 -0
  58. package/website/docusaurus.config.js +82 -0
  59. package/website/package-lock.json +25218 -0
  60. package/website/package.json +39 -0
  61. package/website/sidebars.js +31 -0
  62. package/website/src/components/HomepageFeatures/index.js +79 -0
  63. package/website/src/components/HomepageFeatures/styles.module.css +11 -0
  64. package/website/src/css/custom.css +39 -0
  65. package/website/src/pages/index.js +57 -0
  66. package/website/src/pages/index.module.css +23 -0
  67. package/website/static/.nojekyll +0 -0
  68. package/website/static/example.gif +0 -0
  69. package/website/static/example.mov +0 -0
  70. package/website/static/img/favicon.ico +0 -0
  71. package/website/static/img/intro/deploy.png +0 -0
  72. package/website/static/img/intro/logs.png +0 -0
  73. package/{docs → website/static/img}/logo.png +0 -0
  74. package/{docs → website/static/img}/logo.pxm +0 -0
  75. package/{docs → website/static/img}/logo@2x.png +0 -0
  76. package/.npmignore +0 -9
  77. package/.travis.yml +0 -9
  78. package/TODO.md +0 -12
  79. package/docs/code/classifier.js.html +0 -116
  80. package/docs/code/deploy.js.html +0 -138
  81. package/docs/code/fonts/OpenSans-Bold-webfont.eot +0 -0
  82. package/docs/code/fonts/OpenSans-Bold-webfont.svg +0 -1830
  83. package/docs/code/fonts/OpenSans-Bold-webfont.woff +0 -0
  84. package/docs/code/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  85. package/docs/code/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  86. package/docs/code/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  87. package/docs/code/fonts/OpenSans-Italic-webfont.eot +0 -0
  88. package/docs/code/fonts/OpenSans-Italic-webfont.svg +0 -1830
  89. package/docs/code/fonts/OpenSans-Italic-webfont.woff +0 -0
  90. package/docs/code/fonts/OpenSans-Light-webfont.eot +0 -0
  91. package/docs/code/fonts/OpenSans-Light-webfont.svg +0 -1831
  92. package/docs/code/fonts/OpenSans-Light-webfont.woff +0 -0
  93. package/docs/code/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  94. package/docs/code/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  95. package/docs/code/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  96. package/docs/code/fonts/OpenSans-Regular-webfont.eot +0 -0
  97. package/docs/code/fonts/OpenSans-Regular-webfont.svg +0 -1831
  98. package/docs/code/fonts/OpenSans-Regular-webfont.woff +0 -0
  99. package/docs/code/fonts/OpenSans-Semibold-webfont.eot +0 -0
  100. package/docs/code/fonts/OpenSans-Semibold-webfont.svg +0 -1830
  101. package/docs/code/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  102. package/docs/code/fonts/OpenSans-Semibold-webfont.woff +0 -0
  103. package/docs/code/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  104. package/docs/code/fonts/OpenSans-SemiboldItalic-webfont.svg +0 -1830
  105. package/docs/code/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  106. package/docs/code/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  107. package/docs/code/global.html +0 -325
  108. package/docs/code/helpers_cli.js.html +0 -351
  109. package/docs/code/helpers_util.js.html +0 -127
  110. package/docs/code/index.html +0 -81
  111. package/docs/code/models_deployment.js.html +0 -593
  112. package/docs/code/models_request.js.html +0 -150
  113. package/docs/code/models_user.js.html +0 -232
  114. package/docs/code/module-lib_classifier.html +0 -246
  115. package/docs/code/module-lib_deploy.html +0 -350
  116. package/docs/code/module-lib_helpers_cli.html +0 -2067
  117. package/docs/code/module-lib_helpers_util.html +0 -608
  118. package/docs/code/module-models_deployment-Deployment.html +0 -359
  119. package/docs/code/module-models_deployment-DeploymentSchema.html +0 -359
  120. package/docs/code/module-models_deployment.Deployment.html +0 -359
  121. package/docs/code/module-models_deployment.html +0 -1851
  122. package/docs/code/module-models_request-Request.html +0 -409
  123. package/docs/code/module-models_request-RequestSchema.html +0 -359
  124. package/docs/code/module-models_request.html +0 -446
  125. package/docs/code/module-models_user-User.html +0 -306
  126. package/docs/code/module-models_user-UserSchema.html +0 -306
  127. package/docs/code/module-models_user.User.html +0 -306
  128. package/docs/code/module-models_user.html +0 -1200
  129. package/docs/code/scripts/linenumber.js +0 -25
  130. package/docs/code/scripts/prettify/Apache-License-2.0.txt +0 -202
  131. package/docs/code/scripts/prettify/lang-css.js +0 -2
  132. package/docs/code/scripts/prettify/prettify.js +0 -28
  133. package/docs/code/styles/jsdoc-default.css +0 -692
  134. package/docs/code/styles/prettify-jsdoc.css +0 -111
  135. package/docs/code/styles/prettify-tomorrow.css +0 -132
  136. package/docs/example-docker.gif +0 -0
  137. package/docs/example-node.gif +0 -0
  138. package/docs/example-static.gif +0 -0
  139. package/docs/index.html +0 -50
  140. package/docs/main.css +0 -12
  141. package/docs/psychic-min.css +0 -1
  142. package/lib/helpers/static-server.js +0 -69
  143. package/test/fixtures/docker/index.js +0 -12
  144. package/test/fixtures/node/index.js +0 -8
  145. package/test/fixtures/static/index.html +0 -14
  146. package/test/lib/classifier.js +0 -51
  147. package/test/lib/helpers/util.js +0 -30
package/index.js CHANGED
@@ -1,70 +1,69 @@
1
- const Async = require('async');
2
- const mongoose = require('mongoose');
3
- const ora = require('ora');
1
+ import ora from "ora";
2
+ import mongoose from "mongoose";
4
3
 
5
- const spinner = ora('Starting up deploy.sh server').start();
6
- const { start, stop } = require('./lib/models/deployment');
4
+ import Deployment from "./lib/models/deployment.js";
7
5
 
8
6
  let running = true;
9
7
 
10
8
  mongoose.Promise = global.Promise;
11
9
 
12
- process.on('unhandledRejection', (err, p) => {
13
- console.log('An unhandledRejection occurred'); // eslint-disable-line
14
- console.log(`Rejected Promise: ${p}`); // eslint-disable-line
15
- console.log(`Rejection: ${err}`); // eslint-disable-line
16
- });
10
+ export default async function (cli, spinner) {
11
+ try {
12
+ spinner.text = "Starting up deploy.sh server";
17
13
 
18
- Async.waterfall([
19
- function(callback) {
20
- spinner.text = 'Connecting to mongo';
14
+ spinner.text = "Connecting to mongo";
15
+ await mongoose.connect(cli.mongo);
21
16
 
22
- mongoose.connect('mongodb://localhost/deploy-sh', { useMongoClient: true })
23
- .then(() => callback())
24
- .catch(err => callback(err));
25
- },
26
- function(callback) {
27
- spinner.text = 'Starting existing applications';
28
- start({})
29
- .then((deployments) => callback(null, deployments))
30
- .catch((ex) => callback(ex));
31
- }
32
- ], (error, deployments) => {
33
- if(error) {
34
- spinner.fail(`
35
- Error on startup:
36
- ${error}
37
- `);
38
- } else {
39
- spinner.succeed(`Started ${deployments.length} deployment(s) successfully`);
17
+ spinner.text = "Starting existing applications";
18
+ const deployments = await Deployment.start({});
19
+
20
+ spinner.succeed(
21
+ `Started ${
22
+ deployments ? deployments.length : 0
23
+ } deployment(s) successfully`
24
+ );
25
+
26
+ const { default: importServerCommand } = await import("./lib/server.js");
27
+ return importServerCommand;
28
+ } catch (ex) {
29
+ if (
30
+ ex.message.indexOf("HTTP code 304") > -1 ||
31
+ ex.message.indexOf("(HTTP code 404) no such container") > -1
32
+ ) {
33
+ spinner.warn(`Services already started`);
34
+
35
+ const { default: importServerCommand } = await import("./lib/server.js");
36
+ return importServerCommand;
37
+ }
38
+ throw new Error(ex);
40
39
  }
41
- return require('./lib/server');
42
- });
40
+ }
43
41
 
44
- function shutdown() {
45
- if(!running) return;
42
+ async function shutdown() {
43
+ if (!running) return;
46
44
  running = false;
47
- const spinner = ora('Shutting down up deploy.sh server').start();
48
45
 
49
- Async.waterfall([
50
- function(callback) {
51
- spinner.text = 'Stopping deployments';
52
- stop({})
53
- .then((deployments) => callback(null, deployments))
54
- .catch((error) => callback(error));
55
- }
56
- ], (error, deployments) => {
57
- if(error) {
58
- spinner.fail(`
59
- Error on shutdown:
60
- ${error}
61
- `);
62
- } else {
63
- spinner.succeed(`Shutdown ${deployments.length} deployment(s) successfully`);
64
- }
46
+ const spinner = ora("Shutting down up deploy.sh server").start();
47
+
48
+ try {
49
+ spinner.text = "Stopping deployments";
50
+ const deployments = await Deployment.stop({});
51
+
52
+ spinner.succeed(
53
+ `Shutdown ${
54
+ deployments ? deployments.length : 0
55
+ } deployment(s) successfully`
56
+ );
57
+
65
58
  process.exit(0);
66
- });
59
+ } catch (ex) {
60
+ spinner.fail(`
61
+ Error on shutdown:
62
+ ${ex}
63
+ `);
64
+ process.exit(1);
65
+ }
67
66
  }
68
67
 
69
- process.on('SIGTERM', shutdown);
70
- process.on('SIGINT', shutdown);
68
+ process.on("SIGTERM", shutdown);
69
+ process.on("SIGINT", shutdown);
package/jsdoc.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "allowUnknownTags": false
4
4
  },
5
5
  "source": {
6
- "include": ["./lib", "README.md"],
6
+ "include": ["./lib"],
7
7
  "includePattern": ".js$",
8
8
  "excludePattern": "(node_modules/|docs)"
9
9
  },
@@ -15,10 +15,13 @@
15
15
  "destination": "docs/code",
16
16
  "recurse": true,
17
17
  "verbose": true,
18
- "template": "./node_modules/minami"
18
+ "template": "node_modules/minami"
19
19
  },
20
20
  "templates": {
21
21
  "cleverLinks": true,
22
- "monospaceLinks": false
22
+ "monospaceLinks": false,
23
+ "default": {
24
+ "includeDate": false
25
+ }
23
26
  }
24
27
  }
package/lib/classifier.js CHANGED
@@ -1,7 +1,10 @@
1
- const fs = require('fs');
2
- const path = require('path');
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { promisify } from "util";
3
4
 
4
- const { contains } = require('./helpers/util');
5
+ import { contains } from "./helpers/util.js";
6
+
7
+ const readFile = promisify(fs.readFile);
5
8
 
6
9
  /**
7
10
  * classifies what type of deployment is needed for a certain directory
@@ -9,22 +12,24 @@ const { contains } = require('./helpers/util');
9
12
  * @param {String} directory - the directory of which to classify
10
13
  * @return {Object} the configuration needed to deploy
11
14
  */
12
- module.exports = function classifier(directory) {
15
+ async function classifier(directory) {
13
16
  const files = fs.readdirSync(directory);
14
-
15
- if(contains(files, ['Dockerfile'])) {
16
- let build = fs.readFileSync(path.resolve(directory, 'Dockerfile')).toString('utf8');
17
+
18
+ if (contains(files, ["Dockerfile"])) {
19
+ let build = (
20
+ await readFile(path.resolve(directory, "Dockerfile"))
21
+ ).toString("utf8");
17
22
  build = build.replace(/\$\{directory\}/, directory);
18
23
 
19
24
  return {
20
- type: 'docker',
21
- build
25
+ type: "docker",
26
+ build,
22
27
  };
23
28
  }
24
29
 
25
- if(contains(files, ['package.json'])) {
30
+ if (contains(files, ["package.json"])) {
26
31
  return {
27
- type: 'node',
32
+ type: "node",
28
33
  build: `
29
34
  FROM mhart/alpine-node:8
30
35
  WORKDIR ${directory}
@@ -33,24 +38,26 @@ module.exports = function classifier(directory) {
33
38
  RUN npm install
34
39
 
35
40
  CMD ["npm", "start"]
36
- `
41
+ `,
37
42
  };
38
43
  }
39
44
 
40
- if(contains(files, ['index.html', '!Dockerfile', '!package.json'])) {
45
+ if (contains(files, ["index.html", "!Dockerfile", "!package.json"])) {
41
46
  return {
42
- type: 'static',
47
+ type: "static",
43
48
  build: `
44
49
  FROM mhart/alpine-node:base-8
45
50
  WORKDIR ${directory}
46
51
  ADD . .
47
52
 
48
53
  CMD ["node", "index.js"]
49
- `
54
+ `,
50
55
  };
51
56
  }
52
57
 
53
58
  return {
54
- type: 'unknown'
59
+ type: "unknown",
55
60
  };
56
- };
61
+ }
62
+
63
+ export default classifier;
package/lib/deploy.js CHANGED
@@ -1,13 +1,14 @@
1
- const Async = require('async');
2
- const tar = require('tar');
3
- const path = require('path');
4
- const fs = require('fs');
5
- const mkdirp = require('mkdirp');
1
+ import tar from "tar";
2
+ import path from "path";
3
+ import fs from "fs";
4
+ import { promisify } from "util";
6
5
 
7
- const classifer = require('./classifier');
6
+ const writeFile = promisify(fs.writeFile);
7
+ const readFile = promisify(fs.readFile);
8
8
 
9
- const { getPort } = require('./helpers/util');
10
- const { get, build, remove } = require('./models/deployment');
9
+ import classifer from "./classifier.js";
10
+ import { getPort, mk } from "./helpers/util.js";
11
+ import Deployment from "./models/deployment.js";
11
12
 
12
13
  /**
13
14
  * handles the deployment of an application tar
@@ -18,61 +19,52 @@ const { get, build, remove } = require('./models/deployment');
18
19
  * @param {String} option.token - token associated with the user that want to deploy the application
19
20
  * @param {String} option.username - username of the user the token is associated too
20
21
  */
21
- module.exports = function deploy({ name, bundlePath, token, username }) {
22
- return new Promise(function(resolve, reject) {
23
- get({ username, token, name, create: true })
24
- .then((deployment) => {
25
- const outputDir = path.resolve(__dirname, '..', 'tmp', deployment.subdomain);
26
- mkdirp.sync(outputDir);
22
+ export default async function deploy({ name, bundlePath, token, username }) {
23
+ const deployment = await Deployment.get({
24
+ username,
25
+ token,
26
+ name,
27
+ create: true,
28
+ });
29
+ const outputDir = `${process.cwd()}/tmp/${deployment.subdomain}`;
30
+
31
+ // makes the directory recursively
32
+ await mk(outputDir);
33
+
34
+ await tar.x({
35
+ file: bundlePath,
36
+ cwd: outputDir,
37
+ });
38
+
39
+ await Deployment.remove({
40
+ token,
41
+ username,
42
+ subdomain: deployment.subdomain,
43
+ });
44
+
45
+ const config = await classifer(outputDir);
46
+
47
+ if (config.type === "unknown") {
48
+ throw new Error("deployment not supported");
49
+ }
50
+
51
+ if (config.type === "static") {
52
+ await writeFile(
53
+ path.resolve(outputDir, "index.js"),
54
+ (
55
+ await readFile(new URL("static", "static-server.js", import.meta.url))
56
+ ).toString("utf8")
57
+ );
58
+ }
59
+
60
+ await writeFile(path.resolve(outputDir, "Dockerfile"), config.build);
27
61
 
28
- tar.x({
29
- file: bundlePath,
30
- cwd: outputDir
31
- }).then(() => {
32
- Async.waterfall([
33
- (callback) => {
34
- remove({
35
- token,
36
- username,
37
- name: deployment.subdomain
38
- })
39
- .then(() => callback())
40
- .catch((ex) => callback(ex));
41
- },
42
- (callback) => {
43
- const config = classifer(outputDir);
44
- if (config.type === 'unknown') {
45
- callback('deployment not supported', null);
46
- }
47
- if (config.type === 'static') {
48
- fs.writeFileSync(path.resolve(outputDir, 'index.js'), fs.readFileSync(path.resolve(__dirname, 'helpers', 'static-server.js')));
49
- }
50
- callback(null, config.build);
51
- },
52
- (config, callback) => {
53
- fs.writeFile(path.resolve(outputDir, 'Dockerfile'), config, callback);
54
- },
55
- (callback) => {
56
- getPort(callback);
57
- },
58
- (port, callback) => {
59
- build({
60
- name,
61
- token,
62
- username,
63
- subdomain: deployment.subdomain,
64
- port,
65
- directory: outputDir
66
- })
67
- .then((deployment) => callback(null, deployment))
68
- .catch((ex) => callback(ex));
69
- }
70
- ], (err, result) => {
71
- if (err) return reject(err);
72
- resolve(result);
73
- });
74
- })
75
- .catch((ex) => reject(ex));
76
- });
62
+ return await Deployment.build({
63
+ name,
64
+ token,
65
+ username,
66
+ subdomain: deployment.subdomain,
67
+ port: await getPort(),
68
+ directory: outputDir,
77
69
  });
78
- };
70
+ }