Skip to content

Commit

Permalink
Merge pull request #677 from gerrod3/pulp-ui
Browse files Browse the repository at this point in the history
Add pulp-ui to pulp image
  • Loading branch information
mdellweg authored Nov 5, 2024
2 parents 97a31eb + 2ad7a98 commit d74b7bb
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 1 deletion.
23 changes: 22 additions & 1 deletion .github/actions/build_image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ inputs:
image_cache_key:
description: 'The key value used to store the base images in the cache'
required: true
latest_ui:
description: 'Use the latest pulp-ui when building the image'
default: 'false'
required: false
outputs:
app_version:
value: ${{ steps.image_version_branch.outputs.app_version }}
Expand All @@ -30,6 +34,10 @@ runs:
with:
python-version: 3.11

- name: Install python deps
run: pip install httpie jq
shell: bash

- name: Restore podman images from cache
uses: actions/cache/restore@v3
with:
Expand All @@ -41,6 +49,19 @@ runs:
podman load -i base-images.tar.gz
shell: bash

- name: Find latest ui version
if: inputs.latest_ui != 'false'
run: |
echo "Requesting the latest pulp-ui release"
URL=$(http --verify=no GET https://api.github.com/repos/pulp/pulp-ui/releases/latest | jq -r '.assets[0].browser_download_url')
if [[ -n "${URL}" && ("${URL}" != "null") ]]; then
echo "Found UI url ${URL}"
echo "BUILD_UI_ARG=--build-arg PULP_UI_URL=${URL}" >> $GITHUB_ENV
else
echo "Failed to find the latest pulp-ui release"
fi
shell: bash

- name: Build images
run: |
podman version
Expand All @@ -53,7 +74,7 @@ runs:
podman build --platform linux/${ARCH} --format docker --pull=false --file images/${{ inputs.image_name }}/${{ inputs.image_variant }}/Containerfile.core --tag pulp/${{ inputs.image_name }}:ci-${ARCH} --build-arg FROM_TAG=ci-${ARCH} .
podman build --platform linux/${ARCH} --format docker --pull=false --file images/${{ inputs.image_name }}/${{ inputs.image_variant }}/Containerfile.webserver --tag pulp/${base_image}-web:ci-${ARCH} --build-arg FROM_TAG=ci-${ARCH} .
else
podman build --platform linux/${ARCH} --format docker --pull=false --file images/${{ inputs.image_name }}/${{ inputs.image_variant }}/Containerfile --tag pulp/${{ inputs.image_name }}:ci-${ARCH} --build-arg FROM_TAG=ci-${ARCH} .
podman build --platform linux/${ARCH} --format docker --pull=false --file images/${{ inputs.image_name }}/${{ inputs.image_variant }}/Containerfile --tag pulp/${{ inputs.image_name }}:ci-${ARCH} --build-arg FROM_TAG=ci-${ARCH} ${{ env.BUILD_UI_ARG }} .
fi
done
podman images -a
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
image_name: ${{ matrix.image_name }}
image_variant: "stable"
image_cache_key: ${{ needs.base-images.outputs.base_cache_key }}
latest_ui: ${{ github.base_ref == 'latest' }}

- name: Test App Image
uses: "./.github/actions/test_image"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ jobs:
image_name: ${{ matrix.image_name }}
image_variant: ${{ matrix.image_variant }}
image_cache_key: ${{ needs.base-images.outputs.base_cache_key }}
latest_ui: ${{ github.ref_name == 'latest' }}

- name: Test App Image
if: matrix.image_variant != 'nightly'
Expand Down
1 change: 1 addition & 0 deletions CHANGES/664.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The pulp/pulp images are now built with the new pulp-ui available at `/ui/`.
9 changes: 9 additions & 0 deletions images/pulp/stable/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ ARG PULP_MAVEN_VERSION=""
ARG PULP_PYTHON_VERSION=""
ARG PULP_RPM_VERSION=""
ARG PULP_OSTREE_VERSION=""
ARG PULP_UI_URL=""

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

RUN pip3 install --upgrade \
Expand All @@ -39,3 +41,10 @@ USER root:root
RUN ln $(pip3 show pulp_ansible | sed -n -e 's/Location: //p')/pulp_ansible/app/webserver_snippets/nginx.conf /etc/nginx/pulp/pulp_ansible.conf
RUN ln $(pip3 show pulp_container | sed -n -e 's/Location: //p')/pulp_container/app/webserver_snippets/nginx.conf /etc/nginx/pulp/pulp_container.conf
RUN ln $(pip3 show pulp_python | sed -n -e 's/Location: //p')/pulp_python/app/webserver_snippets/nginx.conf /etc/nginx/pulp/pulp_python.conf

RUN \
if [ -n "$PULP_UI_URL" ]; then \
mkdir -p "${PULP_STATIC_ROOT}pulp_ui"; \
curl -Ls $PULP_UI_URL | tar -xzv -C "${PULP_STATIC_ROOT}pulp_ui"; \
fi

14 changes: 14 additions & 0 deletions images/s6_assets/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ http {

include pulp/*.conf;

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

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Expand Down
20 changes: 20 additions & 0 deletions 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 @@ -15,11 +16,13 @@
args = parser.parse_args()

https = os.getenv("PULP_HTTPS", "false")
ui = os.getenv("PULP_UI", "false")
values = {
"https": https.lower() == "true",
"api_root": "/pulp/",
"content_path": "/pulp/content/",
"domain_enabled": False,
"ui": ui.lower() != "false",
}

try:
Expand All @@ -32,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 d74b7bb

Please sign in to comment.