diff --git a/packages/bolt/build/actions/route-list.js b/packages/bolt/build/actions/route-list.js index 234aa52..75bf974 100644 --- a/packages/bolt/build/actions/route-list.js +++ b/packages/bolt/build/actions/route-list.js @@ -16,16 +16,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) { if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { - define(["require", "exports", "@gluestack/helpers", "../common", "../helpers/exit-with-msg", "../helpers/validate-metadata", "../helpers/validate-services"], factory); + define(["require", "exports", "path", "@gluestack/helpers", "../common", "../helpers/exit-with-msg", "../helpers/validate-metadata", "../helpers/validate-services", "../helpers/data-interpolate"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); + const path_1 = require("path"); const helpers_1 = require("@gluestack/helpers"); const common_1 = __importDefault(require("../common")); const exit_with_msg_1 = require("../helpers/exit-with-msg"); const validate_metadata_1 = require("../helpers/validate-metadata"); const validate_services_1 = require("../helpers/validate-services"); + const data_interpolate_1 = __importDefault(require("../helpers/data-interpolate")); class RouteList { handle() { return __awaiter(this, void 0, void 0, function* () { @@ -36,6 +38,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) { if (!_yamlContent.ingress || _yamlContent.ingress.length === 0) { return (0, exit_with_msg_1.exitWithMsg)(">> No ingress found in config. Skipping route generation..."); } + // interpolate all variables from yaml and inject .env file's vars + const content = yield (0, data_interpolate_1.default)(_yamlContent, (0, path_1.join)(process.cwd(), ".env")); const rows = []; const head = [ "Domain", @@ -46,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { "Rewrite Value", "Client MaxBody (in MB)", ]; - _yamlContent.ingress.forEach((ingress) => { + content.ingress.forEach((ingress) => { const domain = ingress.domain || undefined; const port = ingress.port || undefined; if (!domain || !port) { diff --git a/packages/bolt/build/actions/service-up.js b/packages/bolt/build/actions/service-up.js index f15e11a..2746546 100644 --- a/packages/bolt/build/actions/service-up.js +++ b/packages/bolt/build/actions/service-up.js @@ -16,12 +16,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) { if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { - define(["require", "exports", "chalk", "../helpers/docker-info", "../helpers/exit-with-msg", "../helpers/get-store", "../helpers/validate-metadata", "../helpers/validate-services", "../common", "../runners/service"], factory); + define(["require", "exports", "chalk", "path", "../helpers/docker-info", "../helpers/exit-with-msg", "../helpers/get-store", "../helpers/validate-metadata", "../helpers/validate-services", "../common", "../runners/service", "../helpers/data-interpolate"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chalk_1 = __importDefault(require("chalk")); + const path_1 = require("path"); const docker_info_1 = require("../helpers/docker-info"); const exit_with_msg_1 = require("../helpers/exit-with-msg"); const get_store_1 = __importDefault(require("../helpers/get-store")); @@ -29,6 +30,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { const validate_services_1 = require("../helpers/validate-services"); const common_1 = __importDefault(require("../common")); const service_1 = __importDefault(require("../runners/service")); + const data_interpolate_1 = __importDefault(require("../helpers/data-interpolate")); class ServiceUp { // checkIfAlreadyUp(_yamlContent, serviceName) { @@ -49,6 +51,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return true; } handle(serviceName, options) { + var _a, _b; return __awaiter(this, void 0, void 0, function* () { try { let { serviceRunner: srOption, cache } = options; @@ -68,8 +71,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) { console.log(chalk_1.default.yellow(`>> Given "${srOption}" service runner is not supported for ${serviceName}, using "${content.supported_service_runners[0]}" instead!`)); srOption = content.supported_service_runners[0]; } + const { envfile: localENV } = content.service_runners["local"]; + const { envfile: dockerENV } = content.service_runners["docker"]; + const localENVPath = (0, path_1.join)(servicePath, localENV); + const dockerENVPath = (0, path_1.join)(servicePath, dockerENV); // generates .env yield common_1.default.generateEnv(); + // Make data interpolate into service-runner's yaml content from given env file :: LOCAL + if ((_a = content === null || content === void 0 ? void 0 : content.service_runners) === null || _a === void 0 ? void 0 : _a.local) { + content.service_runners.local = yield (0, data_interpolate_1.default)(content.service_runners.local, localENVPath); + } + // Make data interpolate into service-runner's yaml content from given env file :: DOCKER + if ((_b = content === null || content === void 0 ? void 0 : content.service_runners) === null || _b === void 0 ? void 0 : _b.docker) { + content.service_runners.docker = yield (0, data_interpolate_1.default)(content.service_runners.docker, dockerENVPath); + } let isConfigValid = false; const serviceRunner = new service_1.default(); switch (srOption) { diff --git a/packages/bolt/build/actions/up.js b/packages/bolt/build/actions/up.js index f5e2ced..5733078 100644 --- a/packages/bolt/build/actions/up.js +++ b/packages/bolt/build/actions/up.js @@ -43,7 +43,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { const update_store_1 = require("../helpers/update-store"); class Up { handle(options) { - var _a, e_1, _b, _c; + var _a, e_1, _b, _c, _d, e_2, _e, _f; return __awaiter(this, void 0, void 0, function* () { let projectRunnerOption = "default"; const cache = options.cache || false; @@ -63,9 +63,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) { const vmRunners = ["vmlocal", "vmdocker"]; let isVmPresent = false; try { - for (var _d = true, _e = __asyncValues(Object.entries(_yamlContent.services)), _f; _f = yield _e.next(), _a = _f.done, !_a;) { - _c = _f.value; - _d = false; + for (var _g = true, _h = __asyncValues(Object.entries(_yamlContent.services)), _j; _j = yield _h.next(), _a = _j.done, !_a;) { + _c = _j.value; + _g = false; try { const [serviceName, service] = _c; if (data[serviceName] && data[serviceName].status !== "down") { @@ -80,14 +80,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) { } } finally { - _d = true; + _g = true; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { - if (!_d && !_a && (_b = _e.return)) yield _b.call(_e); + if (!_g && !_a && (_b = _h.return)) yield _b.call(_h); } finally { if (e_1) throw e_1.error; } } @@ -97,46 +97,61 @@ var __importDefault = (this && this.__importDefault) || function (mod) { yield boltVm.create(cache); yield (0, update_store_1.updateStore)("vm", "up"); } - Object.entries(_yamlContent.services).forEach(([serviceName]) => __awaiter(this, void 0, void 0, function* () { - if (data[serviceName] && data[serviceName].status !== "down") { - return; - } - // Validating and getting content from bolt.service.yaml - const { content } = yield common_1.default.getAndValidateService(serviceName, _yamlContent); - const { default_service_runner, supported_service_runners } = content; - let prepared_service_runner = default_service_runner; - if (projectRunnerOption === "host") { - if (!supported_service_runners.includes("local") && - !supported_service_runners.includes("docker")) { - console.log(chalk_1.default.red(`>> ${serviceName} does not includes host service runners. Skipping...`)); - return; + try { + for (var _k = true, _l = __asyncValues(Object.entries(_yamlContent.services)), _m; _m = yield _l.next(), _d = _m.done, !_d;) { + _f = _m.value; + _k = false; + try { + const [serviceName] = _f; + if (data[serviceName] && data[serviceName].status !== "down") { + continue; + } + // Validating and getting content from bolt.service.yaml + const { content } = yield common_1.default.getAndValidateService(serviceName, _yamlContent); + const { default_service_runner, supported_service_runners } = content; + let prepared_service_runner = default_service_runner; + if (projectRunnerOption === "host") { + if (!supported_service_runners.includes("local") && + !supported_service_runners.includes("docker")) { + console.log(chalk_1.default.red(`>> ${serviceName} does not includes host service runners. Skipping...`)); + continue; + } + else { + const availableRunners = supported_service_runners.filter((e) => !vmRunners.includes(e)); + prepared_service_runner = availableRunners[0]; + } + } + if (projectRunnerOption === "vm") { + if (!supported_service_runners.includes("vmlocal") && + !supported_service_runners.includes("vmdocker")) { + console.log(chalk_1.default.red(`>> ${serviceName} does not includes vm service runners. Skipping...`)); + continue; + } + else { + const availableRunners = supported_service_runners.filter((e) => !localRunners.includes(e)); + prepared_service_runner = availableRunners[0]; + } + } + const serviceUp = new service_up_1.default(); + serviceUpPromises.push(serviceUp.handle(serviceName, { + serviceRunner: prepared_service_runner, + cache: cache, + ports, + })); } - else { - const availableRunners = supported_service_runners.filter((e) => !vmRunners.includes(e)); - prepared_service_runner = availableRunners[0]; + finally { + _k = true; } } - if (projectRunnerOption === "vm") { - if (!supported_service_runners.includes("vmlocal") && - !supported_service_runners.includes("vmdocker")) { - console.log(chalk_1.default.red(`>> ${serviceName} does not includes vm service runners. Skipping...`)); - return; - } - else { - const availableRunners = supported_service_runners.filter((e) => !localRunners.includes(e)); - prepared_service_runner = availableRunners[0]; - } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (!_k && !_d && (_e = _l.return)) yield _e.call(_l); } - const serviceUp = new service_up_1.default(); - serviceUpPromises.push(serviceUp.handle(serviceName, { - serviceRunner: prepared_service_runner, - cache: cache, - ports, - })); - })); + finally { if (e_2) throw e_2.error; } + } yield Promise.all(serviceUpPromises); - // 2. generates .env - yield common_1.default.generateEnv(); // 5. starts nginx if the project runner is not vm and nginx config exists in bolt.yaml if (_yamlContent.ingress) { const nginxConfig = (0, path_1.join)(process.cwd(), bolt_configs_1.BOLT.NGINX_CONFIG_FILE_NAME); diff --git a/packages/bolt/build/common/index.js b/packages/bolt/build/common/index.js index 4542ed9..343ad82 100644 --- a/packages/bolt/build/common/index.js +++ b/packages/bolt/build/common/index.js @@ -40,9 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { yield (0, exit_with_msg_1.exitWithMsg)(`>> "${_yamlPath}" doesn't exists`); } const _yamlContent = yield (0, bolt_1.validateBolt)(yield (0, parse_yaml_1.parseYAML)(_yamlPath)); - if (!_yamlContent || - !_yamlContent.services || - (0, lodash_1.isEmpty)(_yamlContent.services)) { + if (!(_yamlContent === null || _yamlContent === void 0 ? void 0 : _yamlContent.services) || (0, lodash_1.isEmpty)(_yamlContent.services)) { yield (0, exit_with_msg_1.exitWithMsg)(`>> "${bolt_configs_1.BOLT.YAML_FILE_NAME}" services does not exists`); } return _yamlContent; diff --git a/packages/bolt/build/helpers/data-interpolate.d.ts b/packages/bolt/build/helpers/data-interpolate.d.ts new file mode 100644 index 0000000..dad9063 --- /dev/null +++ b/packages/bolt/build/helpers/data-interpolate.d.ts @@ -0,0 +1,2 @@ +declare const interpolateEnvVariables: (data: any, envFilePath: string) => Promise; +export default interpolateEnvVariables; diff --git a/packages/bolt/build/helpers/data-interpolate.js b/packages/bolt/build/helpers/data-interpolate.js new file mode 100644 index 0000000..14bef8c --- /dev/null +++ b/packages/bolt/build/helpers/data-interpolate.js @@ -0,0 +1,59 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./fs-readfile"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + const fs_readfile_1 = require("./fs-readfile"); + const interpolateEnvVariables = (data, envFilePath) => __awaiter(void 0, void 0, void 0, function* () { + const envContent = yield (0, fs_readfile_1.readfile)(envFilePath); + if (!envContent) { + return data; + } + const envVars = envContent + .split('\n') + .filter((line) => line.trim() && !line.trim().startsWith('#')) + .map((line) => { + const [key, value] = line.split('='); + return { key: key.trim(), value: value.trim() }; + }); + const interpolateObject = (obj) => { + if (typeof obj === 'string') { + const regex = /\${(.+?)}/g; + return obj.replace(regex, (_, varName) => { + const envVar = envVars.find(env => env.key === varName); + return envVar ? envVar.value : ''; + }); + } + else if (Array.isArray(obj)) { + return obj.map(item => interpolateObject(item)); + } + else if (typeof obj === 'object') { + const newObj = {}; + for (const key in obj) { + newObj[key] = interpolateObject(obj[key]); + } + return newObj; + } + else { + return obj; + } + }; + return interpolateObject(data); + }); + exports.default = interpolateEnvVariables; +}); diff --git a/packages/bolt/build/helpers/generate-routes.js b/packages/bolt/build/helpers/generate-routes.js index 80bb017..892b4c7 100644 --- a/packages/bolt/build/helpers/generate-routes.js +++ b/packages/bolt/build/helpers/generate-routes.js @@ -16,7 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { - define(["require", "exports", "chalk", "@gluestack/helpers", "path", "./fs-removefile", "lodash", "../constants/bolt-configs"], factory); + define(["require", "exports", "chalk", "@gluestack/helpers", "path", "./fs-removefile", "lodash", "../constants/bolt-configs", "./data-interpolate"], factory); } })(function (require, exports) { "use strict"; @@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { const fs_removefile_1 = require("./fs-removefile"); const lodash_1 = require("lodash"); const bolt_configs_1 = require("../constants/bolt-configs"); + const data_interpolate_1 = __importDefault(require("./data-interpolate")); function generateRoutes(_yamlContent) { return __awaiter(this, void 0, void 0, function* () { yield (0, fs_removefile_1.removefile)((0, path_1.join)(process.cwd(), bolt_configs_1.BOLT.NGINX_CONFIG_FILE_NAME)); @@ -34,6 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { console.log(chalk_1.default.gray(">> No ingress found in config. Skipping route generation...")); return []; } + // construct all servers const serverBlocks = _yamlContent.ingress .map((ingress) => { const domain = ingress.domain || undefined; @@ -83,6 +85,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }`; }) .join("\n"); + // prepare bolt.nginx.conf file's content const nginxConfig = ` user nginx; worker_processes auto; @@ -120,8 +123,12 @@ http { ${serverBlocks} } `; + // prepare bolt.nginx.conf file's path const nginxFile = (0, path_1.join)(process.cwd(), bolt_configs_1.BOLT.NGINX_CONFIG_FILE_NAME); - yield (0, helpers_1.writeFile)(nginxFile, nginxConfig); + // interpolate all variables from yaml and inject .env file's vars + const { content } = yield (0, data_interpolate_1.default)({ content: nginxConfig }, (0, path_1.join)(process.cwd(), ".env")); + // write bolt.nginx.conf file + yield (0, helpers_1.writeFile)(nginxFile, content); console.log(chalk_1.default.green(`>> ${_yamlContent.project_name} created "${bolt_configs_1.BOLT.NGINX_CONFIG_FILE_NAME}".`)); const ports = (0, lodash_1.map)(_yamlContent.ingress, "port"); return ports; diff --git a/packages/bolt/build/index.js b/packages/bolt/build/index.js old mode 100755 new mode 100644 diff --git a/packages/bolt/build/libraries/ingress.js b/packages/bolt/build/libraries/ingress.js index 18ec61e..3914f18 100644 --- a/packages/bolt/build/libraries/ingress.js +++ b/packages/bolt/build/libraries/ingress.js @@ -60,7 +60,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { } args.push(image); yield Ingress.removeIfExist(containerName); - console.log("Running docker", args.join(" ")); + console.log(">> Running boltingress"); yield (0, execute_1.execute)("docker", args, { stdio: "inherit", shell: true, diff --git a/packages/bolt/package.json b/packages/bolt/package.json index 0d43022..9575214 100644 --- a/packages/bolt/package.json +++ b/packages/bolt/package.json @@ -1,6 +1,6 @@ { "name": "@gluestack/bolt", - "version": "0.1.13", + "version": "0.1.14", "description": "Bolt Framework CLI", "main": "build/index.js", "bin": { diff --git a/packages/bolt/src/actions/route-list.ts b/packages/bolt/src/actions/route-list.ts index 8b1224c..edf4c3d 100644 --- a/packages/bolt/src/actions/route-list.ts +++ b/packages/bolt/src/actions/route-list.ts @@ -1,3 +1,4 @@ +import { join } from "path"; import { ConsoleTable } from "@gluestack/helpers"; import Common from "../common"; @@ -6,6 +7,7 @@ import { exitWithMsg } from "../helpers/exit-with-msg"; import { validateMetadata } from "../helpers/validate-metadata"; import { validateServices } from "../helpers/validate-services"; import { Ingress, Option } from "../typings/ingress"; +import interpolate from "../helpers/data-interpolate"; export default class RouteList { public async handle() { @@ -21,6 +23,9 @@ export default class RouteList { ); } + // interpolate all variables from yaml and inject .env file's vars + const content = await interpolate(_yamlContent, join(process.cwd(), ".env")); + const rows = [] as Array>; const head: Array = [ "Domain", @@ -32,7 +37,7 @@ export default class RouteList { "Client MaxBody (in MB)", ]; - _yamlContent.ingress.forEach((ingress: Ingress) => { + content.ingress.forEach((ingress: Ingress) => { const domain = ingress.domain || undefined; const port = ingress.port || undefined; if (!domain || !port) { diff --git a/packages/bolt/src/actions/service-up.ts b/packages/bolt/src/actions/service-up.ts index 267bfcd..6a1d797 100644 --- a/packages/bolt/src/actions/service-up.ts +++ b/packages/bolt/src/actions/service-up.ts @@ -1,5 +1,5 @@ import chalk from "chalk"; -import { join, relative } from "path"; +import { join } from "path"; import { getDockerStatus } from "../helpers/docker-info"; import { exitWithMsg } from "../helpers/exit-with-msg"; @@ -20,6 +20,7 @@ import { VMConfig, } from "../typings/service-runner-config"; import { BoltService, hostServicerunner } from "../typings/bolt-service"; +import interpolate from "../helpers/data-interpolate"; export default class ServiceUp { // @@ -85,9 +86,29 @@ export default class ServiceUp { srOption = content.supported_service_runners[0]; } + const { envfile: localENV } = content.service_runners["local"]; + const { envfile: dockerENV } = content.service_runners["docker"]; + + const localENVPath = join(servicePath, localENV); + const dockerENVPath = join(servicePath, dockerENV); + // generates .env await Common.generateEnv(); + // Make data interpolate into service-runner's yaml content from given env file :: LOCAL + if (content?.service_runners?.local) { + content.service_runners.local = await interpolate( + content.service_runners.local, localENVPath + ); + } + + // Make data interpolate into service-runner's yaml content from given env file :: DOCKER + if (content?.service_runners?.docker) { + content.service_runners.docker = await interpolate( + content.service_runners.docker, dockerENVPath + ); + } + let isConfigValid = false; const serviceRunner = new ServiceRunner(); switch (srOption) { diff --git a/packages/bolt/src/actions/up.ts b/packages/bolt/src/actions/up.ts index 3672f08..e9edf2b 100644 --- a/packages/bolt/src/actions/up.ts +++ b/packages/bolt/src/actions/up.ts @@ -74,9 +74,9 @@ export default class Up { await updateStore("vm", "up"); } - Object.entries(_yamlContent.services).forEach(async ([serviceName]) => { + for await (const [serviceName] of Object.entries(_yamlContent.services)) { if (data[serviceName] && data[serviceName].status !== "down") { - return; + continue; } // Validating and getting content from bolt.service.yaml @@ -98,7 +98,7 @@ export default class Up { `>> ${serviceName} does not includes host service runners. Skipping...` ) ); - return; + continue; } else { const availableRunners = supported_service_runners.filter( (e) => !vmRunners.includes(e) @@ -117,7 +117,7 @@ export default class Up { `>> ${serviceName} does not includes vm service runners. Skipping...` ) ); - return; + continue; } else { const availableRunners = supported_service_runners.filter( (e) => !localRunners.includes(e) @@ -135,13 +135,10 @@ export default class Up { ports, }) ); - }); + } await Promise.all(serviceUpPromises); - // 2. generates .env - await Common.generateEnv(); - // 5. starts nginx if the project runner is not vm and nginx config exists in bolt.yaml if (_yamlContent.ingress) { const nginxConfig = join(process.cwd(), BOLT.NGINX_CONFIG_FILE_NAME); diff --git a/packages/bolt/src/common/index.ts b/packages/bolt/src/common/index.ts index 877b134..6469be1 100644 --- a/packages/bolt/src/common/index.ts +++ b/packages/bolt/src/common/index.ts @@ -20,9 +20,7 @@ export default class Common { const _yamlContent = await validateBolt(await parseYAML(_yamlPath)); if ( - !_yamlContent || - !_yamlContent.services || - isEmpty(_yamlContent.services) + !_yamlContent?.services || isEmpty(_yamlContent.services) ) { await exitWithMsg(`>> "${BOLT.YAML_FILE_NAME}" services does not exists`); } diff --git a/packages/bolt/src/helpers/data-interpolate.ts b/packages/bolt/src/helpers/data-interpolate.ts new file mode 100644 index 0000000..c37fced --- /dev/null +++ b/packages/bolt/src/helpers/data-interpolate.ts @@ -0,0 +1,45 @@ +import { readfile } from './fs-readfile'; + +interface EnvVar { + key: string; + value: string; +} + +const interpolateEnvVariables = async (data: any, envFilePath: string): Promise => { + const envContent = await readfile(envFilePath); + if (!envContent) { + return data; + } + + const envVars: EnvVar[] = envContent + .split('\n') + .filter((line: any) => line.trim() && !line.trim().startsWith('#')) + .map((line: any) => { + const [key, value] = line.split('='); + return { key: key.trim(), value: value.trim() }; + }); + + const interpolateObject = (obj: any): any => { + if (typeof obj === 'string') { + const regex = /\${(.+?)}/g; + return obj.replace(regex, (_, varName) => { + const envVar = envVars.find(env => env.key === varName); + return envVar ? envVar.value : ''; + }); + } else if (Array.isArray(obj)) { + return obj.map(item => interpolateObject(item)); + } else if (typeof obj === 'object') { + const newObj: any = {}; + for (const key in obj) { + newObj[key] = interpolateObject(obj[key]); + } + return newObj; + } else { + return obj; + } + }; + + return interpolateObject(data); +} + +export default interpolateEnvVariables; diff --git a/packages/bolt/src/helpers/generate-routes.ts b/packages/bolt/src/helpers/generate-routes.ts index 57a2588..fe1d305 100644 --- a/packages/bolt/src/helpers/generate-routes.ts +++ b/packages/bolt/src/helpers/generate-routes.ts @@ -6,6 +6,7 @@ import { removefile } from "./fs-removefile"; import { map } from "lodash"; import { Bolt } from "../typings/bolt"; import { BOLT } from "../constants/bolt-configs"; +import interpolate from "./data-interpolate"; export default async function generateRoutes(_yamlContent: Bolt): Promise { await removefile(join(process.cwd(), BOLT.NGINX_CONFIG_FILE_NAME)); @@ -17,6 +18,7 @@ export default async function generateRoutes(_yamlContent: Bolt): Promise { return []; } + // construct all servers const serverBlocks = _yamlContent.ingress .map((ingress: Ingress) => { const domain = ingress.domain || undefined; @@ -78,6 +80,7 @@ export default async function generateRoutes(_yamlContent: Bolt): Promise { }) .join("\n"); + // prepare bolt.nginx.conf file's content const nginxConfig = ` user nginx; worker_processes auto; @@ -116,9 +119,14 @@ http { } `; + // prepare bolt.nginx.conf file's path const nginxFile = join(process.cwd(), BOLT.NGINX_CONFIG_FILE_NAME); - await writeFile(nginxFile, nginxConfig); + // interpolate all variables from yaml and inject .env file's vars + const { content } = await interpolate({ content: nginxConfig }, join(process.cwd(), ".env")); + + // write bolt.nginx.conf file + await writeFile(nginxFile, content); console.log( chalk.green( diff --git a/packages/bolt/src/libraries/ingress.ts b/packages/bolt/src/libraries/ingress.ts index 80ddd64..054cbe5 100644 --- a/packages/bolt/src/libraries/ingress.ts +++ b/packages/bolt/src/libraries/ingress.ts @@ -50,7 +50,7 @@ export default class Ingress { await Ingress.removeIfExist(containerName); - console.log("Running docker", args.join(" ")); + console.log(">> Running boltingress"); await execute("docker", args, { stdio: "inherit", diff --git a/packages/bolt/src/typings/bolt-service.ts b/packages/bolt/src/typings/bolt-service.ts index 2e2e56a..cc59e97 100644 --- a/packages/bolt/src/typings/bolt-service.ts +++ b/packages/bolt/src/typings/bolt-service.ts @@ -1,9 +1,9 @@ export interface BoltServicePlatform { envfile: string; build: string; - // depends_on?: any; ports?: any[]; volumes?: any[]; + // depends_on?: any; // context?: string; }