@faable/faable 1.5.19 → 1.5.21

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,67 @@
1
- import { deploy_command } from './deploy_command.js';
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: "deploy [app_slug]",
5
- describe: "Deploy a faable app",
6
- builder: (yargs) => {
10
+ command: 'deploy [app_id]',
11
+ describe: 'Deploy a faable app',
12
+ builder: yargs => {
7
13
  return yargs
8
- .positional("app_slug", {
9
- type: "string",
10
- description: "App slug",
14
+ .positional('app_id', {
15
+ type: 'string',
16
+ description: 'App Identifier'
11
17
  })
12
- .option("workdir", {
13
- alias: "w",
14
- type: "string",
15
- description: "Working directory",
18
+ .option('workdir', {
19
+ alias: 'w',
20
+ type: 'string',
21
+ description: 'Working directory'
16
22
  })
17
23
  .showHelpOnFail(false);
18
24
  },
19
- handler: deploy_command,
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
+ const app_id = args.app_id || ctx.appId;
32
+ if (!app_id) {
33
+ throw new Error('Missing <app_id>, run inside github action or pass <app_id> after deploy command');
34
+ }
35
+ const app = await api.getApp(app_id);
36
+ // Check if we can build docker images
37
+ await check_environment();
38
+ log.info(`🚀 Deploying "${app.name}" (${app.id}) runtime=${runtime.name}-${runtime.version}`);
39
+ // get environment variables
40
+ const env_vars = await api.getAppSecrets(app.id);
41
+ let type;
42
+ if (runtime.name == 'node') {
43
+ const node_result = await build_node(app, {
44
+ workdir,
45
+ runtime,
46
+ env_vars
47
+ });
48
+ type = node_result.type;
49
+ }
50
+ else if (runtime.name == 'docker') {
51
+ type = 'node';
52
+ await cmd(`docker build -t ${app.id} .`, {
53
+ enableOutput: true
54
+ });
55
+ }
56
+ else {
57
+ throw new Error(`No build pipeline for runtime=${runtime.name}`);
58
+ }
59
+ // Upload to Faable registry
60
+ const { upload_tagname } = await upload_tag({ app, api });
61
+ // Create a deployment for this image
62
+ await api.createDeployment({ app_id: app.id, image: upload_tagname, type });
63
+ log.info(`🌍 Deployment created -> https://${app.url}`);
64
+ }
20
65
  };
21
66
 
22
67
  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(["package.json"]), R.always(strategy_nodejs)],
9
+ [has(['package.json']), R.always(strategy_nodejs)],
10
10
  // [has(["requirements.txt"]), R.always(strategy_python)],
11
- [has(["Dockerfile"]), R.always(strategy_docker)],
11
+ [has(['Dockerfile']), R.always(strategy_docker)]
12
12
  ])(workdir);
13
13
  if (!strategy) {
14
- throw new Error("Cannot detect project type");
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.19",
3
+ "version": "1.5.21",
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 };