@faable/faable 1.1.1 → 1.2.1

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/README.md ADDED
@@ -0,0 +1,24 @@
1
+ <p align="center">
2
+ <a href="https://faable.com">
3
+ <img src="https://www.faable.com/logo/Emblem.png" height="96">
4
+ <h3 align="center">Faable</h3>
5
+ </a>
6
+ </p>
7
+
8
+ <p align="center">
9
+ Your React, Node.js or Python apps, up to the cloud in seconds.
10
+ </p>
11
+
12
+ ## Faable
13
+
14
+ Faable is the best platform to build modern architectures that scale precisely to meet demand. We handle the hard stuff so you can focus on building cloud ready apps. Make your business cloud driven and join those awesome companies.
15
+
16
+ To install the latest version of Faable CLI:
17
+
18
+ ```bash
19
+ npm i -g @faable/faable
20
+ ```
21
+
22
+ ## Documentation
23
+
24
+ For details on how to use Faable CLI, check out our [documentation](https://docs.faable.com/).
package/bin/faable.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import "../dist/index.js";
@@ -0,0 +1,14 @@
1
+ import { log } from '../../log.js';
2
+ import { cmd } from './cmd.js';
3
+
4
+ const build_docker = async (props) => {
5
+ const { app_name, workdir } = props;
6
+ //log.info("Building...");
7
+ await cmd("/bin/bash", [
8
+ "-c",
9
+ `docker build -t app ${workdir} -f .faable/Dockerfile`,
10
+ ]);
11
+ log.info(`✅ Build ${app_name} successful`);
12
+ };
13
+
14
+ export { build_docker };
@@ -0,0 +1,11 @@
1
+ import { spawn } from 'promisify-child-process';
2
+
3
+ const cmd = async (cmd, args) => {
4
+ const { stdout, stderr } = await spawn(cmd, args, {
5
+ encoding: "utf8",
6
+ stdio: "inherit",
7
+ });
8
+ return stdout;
9
+ };
10
+
11
+ export { cmd };
@@ -0,0 +1,42 @@
1
+ import { log } from '../../log.js';
2
+ import { build_docker } from './build_docker.js';
3
+ import { prepare } from './prepare.js';
4
+ import { upload_tag } from './upload_tag.js';
5
+ import fs from 'fs-extra';
6
+
7
+ const deploy = {
8
+ command: "deploy [app_name]",
9
+ describe: "Deploy a faable app",
10
+ builder: (yargs) => {
11
+ return yargs
12
+ .positional("app_name", {
13
+ type: "string",
14
+ description: "App name to build for",
15
+ default: (s) => {
16
+ const { name } = fs.readJSONSync("./package.json");
17
+ return name;
18
+ },
19
+ })
20
+ .option("workdir", {
21
+ alias: "w",
22
+ type: "string",
23
+ description: "Working directory",
24
+ default: process.cwd(),
25
+ })
26
+ .showHelpOnFail(false);
27
+ },
28
+ handler: async (args) => {
29
+ const { app_name, workdir } = args;
30
+ if (!app_name) {
31
+ throw new Error("Missing app_name");
32
+ }
33
+ log.info(`Building ${app_name}`);
34
+ await prepare({ from_image: "node:18.12.0", workdir });
35
+ await build_docker({ app_name, workdir });
36
+ // TODO: get this data from Faable API
37
+ //faablecloud#${ctx.faable_user}+deployment
38
+ await upload_tag({ app_name, user: "", password: "" });
39
+ },
40
+ };
41
+
42
+ export { deploy };
@@ -0,0 +1,33 @@
1
+ import fs from 'fs-extra';
2
+ import Handlebars from 'handlebars';
3
+ import * as path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+ const templates_dir = path.join(__dirname, "../../../templates");
9
+ const dockerfile = fs.readFileSync(`${templates_dir}/Dockerfile`).toString();
10
+ // Docker template file
11
+ const docker_template = Handlebars.compile(dockerfile);
12
+ const prepare = async (props) => {
13
+ const { from_image, build_script = "build", start_script = "start", workdir, } = props;
14
+ await fs.remove(path.join(workdir, ".faable"));
15
+ await fs.mkdirp(path.join(workdir, ".faable"));
16
+ //log.info(`Preparing Dockerfile`);
17
+ // Compose template with data and write to path
18
+ const composed_file_data = docker_template({
19
+ from_image,
20
+ build_script,
21
+ start_script,
22
+ });
23
+ // Create Dockerfile
24
+ let out = path.join(workdir, ".faable", "Dockerfile");
25
+ await fs.writeFile(out, composed_file_data);
26
+ //log.info(`Created ${out}`);
27
+ // Copy entrypoint file
28
+ let out2 = path.join(workdir, ".faable", "entrypoint.sh");
29
+ await fs.copyFile(path.join(templates_dir, "entrypoint.sh"), out2);
30
+ //log.info(`Created ${out2}`);
31
+ };
32
+
33
+ export { prepare };
@@ -0,0 +1,21 @@
1
+ import { log } from '../../log.js';
2
+ import { cmd } from './cmd.js';
3
+
4
+ const upload_tag = async (props) => {
5
+ const { hostname = "harbor.app.faable.com", user, password, app_name, } = props;
6
+ const tag = `${hostname}/${user}/${app_name}`;
7
+ // Registry login
8
+ await cmd("/bin/bash", [
9
+ "-c",
10
+ `echo "${password}" | docker login --username ${user} --password-stdin ${hostname}`,
11
+ ]);
12
+ log.info(`Logged in ${user}`);
13
+ // Tag image for production
14
+ await cmd("docker", ["tag", "app", tag]);
15
+ log.info(`Tagged image ${tag}`);
16
+ // Upload the image to faable registry
17
+ await cmd("docker", ["push", tag]);
18
+ log.info(`Uploaded ${tag}`);
19
+ };
20
+
21
+ export { upload_tag };
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import yargs from 'yargs';
2
+ import { hideBin } from 'yargs/helpers';
3
+ import { deploy } from './commands/deploy/deploy.js';
4
+
5
+ yargs(hideBin(process.argv))
6
+ .scriptName("faable")
7
+ .command(deploy)
8
+ .demandCommand(1)
9
+ .parse();
package/dist/log.js ADDED
@@ -0,0 +1,10 @@
1
+ import * as core from '@actions/core';
2
+
3
+ const log = {
4
+ error: core.error,
5
+ info: core.info,
6
+ warning: core.warning,
7
+ debug: core.debug,
8
+ };
9
+
10
+ export { log };
package/package.json CHANGED
@@ -1,29 +1,26 @@
1
1
  {
2
2
  "name": "@faable/faable",
3
- "version": "1.1.1",
4
- "main": "dist/faable.js",
5
- "license": "MIT",
6
- "author": "Marc Pomar <marc@faable.com>",
7
- "types": "dist/index.d.ts",
8
- "bugs": {
9
- "url": "https://github.com/faablecloud/faable/issues"
10
- },
11
- "homepage": "https://github.com/faablecloud/faable#readme",
12
- "bin": {
13
- "faable": "bin/faable"
14
- },
3
+ "main": "dist/index.js",
15
4
  "dependencies": {
16
5
  "@actions/core": "^1.10.0",
17
6
  "fs-extra": "^11.1.0",
18
7
  "handlebars": "^4.7.7",
19
8
  "promisify-child-process": "^4.1.1",
20
- "yargs": "^17.6.2",
21
- "tslib": "^2.4.1"
9
+ "yargs": "^17.6.2"
22
10
  },
23
- "engines": {
24
- "node": ">=16"
11
+ "bin": {
12
+ "faable": "bin/faable.js"
13
+ },
14
+ "type": "module",
15
+ "license": "MIT",
16
+ "author": "Marc Pomar <marc@faable.com>",
17
+ "types": "./dist/index.d.ts",
18
+ "bugs": {
19
+ "url": "https://github.com/faablecloud/faable/issues"
25
20
  },
26
21
  "publishConfig": {
27
22
  "access": "public"
28
- }
23
+ },
24
+ "homepage": "https://github.com/faablecloud/faable#readme",
25
+ "version": "1.2.1"
29
26
  }
@@ -0,0 +1,21 @@
1
+ FROM {{from_image}}
2
+ LABEL com.faable.cloud="FaableCloud"
3
+ LABEL description="Faablecloud automatic deployment"
4
+
5
+ WORKDIR /faable/app
6
+
7
+ # Environment variables for runtime
8
+ ENV PORT=80
9
+ ENV NODE_ENV=production
10
+
11
+ # Copy Usercode
12
+ COPY ../ /faable/app
13
+
14
+ # Build the project if requested
15
+ {{#if build_script}}
16
+ RUN echo "Running build command: {{build_script}}"
17
+ RUN yarn run {{build_script}}
18
+ {{/if}}
19
+
20
+
21
+ ENTRYPOINT ["/bin/sh", "/faable/app/entrypoint.sh","{{start_script}}"]
@@ -0,0 +1,12 @@
1
+ #!/bin/sh
2
+
3
+ NPM_RUN_COMMAND=$1
4
+
5
+ NODE_VERSION=$(node --version)
6
+ NPM_VERSION=$(npm --version)
7
+ YARN_VERSION=$(yarn --version)
8
+ echo "FaableCloud · Node:$NODE_VERSION NPM:$NPM_VERSION Yarn:$YARN_VERSION"
9
+ echo "Running npm script -> $NPM_RUN_COMMAND"
10
+
11
+
12
+ yarn run $NPM_RUN_COMMAND
package/bin/faable DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require("../dist/faable");
@@ -1,6 +0,0 @@
1
- interface BuildConfig {
2
- app_name: string;
3
- workdir: string;
4
- }
5
- export declare const build_docker: (props: BuildConfig) => Promise<void>;
6
- export {};
@@ -1,2 +0,0 @@
1
- /// <reference types="node" />
2
- export declare const cmd: (cmd: string, args?: string[]) => Promise<string | Buffer>;
@@ -1,7 +0,0 @@
1
- import { CommandModule } from "yargs";
2
- declare type Options = {
3
- app_name: string;
4
- workdir: string;
5
- };
6
- export declare const deploy: CommandModule<{}, Options>;
7
- export {};
@@ -1,8 +0,0 @@
1
- interface PrepareBuild {
2
- from_image: string;
3
- build_script?: string;
4
- start_script?: string;
5
- workdir: string;
6
- }
7
- export declare const prepare: (props: PrepareBuild) => Promise<void>;
8
- export {};
@@ -1,8 +0,0 @@
1
- interface RegistryUploadConfig {
2
- app_name: string;
3
- hostname?: string;
4
- user: string;
5
- password: string;
6
- }
7
- export declare const upload_tag: (props: RegistryUploadConfig) => Promise<void>;
8
- export {};
package/dist/faable.js DELETED
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const tslib_1 = require("tslib");
5
- const yargs_1 = (0, tslib_1.__importDefault)(require("yargs"));
6
- const helpers_1 = require("yargs/helpers");
7
- const deploy_1 = require("./commands/deploy");
8
- (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
9
- .scriptName("faable")
10
- .command(deploy_1.deploy)
11
- .demandCommand(1)
12
- .parse();
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/log.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import * as core from "@actions/core";
2
- export declare const log: {
3
- error: typeof core.error;
4
- info: typeof core.info;
5
- warning: typeof core.warning;
6
- debug: typeof core.debug;
7
- };