Merge pull request #1673 from jnsgruk/conf-dir-override
Override config directory with env var.
This commit is contained in:
commit
2d8af6eaf6
8 changed files with 28 additions and 24 deletions
|
@ -2,7 +2,7 @@ import { join } from "path";
|
||||||
import { createHash } from "crypto";
|
import { createHash } from "crypto";
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
|
|
||||||
import checkAndCopyConfig from "utils/config/config";
|
import checkAndCopyConfig, { CONF_DIR } from "utils/config/config";
|
||||||
|
|
||||||
const configs = ["docker.yaml", "settings.yaml", "services.yaml", "bookmarks.yaml", "widgets.yaml"];
|
const configs = ["docker.yaml", "settings.yaml", "services.yaml", "bookmarks.yaml", "widgets.yaml"];
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ function hash(buffer) {
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
const hashes = configs.map((config) => {
|
const hashes = configs.map((config) => {
|
||||||
checkAndCopyConfig(config);
|
checkAndCopyConfig(config);
|
||||||
const configYaml = join(process.cwd(), "config", config);
|
const configYaml = join(CONF_DIR, config);
|
||||||
return hash(readFileSync(configYaml, "utf8"));
|
return hash(readFileSync(configYaml, "utf8"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import path from "path";
|
||||||
|
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
|
|
||||||
import checkAndCopyConfig, { getSettings, substituteEnvironmentVars } from "utils/config/config";
|
import checkAndCopyConfig, { getSettings, substituteEnvironmentVars, CONF_DIR } from "utils/config/config";
|
||||||
import {
|
import {
|
||||||
servicesFromConfig,
|
servicesFromConfig,
|
||||||
servicesFromDocker,
|
servicesFromDocker,
|
||||||
|
@ -27,7 +27,7 @@ function compareServices(service1, service2) {
|
||||||
export async function bookmarksResponse() {
|
export async function bookmarksResponse() {
|
||||||
checkAndCopyConfig("bookmarks.yaml");
|
checkAndCopyConfig("bookmarks.yaml");
|
||||||
|
|
||||||
const bookmarksYaml = path.join(process.cwd(), "config", "bookmarks.yaml");
|
const bookmarksYaml = path.join(CONF_DIR, "bookmarks.yaml");
|
||||||
const rawFileContents = await fs.readFile(bookmarksYaml, "utf8");
|
const rawFileContents = await fs.readFile(bookmarksYaml, "utf8");
|
||||||
const fileContents = substituteEnvironmentVars(rawFileContents);
|
const fileContents = substituteEnvironmentVars(rawFileContents);
|
||||||
const bookmarks = yaml.load(fileContents);
|
const bookmarks = yaml.load(fileContents);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { existsSync, readFileSync, copyFileSync } from "fs";
|
import { copyFileSync, existsSync, mkdirSync, readFileSync } from "fs";
|
||||||
|
|
||||||
import cache from "memory-cache";
|
import cache from "memory-cache";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
|
@ -9,8 +9,14 @@ const cacheKey = "homepageEnvironmentVariables";
|
||||||
const homepageVarPrefix = "HOMEPAGE_VAR_";
|
const homepageVarPrefix = "HOMEPAGE_VAR_";
|
||||||
const homepageFilePrefix = "HOMEPAGE_FILE_";
|
const homepageFilePrefix = "HOMEPAGE_FILE_";
|
||||||
|
|
||||||
|
export const CONF_DIR = process.env.HOMEPAGE_CONFIG_DIR ? process.env.HOMEPAGE_CONFIG_DIR : join(process.cwd(), "config");
|
||||||
|
|
||||||
export default function checkAndCopyConfig(config) {
|
export default function checkAndCopyConfig(config) {
|
||||||
const configYaml = join(process.cwd(), "config", config);
|
if (!existsSync(CONF_DIR)) {
|
||||||
|
mkdirSync(CONF_DIR, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
const configYaml = join(CONF_DIR, config);
|
||||||
if (!existsSync(configYaml)) {
|
if (!existsSync(configYaml)) {
|
||||||
const configSkeleton = join(process.cwd(), "src", "skeleton", config);
|
const configSkeleton = join(process.cwd(), "src", "skeleton", config);
|
||||||
try {
|
try {
|
||||||
|
@ -62,7 +68,7 @@ export function substituteEnvironmentVars(str) {
|
||||||
export function getSettings() {
|
export function getSettings() {
|
||||||
checkAndCopyConfig("settings.yaml");
|
checkAndCopyConfig("settings.yaml");
|
||||||
|
|
||||||
const settingsYaml = join(process.cwd(), "config", "settings.yaml");
|
const settingsYaml = join(CONF_DIR, "settings.yaml");
|
||||||
const rawFileContents = readFileSync(settingsYaml, "utf8");
|
const rawFileContents = readFileSync(settingsYaml, "utf8");
|
||||||
const fileContents = substituteEnvironmentVars(rawFileContents);
|
const fileContents = substituteEnvironmentVars(rawFileContents);
|
||||||
const initialSettings = yaml.load(fileContents) ?? {};
|
const initialSettings = yaml.load(fileContents) ?? {};
|
||||||
|
@ -79,6 +85,5 @@ export function getSettings() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return initialSettings
|
return initialSettings
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@ import { readFileSync } from "fs";
|
||||||
|
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
|
|
||||||
import checkAndCopyConfig, { substituteEnvironmentVars } from "utils/config/config";
|
import checkAndCopyConfig, { CONF_DIR, substituteEnvironmentVars } from "utils/config/config";
|
||||||
|
|
||||||
export default function getDockerArguments(server) {
|
export default function getDockerArguments(server) {
|
||||||
checkAndCopyConfig("docker.yaml");
|
checkAndCopyConfig("docker.yaml");
|
||||||
|
|
||||||
const configFile = path.join(process.cwd(), "config", "docker.yaml");
|
const configFile = path.join(CONF_DIR, "docker.yaml");
|
||||||
const rawConfigData = readFileSync(configFile, "utf8");
|
const rawConfigData = readFileSync(configFile, "utf8");
|
||||||
const configData = substituteEnvironmentVars(rawConfigData);
|
const configData = substituteEnvironmentVars(rawConfigData);
|
||||||
const servers = yaml.load(configData);
|
const servers = yaml.load(configData);
|
||||||
|
@ -37,9 +37,9 @@ export default function getDockerArguments(server) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (servers[server].tls){
|
if (servers[server].tls){
|
||||||
res.conn.ca = readFileSync(path.join(process.cwd(), "config", servers[server].tls.caFile));
|
res.conn.ca = readFileSync(path.join(CONF_DIR, servers[server].tls.caFile));
|
||||||
res.conn.cert = readFileSync(path.join(process.cwd(), "config", servers[server].tls.certFile));
|
res.conn.cert = readFileSync(path.join(CONF_DIR, servers[server].tls.certFile));
|
||||||
res.conn.key = readFileSync(path.join(process.cwd(), "config", servers[server].tls.keyFile));
|
res.conn.key = readFileSync(path.join(CONF_DIR, servers[server].tls.keyFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -4,12 +4,12 @@ import { readFileSync } from "fs";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import { KubeConfig } from "@kubernetes/client-node";
|
import { KubeConfig } from "@kubernetes/client-node";
|
||||||
|
|
||||||
import checkAndCopyConfig, { substituteEnvironmentVars } from "utils/config/config";
|
import checkAndCopyConfig, { CONF_DIR, substituteEnvironmentVars } from "utils/config/config";
|
||||||
|
|
||||||
export default function getKubeConfig() {
|
export default function getKubeConfig() {
|
||||||
checkAndCopyConfig("kubernetes.yaml");
|
checkAndCopyConfig("kubernetes.yaml");
|
||||||
|
|
||||||
const configFile = path.join(process.cwd(), "config", "kubernetes.yaml");
|
const configFile = path.join(CONF_DIR, "kubernetes.yaml");
|
||||||
const rawConfigData = readFileSync(configFile, "utf8");
|
const rawConfigData = readFileSync(configFile, "utf8");
|
||||||
const configData = substituteEnvironmentVars(rawConfigData);
|
const configData = substituteEnvironmentVars(rawConfigData);
|
||||||
const config = yaml.load(configData);
|
const config = yaml.load(configData);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import * as shvl from "shvl";
|
||||||
import { CustomObjectsApi, NetworkingV1Api } from "@kubernetes/client-node";
|
import { CustomObjectsApi, NetworkingV1Api } from "@kubernetes/client-node";
|
||||||
|
|
||||||
import createLogger from "utils/logger";
|
import createLogger from "utils/logger";
|
||||||
import checkAndCopyConfig, { substituteEnvironmentVars } from "utils/config/config";
|
import checkAndCopyConfig, { CONF_DIR, substituteEnvironmentVars } from "utils/config/config";
|
||||||
import getDockerArguments from "utils/config/docker";
|
import getDockerArguments from "utils/config/docker";
|
||||||
import getKubeConfig from "utils/config/kubernetes";
|
import getKubeConfig from "utils/config/kubernetes";
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ const logger = createLogger("service-helpers");
|
||||||
export async function servicesFromConfig() {
|
export async function servicesFromConfig() {
|
||||||
checkAndCopyConfig("services.yaml");
|
checkAndCopyConfig("services.yaml");
|
||||||
|
|
||||||
const servicesYaml = path.join(process.cwd(), "config", "services.yaml");
|
const servicesYaml = path.join(CONF_DIR, "services.yaml");
|
||||||
const rawFileContents = await fs.readFile(servicesYaml, "utf8");
|
const rawFileContents = await fs.readFile(servicesYaml, "utf8");
|
||||||
const fileContents = substituteEnvironmentVars(rawFileContents);
|
const fileContents = substituteEnvironmentVars(rawFileContents);
|
||||||
const services = yaml.load(fileContents);
|
const services = yaml.load(fileContents);
|
||||||
|
@ -51,7 +51,7 @@ export async function servicesFromConfig() {
|
||||||
export async function servicesFromDocker() {
|
export async function servicesFromDocker() {
|
||||||
checkAndCopyConfig("docker.yaml");
|
checkAndCopyConfig("docker.yaml");
|
||||||
|
|
||||||
const dockerYaml = path.join(process.cwd(), "config", "docker.yaml");
|
const dockerYaml = path.join(CONF_DIR, "docker.yaml");
|
||||||
const rawDockerFileContents = await fs.readFile(dockerYaml, "utf8");
|
const rawDockerFileContents = await fs.readFile(dockerYaml, "utf8");
|
||||||
const dockerFileContents = substituteEnvironmentVars(rawDockerFileContents);
|
const dockerFileContents = substituteEnvironmentVars(rawDockerFileContents);
|
||||||
const servers = yaml.load(dockerFileContents);
|
const servers = yaml.load(dockerFileContents);
|
||||||
|
|
|
@ -3,12 +3,12 @@ import path from "path";
|
||||||
|
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
|
|
||||||
import checkAndCopyConfig, { substituteEnvironmentVars } from "utils/config/config";
|
import checkAndCopyConfig, { CONF_DIR, substituteEnvironmentVars } from "utils/config/config";
|
||||||
|
|
||||||
export async function widgetsFromConfig() {
|
export async function widgetsFromConfig() {
|
||||||
checkAndCopyConfig("widgets.yaml");
|
checkAndCopyConfig("widgets.yaml");
|
||||||
|
|
||||||
const widgetsYaml = path.join(process.cwd(), "config", "widgets.yaml");
|
const widgetsYaml = path.join(CONF_DIR, "widgets.yaml");
|
||||||
const rawFileContents = await fs.readFile(widgetsYaml, "utf8");
|
const rawFileContents = await fs.readFile(widgetsYaml, "utf8");
|
||||||
const fileContents = substituteEnvironmentVars(rawFileContents);
|
const fileContents = substituteEnvironmentVars(rawFileContents);
|
||||||
const widgets = yaml.load(fileContents);
|
const widgets = yaml.load(fileContents);
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
import { join } from "path";
|
|
||||||
import { format as utilFormat } from "node:util";
|
import { format as utilFormat } from "node:util";
|
||||||
|
|
||||||
import winston from "winston";
|
import winston from "winston";
|
||||||
|
|
||||||
import checkAndCopyConfig, { getSettings } from "utils/config/config";
|
import checkAndCopyConfig, { getSettings, CONF_DIR } from "utils/config/config";
|
||||||
|
|
||||||
|
|
||||||
let winstonLogger;
|
let winstonLogger;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
const configPath = join(process.cwd(), "config");
|
|
||||||
checkAndCopyConfig("settings.yaml");
|
checkAndCopyConfig("settings.yaml");
|
||||||
const settings = getSettings();
|
const settings = getSettings();
|
||||||
const logpath = settings.logpath || configPath;
|
const logpath = settings.logpath || CONF_DIR;
|
||||||
|
|
||||||
function combineMessageAndSplat() {
|
function combineMessageAndSplat() {
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Reference in a new issue