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.
- package/.eslintignore +1 -0
- package/.eslintrc +7 -9
- package/.github/workflows/ci.yml +48 -0
- package/.husky/pre-commit +5 -0
- package/{test/fixtures/unknown/.gitkeep → .prettierrc} +0 -0
- package/.release-it.json +5 -0
- package/CHANGELOG.md +26 -0
- package/README.md +5 -6
- package/__tests__/fixtures/unknown/.gitkeep +0 -0
- package/__tests__/lib/classifier.test.js +49 -0
- package/__tests__/lib/helpers/util.test.js +57 -0
- package/bin/deploy-delete.js +14 -0
- package/bin/deploy-deploy.js +34 -59
- package/bin/deploy-list.js +25 -52
- package/bin/deploy-login.js +36 -52
- package/bin/deploy-logout.js +9 -40
- package/bin/deploy-logs.js +22 -48
- package/bin/deploy-open.js +14 -37
- package/bin/deploy-register.js +37 -50
- package/bin/deploy-server.js +8 -5
- package/bin/deploy-whoami.js +8 -37
- package/bin/deploy.js +145 -19
- package/{test/fixtures → examples}/docker/Dockerfile +0 -0
- package/examples/docker/index.js +12 -0
- package/examples/node/index.js +8 -0
- package/{test/fixtures → examples}/node/package.json +0 -0
- package/examples/static/index.html +22 -0
- package/{test/fixtures → examples}/static/main.css +4 -2
- package/examples/static/out.gifcd +0 -0
- package/generate-docs.js +55 -0
- package/index.js +54 -55
- package/jsdoc.json +6 -3
- package/lib/classifier.js +24 -17
- package/lib/deploy.js +56 -64
- package/lib/helpers/cli.js +178 -207
- package/lib/helpers/util.js +94 -21
- package/lib/models/deployment.js +415 -474
- package/lib/models/request.js +77 -66
- package/lib/models/user.js +119 -144
- package/lib/server.js +187 -97
- package/lib/static/not-found.html +30 -0
- package/lib/static/page-could-not-load.html +30 -0
- package/lib/static/static-server.js +70 -0
- package/package.json +47 -34
- package/website/README.md +41 -0
- package/website/babel.config.js +3 -0
- package/website/docs/api/_category_.yml +1 -0
- package/website/docs/api/lib/classifier.js.md +11 -0
- package/website/docs/api/lib/deploy.js.md +13 -0
- package/website/docs/api/lib/helpers/cli.js.md +193 -0
- package/website/docs/api/lib/helpers/util.js.md +65 -0
- package/website/docs/api/lib/models/deployment.js.md +171 -0
- package/website/docs/api/lib/models/request.js.md +67 -0
- package/website/docs/api/lib/models/user.js.md +92 -0
- package/website/docs/api/lib/server.js.md +0 -0
- package/website/docs/api/lib/static/static-server.js.md +0 -0
- package/website/docs/intro.md +57 -0
- package/website/docusaurus.config.js +82 -0
- package/website/package-lock.json +25218 -0
- package/website/package.json +39 -0
- package/website/sidebars.js +31 -0
- package/website/src/components/HomepageFeatures/index.js +79 -0
- package/website/src/components/HomepageFeatures/styles.module.css +11 -0
- package/website/src/css/custom.css +39 -0
- package/website/src/pages/index.js +57 -0
- package/website/src/pages/index.module.css +23 -0
- package/website/static/.nojekyll +0 -0
- package/website/static/example.gif +0 -0
- package/website/static/example.mov +0 -0
- package/website/static/img/favicon.ico +0 -0
- package/website/static/img/intro/deploy.png +0 -0
- package/website/static/img/intro/logs.png +0 -0
- package/{docs → website/static/img}/logo.png +0 -0
- package/{docs → website/static/img}/logo.pxm +0 -0
- package/{docs → website/static/img}/logo@2x.png +0 -0
- package/.npmignore +0 -9
- package/.travis.yml +0 -9
- package/TODO.md +0 -12
- package/docs/code/classifier.js.html +0 -116
- package/docs/code/deploy.js.html +0 -138
- package/docs/code/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/code/fonts/OpenSans-Bold-webfont.svg +0 -1830
- package/docs/code/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/code/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/code/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
- package/docs/code/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/code/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/code/fonts/OpenSans-Italic-webfont.svg +0 -1830
- package/docs/code/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/code/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/code/fonts/OpenSans-Light-webfont.svg +0 -1831
- package/docs/code/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/code/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/code/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
- package/docs/code/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/code/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/code/fonts/OpenSans-Regular-webfont.svg +0 -1831
- package/docs/code/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/code/fonts/OpenSans-Semibold-webfont.eot +0 -0
- package/docs/code/fonts/OpenSans-Semibold-webfont.svg +0 -1830
- package/docs/code/fonts/OpenSans-Semibold-webfont.ttf +0 -0
- package/docs/code/fonts/OpenSans-Semibold-webfont.woff +0 -0
- package/docs/code/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
- package/docs/code/fonts/OpenSans-SemiboldItalic-webfont.svg +0 -1830
- package/docs/code/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
- package/docs/code/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
- package/docs/code/global.html +0 -325
- package/docs/code/helpers_cli.js.html +0 -351
- package/docs/code/helpers_util.js.html +0 -127
- package/docs/code/index.html +0 -81
- package/docs/code/models_deployment.js.html +0 -593
- package/docs/code/models_request.js.html +0 -150
- package/docs/code/models_user.js.html +0 -232
- package/docs/code/module-lib_classifier.html +0 -246
- package/docs/code/module-lib_deploy.html +0 -350
- package/docs/code/module-lib_helpers_cli.html +0 -2067
- package/docs/code/module-lib_helpers_util.html +0 -608
- package/docs/code/module-models_deployment-Deployment.html +0 -359
- package/docs/code/module-models_deployment-DeploymentSchema.html +0 -359
- package/docs/code/module-models_deployment.Deployment.html +0 -359
- package/docs/code/module-models_deployment.html +0 -1851
- package/docs/code/module-models_request-Request.html +0 -409
- package/docs/code/module-models_request-RequestSchema.html +0 -359
- package/docs/code/module-models_request.html +0 -446
- package/docs/code/module-models_user-User.html +0 -306
- package/docs/code/module-models_user-UserSchema.html +0 -306
- package/docs/code/module-models_user.User.html +0 -306
- package/docs/code/module-models_user.html +0 -1200
- package/docs/code/scripts/linenumber.js +0 -25
- package/docs/code/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/docs/code/scripts/prettify/lang-css.js +0 -2
- package/docs/code/scripts/prettify/prettify.js +0 -28
- package/docs/code/styles/jsdoc-default.css +0 -692
- package/docs/code/styles/prettify-jsdoc.css +0 -111
- package/docs/code/styles/prettify-tomorrow.css +0 -132
- package/docs/example-docker.gif +0 -0
- package/docs/example-node.gif +0 -0
- package/docs/example-static.gif +0 -0
- package/docs/index.html +0 -50
- package/docs/main.css +0 -12
- package/docs/psychic-min.css +0 -1
- package/lib/helpers/static-server.js +0 -69
- package/test/fixtures/docker/index.js +0 -12
- package/test/fixtures/node/index.js +0 -8
- package/test/fixtures/static/index.html +0 -14
- package/test/lib/classifier.js +0 -51
- package/test/lib/helpers/util.js +0 -30
package/index.js
CHANGED
|
@@ -1,70 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const ora = require('ora');
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import mongoose from "mongoose";
|
|
4
3
|
|
|
5
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
spinner.text = 'Connecting to mongo';
|
|
14
|
+
spinner.text = "Connecting to mongo";
|
|
15
|
+
await mongoose.connect(cli.mongo);
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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(
|
|
70
|
-
process.on(
|
|
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"
|
|
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": "
|
|
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
|
-
|
|
2
|
-
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { promisify } from "util";
|
|
3
4
|
|
|
4
|
-
|
|
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
|
-
|
|
15
|
+
async function classifier(directory) {
|
|
13
16
|
const files = fs.readdirSync(directory);
|
|
14
|
-
|
|
15
|
-
if(contains(files, [
|
|
16
|
-
let build =
|
|
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:
|
|
21
|
-
build
|
|
25
|
+
type: "docker",
|
|
26
|
+
build,
|
|
22
27
|
};
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
if(contains(files, [
|
|
30
|
+
if (contains(files, ["package.json"])) {
|
|
26
31
|
return {
|
|
27
|
-
type:
|
|
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, [
|
|
45
|
+
if (contains(files, ["index.html", "!Dockerfile", "!package.json"])) {
|
|
41
46
|
return {
|
|
42
|
-
type:
|
|
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:
|
|
59
|
+
type: "unknown",
|
|
55
60
|
};
|
|
56
|
-
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default classifier;
|
package/lib/deploy.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
6
|
+
const writeFile = promisify(fs.writeFile);
|
|
7
|
+
const readFile = promisify(fs.readFile);
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
}
|