Merge pull request #8406 from prkeshri/7340-remote-config-fix

7340 remote config fix
This commit is contained in:
Fredrik Adelöw
2021-12-17 10:34:32 +01:00
committed by GitHub
7 changed files with 48 additions and 4 deletions
+22
View File
@@ -0,0 +1,22 @@
---
'@backstage/backend-common': patch
---
Fixed bug in backend-common to allow passing of remote option in order to enable passing remote url in --config option. The remote option should be passed along with reloadIntervalSeconds from packages/backend/src/index.ts (Updated the file as well)
These changes are needed in `packages/backend/src/index.ts` if remote URLs are desired to be passed in --config option and read and watch remote files for config.
```diff
@@ -86,7 +86,11 @@ async function main() {
const config = await loadBackendConfig({
argv: process.argv,
logger,
+ remote: {
+ reloadIntervalSeconds: 60 * 10 // Check remote config changes every 10 minutes. Change to your desired interval in seconds
+ }
});
+
const createEnv = makeCreateEnv(config);
const healthcheckEnv = useHotMemoize(module, () => createEnv('healthcheck'));
```
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/config-loader': patch
---
In case remote.reloadIntervalSeconds is passed, it must be a valid positive value
+4 -1
View File
@@ -67,7 +67,7 @@ production build.
## Configuration Files
It is possible to have multiple configuration files (bundled and/or remote),
It is possible to have multiple configuration files (bundled and/or remote\*),
both to support different environments, but also to define configuration that is
local to specific packages. The configuration files to load are selected using a
`--config <local-path|url>` flag, and it is possible to load any number of
@@ -77,6 +77,9 @@ root when running the backend, you would use `--config ../../my-config.yaml`,
and for config file on a config server you would use
`--config https://some.domain.io/app-config.yaml`
**Note**: In case URLs are passed, it is also needed to set the remote option in
the loadBackendConfig call.
If no `config` flags are specified, the default behavior is to load
`app-config.yaml` and, if it exists, `app-config.local.yaml` from the repo root.
In the provided project setup, `app-config.local.yaml` is `.gitignore`'d, making
+2
View File
@@ -21,6 +21,7 @@ import { GitLabIntegration } from '@backstage/integration';
import { isChildPath } from '@backstage/cli-common';
import { JsonValue } from '@backstage/types';
import { Knex } from 'knex';
import { LoadConfigOptionsRemote } from '@backstage/config-loader';
import { Logger as Logger_2 } from 'winston';
import { MergeResult } from 'isomorphic-git';
import { PushResult } from 'isomorphic-git';
@@ -338,6 +339,7 @@ export function isDatabaseConflictError(e: unknown): boolean;
// @public
export function loadBackendConfig(options: {
logger: Logger_2;
remote?: LoadConfigOptionsRemote;
argv: string[];
}): Promise<Config>;
+3
View File
@@ -23,6 +23,7 @@ import {
loadConfig,
ConfigSchema,
ConfigTarget,
LoadConfigOptionsRemote,
} from '@backstage/config-loader';
import { AppConfig, Config, ConfigReader } from '@backstage/config';
import { JsonValue } from '@backstage/types';
@@ -178,6 +179,7 @@ let currentCancelFunc: () => void;
export async function loadBackendConfig(options: {
logger: Logger;
// process.argv or any other overrides
remote?: LoadConfigOptionsRemote;
argv: string[];
}): Promise<Config> {
const args = parseArgs(options.argv);
@@ -203,6 +205,7 @@ export async function loadBackendConfig(options: {
const { appConfigs } = await loadConfig({
configRoot: paths.targetRoot,
configTargets: configTargets,
remote: options.remote,
watch: {
onChange(newConfigs) {
options.logger.info(
+1
View File
@@ -89,6 +89,7 @@ async function main() {
argv: process.argv,
logger,
});
const createEnv = makeCreateEnv(config);
const healthcheckEnv = useHotMemoize(module, () => createEnv('healthcheck'));
+11 -3
View File
@@ -45,7 +45,7 @@ export type LoadConfigOptionsWatch = {
export type LoadConfigOptionsRemote = {
/**
* An optional remote config reloading period, in seconds
* A remote config reloading period, in seconds
*/
reloadIntervalSeconds: number;
};
@@ -114,8 +114,16 @@ export async function loadConfig(
.filter((e): e is { url: string } => e.hasOwnProperty('url'))
.map(configTarget => configTarget.url);
if (remote === undefined && configUrls.length > 0) {
throw new Error(`Remote config detected but this feature is turned off`);
if (remote === undefined) {
if (configUrls.length > 0) {
throw new Error(
`Please make sure you are passing the remote option when loading remote configurations. See https://backstage.io/docs/conf/writing#configuration-files for detailed info.`,
);
}
} else if (remote.reloadIntervalSeconds <= 0) {
throw new Error(
`Remote config must be contain a non zero reloadIntervalSeconds: <seconds> value`,
);
}
// If no paths are provided, we default to reading