Skip to content

Commit

Permalink
Update ui templating to handle new config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
gerrod3 committed Oct 21, 2024
1 parent d14d3a9 commit 64b9e94
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
6 changes: 3 additions & 3 deletions images/pulp/stable/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ARG PULP_RPM_VERSION=""
ARG PULP_OSTREE_VERSION=""
ARG PULP_UI_URL=""

ENV PULP_UI=true
ENV PULP_UI=${PULP_UI_URL:-false}
COPY images/assets/requirements.extra.txt /requirements.extra.txt

RUN pip3 install --upgrade \
Expand Down Expand Up @@ -44,7 +44,7 @@ RUN ln $(pip3 show pulp_python | sed -n -e 's/Location: //p')/pulp_python/app/we

RUN <<EOF
if [[ "$PULP_UI_URL" ]]; then
mkdir -p /usr/share/nginx/static/pulp_ui
curl -Ls $PULP_UI_URL | tar -xzv -C /usr/share/nginx/static/pulp_ui
mkdir -p "${PULP_STATIC_ROOT}pulp_ui"
curl -Ls $PULP_UI_URL | tar -xzv -C "${PULP_STATIC_ROOT}pulp_ui"
fi
EOF
9 changes: 6 additions & 3 deletions images/s6_assets/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,15 @@ http {

{% if ui | default(false) -%}
location /static/pulp_ui/ {
root /usr/share/nginx/;
root {{ pulp_ui_static|replace("static/pulp_ui/", "") }};
try_files $uri /static/pulp_ui/index.html;
}
location /ui/ {
alias /usr/share/nginx/static/pulp_ui/;
try_files $uri /static/pulp_ui/index.html
alias {{ pulp_ui_static }};
try_files $uri index.html;
}
location /pulp-ui-config.json {
root {{ pulp_ui_static }};
}
{%- endif %}

Expand Down
20 changes: 19 additions & 1 deletion images/s6_assets/template_nginx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import json
import os
import django
from django.core.exceptions import AppRegistryNotReady, ImproperlyConfigured
Expand All @@ -21,7 +22,7 @@
"api_root": "/pulp/",
"content_path": "/pulp/content/",
"domain_enabled": False,
"ui": ui != "false",
"ui": ui.lower() != "false",
}

try:
Expand All @@ -34,6 +35,23 @@
values["content_path"] = settings.CONTENT_PATH_PREFIX
values["domain_enabled"] = getattr(settings, "DOMAIN_ENABLED", False)

if values["ui"]:
static = os.getenv("PULP_STATIC_ROOT", "/var/lib/operator/static/")
values["pulp_ui_static"] = f"{static}pulp_ui/"
if os.path.exists(values["pulp_ui_static"]):
ui_config_path = f'{values["pulp_ui_static"]}pulp-ui-config.json'
if os.path.exists(ui_config_path):
with open(ui_config_path, "r") as f:
ui_config = json.load(f)
api_base_path = f"{values['api_root']}api/v3/"
if ui_config["API_BASE_PATH"] != api_base_path:
ui_config["API_BASE_PATH"] = api_base_path
with open(ui_config_path, "w") as f:
json.dump(ui_config, f)
else:
print(f"Failed to find the pulp-ui static files at {values['pulp_ui_static']}")
values["ui"] = False

template = Template(args.template_file.read())
output = template.render(**values)
args.output_file.write(output)

0 comments on commit 64b9e94

Please sign in to comment.