@faable/faable 1.5.19 → 1.5.20
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.
|
@@ -1,22 +1,74 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { context } from '../../api/context.js';
|
|
2
|
+
import { cmd } from '../../lib/cmd.js';
|
|
3
|
+
import { log } from '../../log.js';
|
|
4
|
+
import { check_environment } from './check_environment.js';
|
|
5
|
+
import { build_node } from './node-pipeline/index.js';
|
|
6
|
+
import { runtime_detection } from './runtime-detect/runtime_detection.js';
|
|
7
|
+
import { upload_tag } from './upload_tag.js';
|
|
2
8
|
|
|
3
9
|
const deploy = {
|
|
4
|
-
command:
|
|
5
|
-
describe:
|
|
6
|
-
builder:
|
|
10
|
+
command: 'deploy [app_id]',
|
|
11
|
+
describe: 'Deploy a faable app',
|
|
12
|
+
builder: yargs => {
|
|
7
13
|
return yargs
|
|
8
|
-
.positional(
|
|
9
|
-
type:
|
|
10
|
-
description:
|
|
14
|
+
.positional('app_id', {
|
|
15
|
+
type: 'string',
|
|
16
|
+
description: 'App Identifier'
|
|
11
17
|
})
|
|
12
|
-
.option(
|
|
13
|
-
alias:
|
|
14
|
-
type:
|
|
15
|
-
description:
|
|
18
|
+
.option('workdir', {
|
|
19
|
+
alias: 'w',
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'Working directory'
|
|
16
22
|
})
|
|
17
23
|
.showHelpOnFail(false);
|
|
18
24
|
},
|
|
19
|
-
handler:
|
|
25
|
+
handler: async (args) => {
|
|
26
|
+
const workdir = args.workdir || process.cwd();
|
|
27
|
+
const ctx = await context();
|
|
28
|
+
const { api } = ctx;
|
|
29
|
+
// Resolve runtime
|
|
30
|
+
const { runtime } = await runtime_detection(workdir);
|
|
31
|
+
let app;
|
|
32
|
+
if (args.app_id) {
|
|
33
|
+
app = await api.getApp(args.app_id);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
if (ctx.appId) {
|
|
37
|
+
app = await api.getApp(ctx.appId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!app) {
|
|
41
|
+
throw new Error('Missing <app_id>');
|
|
42
|
+
}
|
|
43
|
+
// Check if we can build docker images
|
|
44
|
+
await check_environment();
|
|
45
|
+
log.info(`🚀 Deploying "${app.name}" (${app.id}) runtime=${runtime.name}-${runtime.version}`);
|
|
46
|
+
// get environment variables
|
|
47
|
+
const env_vars = await api.getAppSecrets(app.id);
|
|
48
|
+
let type;
|
|
49
|
+
if (runtime.name == 'node') {
|
|
50
|
+
const node_result = await build_node(app, {
|
|
51
|
+
workdir,
|
|
52
|
+
runtime,
|
|
53
|
+
env_vars
|
|
54
|
+
});
|
|
55
|
+
type = node_result.type;
|
|
56
|
+
}
|
|
57
|
+
else if (runtime.name == 'docker') {
|
|
58
|
+
type = 'node';
|
|
59
|
+
await cmd(`docker build -t ${app.id} .`, {
|
|
60
|
+
enableOutput: true
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new Error(`No build pipeline for runtime=${runtime.name}`);
|
|
65
|
+
}
|
|
66
|
+
// Upload to Faable registry
|
|
67
|
+
const { upload_tagname } = await upload_tag({ app, api });
|
|
68
|
+
// Create a deployment for this image
|
|
69
|
+
await api.createDeployment({ app_id: app.id, image: upload_tagname, type });
|
|
70
|
+
log.info(`🌍 Deployment created -> https://${app.url}`);
|
|
71
|
+
}
|
|
20
72
|
};
|
|
21
73
|
|
|
22
74
|
export { deploy };
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { strategy_nodejs } from './strategies/nodejs.js';
|
|
2
1
|
import * as R from 'ramda';
|
|
3
2
|
import { has_any_of_files } from './helpers/has_any_of_files.js';
|
|
4
3
|
import { strategy_docker } from './strategies/docker.js';
|
|
4
|
+
import { strategy_nodejs } from './strategies/nodejs.js';
|
|
5
5
|
|
|
6
6
|
const runtime_detection = async (workdir) => {
|
|
7
7
|
const has = R.curry(has_any_of_files);
|
|
8
8
|
const strategy = R.cond([
|
|
9
|
-
[has([
|
|
9
|
+
[has(['package.json']), R.always(strategy_nodejs)],
|
|
10
10
|
// [has(["requirements.txt"]), R.always(strategy_python)],
|
|
11
|
-
[has([
|
|
11
|
+
[has(['Dockerfile']), R.always(strategy_docker)]
|
|
12
12
|
])(workdir);
|
|
13
13
|
if (!strategy) {
|
|
14
|
-
throw new Error(
|
|
14
|
+
throw new Error('Cannot detect project type');
|
|
15
15
|
}
|
|
16
16
|
return strategy(workdir);
|
|
17
17
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faable/faable",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.20",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Marc Pomar <marc@faable.com>",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@rollup/plugin-json": "^6.1.0",
|
|
47
47
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
48
48
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
49
|
+
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
49
50
|
"@types/bluebird": "^3.5.38",
|
|
50
51
|
"@types/fs-extra": "^11.0.4",
|
|
51
52
|
"@types/node": "^24.10.2",
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { log } from '../../log.js';
|
|
2
|
-
import { upload_tag } from './upload_tag.js';
|
|
3
|
-
import { check_environment } from './check_environment.js';
|
|
4
|
-
import { context } from '../../api/context.js';
|
|
5
|
-
import { build_node } from './node-pipeline/index.js';
|
|
6
|
-
import { runtime_detection } from './runtime-detect/runtime_detection.js';
|
|
7
|
-
import { cmd } from '../../lib/cmd.js';
|
|
8
|
-
|
|
9
|
-
const deploy_command = async (args) => {
|
|
10
|
-
const workdir = args.workdir || process.cwd();
|
|
11
|
-
const { api, appId } = await context();
|
|
12
|
-
// Resolve runtime
|
|
13
|
-
const { app_name, runtime } = await runtime_detection(workdir);
|
|
14
|
-
let app;
|
|
15
|
-
if (args.app_slug) {
|
|
16
|
-
app = await api.getBySlug(args.app_slug);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
const oidc_app_id = appId;
|
|
20
|
-
if (oidc_app_id) {
|
|
21
|
-
app = await api.getApp(oidc_app_id);
|
|
22
|
-
}
|
|
23
|
-
else if (app_name) {
|
|
24
|
-
app = await api.getBySlug(app_name);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (!app) {
|
|
28
|
-
throw new Error("Missing <app_name>");
|
|
29
|
-
}
|
|
30
|
-
// Check if we can build docker images
|
|
31
|
-
await check_environment();
|
|
32
|
-
log.info(`🚀 Deploying ${app.name} (${app.id}) runtime=${runtime.name}-${runtime.version}`);
|
|
33
|
-
// get environment variables
|
|
34
|
-
const env_vars = await api.getAppSecrets(app.id);
|
|
35
|
-
let type;
|
|
36
|
-
if (runtime.name == "node") {
|
|
37
|
-
const node_result = await build_node(app, {
|
|
38
|
-
workdir,
|
|
39
|
-
runtime,
|
|
40
|
-
env_vars,
|
|
41
|
-
});
|
|
42
|
-
type = node_result.type;
|
|
43
|
-
}
|
|
44
|
-
else if (runtime.name == "docker") {
|
|
45
|
-
type = "node";
|
|
46
|
-
await cmd(`docker build -t ${app.id} .`, {
|
|
47
|
-
enableOutput: true,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
throw new Error(`No build pipeline for runtime=${runtime.name}`);
|
|
52
|
-
}
|
|
53
|
-
// Upload to Faable registry
|
|
54
|
-
const { upload_tagname } = await upload_tag({ app, api });
|
|
55
|
-
// Create a deployment for this image
|
|
56
|
-
await api.createDeployment({ app_id: app.id, image: upload_tagname, type });
|
|
57
|
-
log.info(`🌍 Deployment created -> https://${app.url}`);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export { deploy_command };
|