@faable/faable 1.4.11 → 1.4.12
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/dist/builder/python/index.js +13 -1
- package/dist/builder/python/prepare_dockerfile.js +40 -0
- package/dist/builder/python/templates/Dockerfile +26 -0
- package/dist/builder/python/templates/entrypoint.sh +7 -0
- package/dist/commands/deploy/deploy_command.js +1 -1
- package/dist/index.js +0 -11
- package/dist/lib/Configuration.js +6 -4
- package/package.json +1 -1
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path__default from 'path';
|
|
3
|
+
import { prepare_dockerfile } from './prepare_dockerfile.js';
|
|
4
|
+
|
|
1
5
|
const builder = async (ctx) => {
|
|
2
|
-
|
|
6
|
+
const { workdir, log } = ctx;
|
|
7
|
+
const hasRequirements = fs.existsSync(path__default.join(path__default.resolve(workdir), "requirements.txt"));
|
|
8
|
+
if (!hasRequirements) {
|
|
9
|
+
throw new Error(`Missing requirements.txt`);
|
|
10
|
+
}
|
|
11
|
+
const { dockerfile } = await prepare_dockerfile(ctx);
|
|
12
|
+
return {
|
|
13
|
+
dockerfile,
|
|
14
|
+
};
|
|
3
15
|
};
|
|
4
16
|
|
|
5
17
|
export { builder, builder as default };
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
const entrypoint = fs
|
|
11
|
+
.readFileSync(`${templates_dir}/entrypoint.sh`)
|
|
12
|
+
.toString("utf-8");
|
|
13
|
+
Handlebars.registerHelper("escape", function (variable) {
|
|
14
|
+
//const escaped_quotes = variable.replace(/(['"])/g, "\\$1");
|
|
15
|
+
const escaped_lines = variable
|
|
16
|
+
.replace(/(['`\\])/g, "\\$1")
|
|
17
|
+
.replace(/([$])/g, "\\$1");
|
|
18
|
+
return escaped_lines.split("\n").join("\\n");
|
|
19
|
+
//return escaped_lines.split("\n").join("\\n");
|
|
20
|
+
});
|
|
21
|
+
// Docker template file
|
|
22
|
+
const docker_template = Handlebars.compile(dockerfile);
|
|
23
|
+
const entrypoint_template = Handlebars.compile(entrypoint);
|
|
24
|
+
const prepare_dockerfile = async (ctx, params = {}) => {
|
|
25
|
+
const { app, workdir, log, config } = ctx;
|
|
26
|
+
const entrypoint_custom = entrypoint_template(params);
|
|
27
|
+
const start_command = config.getConfigProperty("startCommand");
|
|
28
|
+
if (!start_command) {
|
|
29
|
+
throw new Error(`Missing start command configuration`);
|
|
30
|
+
}
|
|
31
|
+
log.info(`✅ Start command set to "${start_command}"`);
|
|
32
|
+
const dockerfile = docker_template({
|
|
33
|
+
...params,
|
|
34
|
+
entry_script: entrypoint_custom,
|
|
35
|
+
start_command,
|
|
36
|
+
});
|
|
37
|
+
return { dockerfile };
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { prepare_dockerfile };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
FROM python:3.9-slim
|
|
2
|
+
|
|
3
|
+
RUN apt-get update && apt-get install -y locales locales-all && rm -rf /var/lib/apt/lists/*
|
|
4
|
+
|
|
5
|
+
RUN sed -i '/es_ES.UTF-8/s/^# //g' /etc/locale.gen && \
|
|
6
|
+
locale-gen
|
|
7
|
+
|
|
8
|
+
ENV LANG es_ES.UTF-8
|
|
9
|
+
ENV LANGUAGE es_ES:es
|
|
10
|
+
ENV LC_ALL es_ES.UTF-8
|
|
11
|
+
|
|
12
|
+
ENV PORT=80
|
|
13
|
+
ENV START_COMMAND="{{start_command}}"
|
|
14
|
+
|
|
15
|
+
WORKDIR /app
|
|
16
|
+
|
|
17
|
+
COPY requirements.txt .
|
|
18
|
+
|
|
19
|
+
RUN pip install --no-cache-dir -r requirements.txt
|
|
20
|
+
|
|
21
|
+
COPY . .
|
|
22
|
+
|
|
23
|
+
# Entrypoint stript
|
|
24
|
+
RUN echo '{{{escape entry_script}}}' >> entrypoint.sh
|
|
25
|
+
|
|
26
|
+
CMD ["/bin/sh", "./entrypoint.sh"]
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,6 @@ import { deploy } from './commands/deploy/index.js';
|
|
|
6
6
|
import { log } from './log.js';
|
|
7
7
|
import { init } from './commands/init/index.js';
|
|
8
8
|
import { version } from './config.js';
|
|
9
|
-
import { Configuration } from './lib/Configuration.js';
|
|
10
9
|
|
|
11
10
|
const yg = yargs();
|
|
12
11
|
yg.scriptName("faable")
|
|
@@ -18,16 +17,6 @@ yg.scriptName("faable")
|
|
|
18
17
|
description: "Path to the local `faable.json` file",
|
|
19
18
|
string: true,
|
|
20
19
|
})
|
|
21
|
-
.middleware(function (argv) {
|
|
22
|
-
if (argv.config) {
|
|
23
|
-
Configuration.instance().setConfigFile(argv.config, {
|
|
24
|
-
ignoreWarnings: false,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
Configuration.instance();
|
|
29
|
-
}
|
|
30
|
-
}, true)
|
|
31
20
|
.command(deploy)
|
|
32
21
|
.command(apps)
|
|
33
22
|
.command(configure)
|
|
@@ -3,14 +3,16 @@ import fs from 'fs-extra';
|
|
|
3
3
|
import { log } from '../log.js';
|
|
4
4
|
|
|
5
5
|
class Configuration {
|
|
6
|
+
workdir;
|
|
6
7
|
static _instance;
|
|
7
8
|
config = {};
|
|
8
|
-
constructor() {
|
|
9
|
+
constructor(workdir) {
|
|
10
|
+
this.workdir = workdir;
|
|
9
11
|
// Try to read default config file
|
|
10
12
|
this.setConfigFile("faable.json", { ignoreWarnings: true });
|
|
11
13
|
}
|
|
12
14
|
setConfigFile(file, options) {
|
|
13
|
-
const config_file = path__default.join(
|
|
15
|
+
const config_file = path__default.join(this.workdir, file);
|
|
14
16
|
if (fs.existsSync(config_file)) {
|
|
15
17
|
this.config = fs.readJSONSync(config_file);
|
|
16
18
|
log.info(`Loaded configuration from: ${file}`);
|
|
@@ -21,9 +23,9 @@ class Configuration {
|
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
|
-
static instance() {
|
|
26
|
+
static instance(workdir) {
|
|
25
27
|
if (!Configuration._instance) {
|
|
26
|
-
Configuration._instance = new Configuration();
|
|
28
|
+
Configuration._instance = new Configuration(workdir);
|
|
27
29
|
}
|
|
28
30
|
return Configuration._instance;
|
|
29
31
|
}
|