Merge pull request #2976 from spotify/rugvip/logconf

backend-common: make loadBackendConfig return config directly and log all resolved app-configs
This commit is contained in:
Patrik Oldsberg
2020-10-21 13:00:52 +02:00
committed by GitHub
17 changed files with 70 additions and 29 deletions
+13 -2
View File
@@ -15,12 +15,18 @@
*/
import { findPaths } from '@backstage/cli-common';
import { Config, ConfigReader } from '@backstage/config';
import { loadConfig } from '@backstage/config-loader';
import { Logger } from 'winston';
type Options = {
logger: Logger;
};
/**
* Load configuration for a Backend
*/
export async function loadBackendConfig() {
export async function loadBackendConfig(options: Options): Promise<Config> {
/* eslint-disable-next-line no-restricted-syntax */
const paths = findPaths(__dirname);
const configs = await loadConfig({
@@ -28,5 +34,10 @@ export async function loadBackendConfig() {
rootPaths: [paths.targetRoot, paths.targetDir],
shouldReadSecrets: true,
});
return configs;
options.logger.info(
`Loaded config from ${configs.map(c => c.context).join(', ')}`,
);
return ConfigReader.fromConfigs(configs);
}
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ConfigReader } from '@backstage/config';
import { Config } from '@backstage/config';
import compression from 'compression';
import cors from 'cors';
import express, { Router } from 'express';
@@ -77,7 +77,7 @@ export class ServiceBuilderImpl implements ServiceBuilder {
this.module = moduleRef;
}
loadConfig(config: ConfigReader): ServiceBuilder {
loadConfig(config: Config): ServiceBuilder {
const backendConfig = config.getOptionalConfig('backend');
if (!backendConfig) {
return this;
+5 -6
View File
@@ -33,7 +33,7 @@ import {
SingleHostDiscovery,
UrlReaders,
} from '@backstage/backend-common';
import { ConfigReader } from '@backstage/config';
import { Config } from '@backstage/config';
import healthcheck from './plugins/healthcheck';
import auth from './plugins/auth';
import catalog from './plugins/catalog';
@@ -47,7 +47,7 @@ import graphql from './plugins/graphql';
import app from './plugins/app';
import { PluginEnvironment } from './types';
function makeCreateEnv(config: ConfigReader) {
function makeCreateEnv(config: Config) {
const root = getRootLogger();
const reader = UrlReaders.default({ logger: root, config });
const discovery = SingleHostDiscovery.fromConfig(config);
@@ -64,9 +64,8 @@ function makeCreateEnv(config: ConfigReader) {
}
async function main() {
const configs = await loadBackendConfig();
const configReader = ConfigReader.fromConfigs(configs);
const createEnv = makeCreateEnv(configReader);
const config = await loadBackendConfig({ logger: getRootLogger() });
const createEnv = makeCreateEnv(config);
const healthcheckEnv = useHotMemoize(module, () => createEnv('healthcheck'));
const catalogEnv = useHotMemoize(module, () => createEnv('catalog'));
@@ -93,7 +92,7 @@ async function main() {
apiRouter.use(notFoundHandler());
const service = createServiceBuilder(module)
.loadConfig(configReader)
.loadConfig(config)
.addRouter('', await healthcheck(healthcheckEnv))
.addRouter('/api', apiRouter)
.addRouter('', await app(appEnv));
+5
View File
@@ -26,6 +26,11 @@ export default async (cmd: Command) => {
env: process.env.APP_ENV ?? process.env.NODE_ENV ?? 'production',
rootPaths: [paths.targetRoot, paths.targetDir],
});
console.log(
`Loaded config from ${appConfigs.map(c => c.context).join(', ')}`,
);
await buildBundle({
entry: 'src/index',
parallel: parseParallel(process.env[PARALLEL_ENV_VAR]),
+5
View File
@@ -25,6 +25,11 @@ export default async (cmd: Command) => {
env: process.env.APP_ENV ?? process.env.NODE_ENV ?? 'development',
rootPaths: [paths.targetRoot, paths.targetDir],
});
console.log(
`Loaded config from ${appConfigs.map(c => c.context).join(', ')}`,
);
const waitForExit = await serveBundle({
entry: 'src/index',
checksEnabled: cmd.check,
+4
View File
@@ -26,6 +26,10 @@ export default async (cmd: Command) => {
rootPaths: [paths.targetRoot, paths.targetDir],
});
console.log(
`Loaded config from ${appConfigs.map(c => c.context).join(', ')}`,
);
const waitForExit = await serveBackend({
entry: 'src/index',
checksEnabled: cmd.check,
@@ -28,6 +28,10 @@ export default async (cmd: Command) => {
rootPaths: [paths.targetRoot, paths.targetDir],
});
console.log(
`Loaded config from ${appConfigs.map(c => c.context).join(', ')}`,
);
const flatConfig = ConfigReader.fromConfigs(appConfigs).get();
if (cmd.format === 'json') {
@@ -25,6 +25,11 @@ export default async (cmd: Command) => {
env: process.env.APP_ENV ?? process.env.NODE_ENV ?? 'production',
rootPaths: [paths.targetRoot, paths.targetDir],
});
console.log(
`Loaded config from ${appConfigs.map(c => c.context).join(', ')}`,
);
await buildBundle({
entry: 'dev/index',
statsJsonEnabled: cmd.stats,
@@ -25,6 +25,11 @@ export default async (cmd: Command) => {
env: process.env.APP_ENV ?? process.env.NODE_ENV ?? 'development',
rootPaths: [paths.targetRoot, paths.targetDir],
});
console.log(
`Loaded config from ${appConfigs.map(c => c.context).join(', ')}`,
);
const waitForExit = await serveBundle({
entry: 'dev/index',
checksEnabled: cmd.check,
@@ -17,7 +17,7 @@ import {
SingleHostDiscovery,
UrlReaders,
} from '@backstage/backend-common';
import { ConfigReader } from '@backstage/config';
import { Config } from '@backstage/config';
import auth from './plugins/auth';
import catalog from './plugins/catalog';
import scaffolder from './plugins/scaffolder';
@@ -25,7 +25,7 @@ import proxy from './plugins/proxy';
import techdocs from './plugins/techdocs';
import { PluginEnvironment } from './types';
function makeCreateEnv(config: ConfigReader) {
function makeCreateEnv(config: Config) {
const root = getRootLogger();
const reader = UrlReaders.default({ logger: root, config });
const discovery = SingleHostDiscovery.fromConfig(config);
@@ -42,9 +42,8 @@ function makeCreateEnv(config: ConfigReader) {
}
async function main() {
const configs = await loadBackendConfig();
const configReader = ConfigReader.fromConfigs(configs);
const createEnv = makeCreateEnv(configReader);
const config = await loadBackendConfig({logger: getRootLogger()});
const createEnv = makeCreateEnv(config);
const catalogEnv = useHotMemoize(module, () => createEnv('catalog'));
const scaffolderEnv = useHotMemoize(module, () => createEnv('scaffolder'));
@@ -61,7 +60,7 @@ async function main() {
apiRouter.use(notFoundHandler());
const service = createServiceBuilder(module)
.loadConfig(configReader)
.loadConfig(config)
.addRouter('/api', apiRouter)
await service.start().catch(err => {