Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable UI config overrides post build #1830

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions frontend/amundsen_application/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,22 @@

def init_routes(app: Flask) -> None:
frontend_base = app.config.get('FRONTEND_BASE')
config_override_enabled = app.config.get('JS_CONFIG_OVERRIDE_ENABLED')

app.add_url_rule('/healthcheck', 'healthcheck', healthcheck)
app.add_url_rule('/opensearch.xml', 'opensearch.xml', opensearch, defaults={'frontend_base': frontend_base})
app.add_url_rule('/', 'index', index, defaults={'path': '',
'config_override_enabled': config_override_enabled,
'frontend_base': frontend_base}) # also functions as catch_all
app.add_url_rule('/<path:path>', 'index', index, defaults={'frontend_base': frontend_base}) # catch_all
app.add_url_rule('/<path:path>', 'index', index,
defaults={'frontend_base': frontend_base,
'config_override_enabled': config_override_enabled}) # catch_all


def index(path: str, frontend_base: str) -> Any:
def index(path: str, frontend_base: str, config_override_enabled: bool) -> Any:
try:
return render_template("index.html", env=ENVIRONMENT, frontend_base=frontend_base) # pragma: no cover
return render_template("index.html", env=ENVIRONMENT, frontend_base=frontend_base,
config_override_enabled=config_override_enabled) # pragma: no cover
except jinja2.exceptions.TemplateNotFound as e:
LOGGER.error("index.html template not found, have you built the front-end JS (npm run build in static/?")
raise e
Expand Down
6 changes: 6 additions & 0 deletions frontend/amundsen_application/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

import os
import distutils.util
from typing import Callable, Dict, List, Optional, Set # noqa: F401
from amundsen_application.models.user import User

Expand Down Expand Up @@ -57,6 +58,9 @@ class Config:
# Frontend Application
FRONTEND_BASE = ''

# JS config override for frontend app
JS_CONFIG_OVERRIDE_ENABLED = False

# Search Service
SEARCHSERVICE_REQUEST_CLIENT = None
SEARCHSERVICE_REQUEST_HEADERS = None
Expand Down Expand Up @@ -156,6 +160,8 @@ class LocalConfig(Config):
# If installing using the Docker bootstrap, this should be modified to the docker host ip.
LOCAL_HOST = '0.0.0.0'

JS_CONFIG_OVERRIDE_ENABLED = distutils.util.strtobool(os.environ.get('JS_CONFIG_OVERRIDE_ENABLED', 'False'))

FRONTEND_BASE = os.environ.get('FRONTEND_BASE',
'http://{LOCAL_HOST}:{PORT}'.format(
LOCAL_HOST=LOCAL_HOST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ export interface AppConfig {
productTour: ToursConfig;
}

/**
* configExternal - If you choose to override one of the configs, you must provide the full type definition
* for configExternal
*/

export interface AppConfigExternal {
configExternal: AppConfig;
}

export interface AppConfigCustom {
analytics?: AnalyticsConfig;
badges?: BadgeConfig;
Expand Down
13 changes: 10 additions & 3 deletions frontend/amundsen_application/static/js/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { AppConfig } from './config-types';
import { AppConfig, AppConfigExternal } from './config-types';
import configDefault from './config-default';
import configCustom from './config-custom';

// This is not a shallow merge. Any defined members of customConfig will override configDefault.
const appConfig: AppConfig = { ...configDefault, ...configCustom };
// This is not a shallow merge. In two steps we are overriding the application config
// Step 1: Any defined members of customConfig will override configDefault.
// Step 2: Any defined members of configExternal will override the configDefault and configCustom.

const appConfig: AppConfig = {
...configDefault,
...configCustom,
...(((globalThis as unknown) as AppConfigExternal)?.configExternal || {}),
};

export default appConfig;
3 changes: 3 additions & 0 deletions frontend/amundsen_application/static/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<title>Amundsen - Data Discovery Portal</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% if config_override_enabled %}
<script defer="defer" src="/static/config-external.js"></script>
{% endif %}
{% if env == "development" %}
{% include 'fragments/icons-dev.html' %}
{% elif env == "staging" %}
Expand Down