diff --git a/.github/actions/build_image/action.yml b/.github/actions/build_image/action.yml index 366bf53e..8e351fb9 100644 --- a/.github/actions/build_image/action.yml +++ b/.github/actions/build_image/action.yml @@ -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 }} @@ -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: @@ -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 @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fcab260..29c2a321 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 306be930..b9e91031 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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' diff --git a/CHANGES/664.feature b/CHANGES/664.feature new file mode 100644 index 00000000..4ae0d9b9 --- /dev/null +++ b/CHANGES/664.feature @@ -0,0 +1 @@ +The pulp/pulp images are now built with the new pulp-ui available at `/ui/`. diff --git a/images/pulp/stable/Containerfile b/images/pulp/stable/Containerfile index 322a75d3..69cad47a 100644 --- a/images/pulp/stable/Containerfile +++ b/images/pulp/stable/Containerfile @@ -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 \ @@ -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 + diff --git a/images/s6_assets/nginx.conf.j2 b/images/s6_assets/nginx.conf.j2 index 4d77c4ca..d30764f4 100644 --- a/images/s6_assets/nginx.conf.j2 +++ b/images/s6_assets/nginx.conf.j2 @@ -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; diff --git a/images/s6_assets/template_nginx.py b/images/s6_assets/template_nginx.py index 37abd745..ce9d50bf 100755 --- a/images/s6_assets/template_nginx.py +++ b/images/s6_assets/template_nginx.py @@ -1,4 +1,5 @@ import argparse +import json import os import django from django.core.exceptions import AppRegistryNotReady, ImproperlyConfigured @@ -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: @@ -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)