From 34b7cfdd5a07c8e3b745818d19fd5d600ff4766e Mon Sep 17 00:00:00 2001 From: Gino Lisignoli Date: Fri, 25 Jul 2025 19:23:00 +1200 Subject: [PATCH 1/5] Added run_container.sh script, formatted README --- .gitignore | 1 + README.md | 53 ++++++----------------- tests/run_container.sh | 97 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 40 deletions(-) create mode 100755 tests/run_container.sh diff --git a/.gitignore b/.gitignore index be7293a0..d0a30c8b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ cypress/videos/* dist/ node_modules/ npm-debug.log* +tests/settings diff --git a/README.md b/README.md index a3595759..bf081959 100644 --- a/README.md +++ b/README.md @@ -4,37 +4,19 @@ A community driven UI for [Pulp](https://pulpproject.org/). ## How to run -### backend +### Backend -You can follow the [pulp-oci-images quickstart](https://pulpproject.org/pulp-oci-images/docs/admin/tutorials/quickstart/), -TLDR: +The `tests/run_container.sh` script is provided and allows you to run a command with a [Pulp in one](https://pulpproject.org/pulp-in-one-container/) container active. +It requires Docker or Podman to be installed. +The default credentials are: +Username: admin +Password: password -#### setup: - -```sh -mkdir -p ~/pulp-backend-oci/{settings/certs,pulp_storage,pgsql,containers} -cd ~/pulp-backend-oci/ -echo " -CONTENT_ORIGIN='http://$(hostname):8080' -ANSIBLE_API_HOSTNAME='http://$(hostname):8080' -ANSIBLE_CONTENT_HOSTNAME='http://$(hostname):8080/pulp/content' -" >> settings/settings.py ``` - -#### run: - -```sh -cd ~/pulp-backend-oci/ -podman run --publish 8080:80 \ - --replace --name pulp \ - --volume "$(pwd)/settings":/etc/pulp \ - --volume "$(pwd)/pulp_storage":/var/lib/pulp \ - --volume "$(pwd)/pgsql":/var/lib/pgsql \ - --volume "$(pwd)/containers":/var/lib/containers \ - docker.io/pulp/pulp +./tests/run_container sleep inf ``` -#### check: +#### Check: ```sh curl localhost:8080/pulp/api/v3/status/ | jq @@ -42,26 +24,17 @@ curl localhost:8080/pulp/api/v3/status/ | jq or open http://localhost:8080/pulp/api/v3/status/ -#### change password: - -```sh -podman exec -it pulp pulpcore-manager reset-admin-password --password admin -``` -```sh -docker exec -it compose-pulp_api-1 pulpcore-manager reset-admin-password --password admin -``` - -#### configure `pulp-cli`: +#### Configure `pulp-cli`: ```sh pip install pulp-cli[pygments] -pulp config create --username admin --base-url http://localhost:8080 --password admin +pulp config create --username admin --base-url http://localhost:8080 --password password pulp --help pulp user list ``` -### frontend +### Frontend You can clone the frontend from https://github.com/pulp/pulp-ui . @@ -72,12 +45,12 @@ npm run start and open http://localhost:8002/ :tada: :) -If your API listens elsewhere, you can use `API_PROXY=http://elsewhere:12345 npm run start` instead. Do note that the server at `elsewhere` has to be configured to allow CORS requests for `localhost` (where UI actually listens); using something like `changeOrigin` is out of scope for pulp-ui, and breaks pulp API URLs (because the domains are based on the Origin header). Do NOT use webpack proxy in production. +If your PULP API listens elsewhere, you can use `API_PROXY=http://elsewhere:12345 npm run start` instead. Do note that the server at `elsewhere` has to be configured to allow CORS requests for `localhost` (where UI actually listens); using something like `changeOrigin` is out of scope for pulp-ui, and breaks pulp API URLs (because the domains are based on the Origin header). Do NOT use webpack proxy in production. ## Misc -### post-build configuration +### Post-build configuration The UI builds produced by `npm run build` can be further configured by serving a `/pulp-ui-config.json` alongside the built UI. (Note it has to be mapped at `/`, not just wherever `index.html` is served from.) diff --git a/tests/run_container.sh b/tests/run_container.sh new file mode 100755 index 00000000..3b766ab8 --- /dev/null +++ b/tests/run_container.sh @@ -0,0 +1,97 @@ +#!/bin/sh + +# This file is shared between some projects please keep all copies in sync +# Known places: +# - https://github.com/pulp/pulp-cli/blob/main/.ci/run_container.sh +# - https://github.com/pulp/pulp-cli-deb/blob/main/.ci/run_container.sh +# - https://github.com/pulp/pulp-cli-ostree/blob/main/.ci/run_container.sh +# - https://github.com/pulp/squeezer/blob/develop/tests/run_container.sh +# - https://github.com/pulp/pulp-ui/blob/main/tests/run_container.sh + +set -eu + +BASEPATH="$(dirname "$(readlink -f "$0")")" +export BASEPATH + +if [ -z "${CONTAINER_RUNTIME:+x}" ] +then + if ls /usr/bin/podman + then + CONTAINER_RUNTIME=podman + else + CONTAINER_RUNTIME=docker + fi +fi +export CONTAINER_RUNTIME + +if [ -z "${KEEP_CONTAINER:+x}" ] +then + RM="yes" +else + RM="" +fi + +IMAGE_TAG="${IMAGE_TAG:-latest}" +FROM_TAG="${FROM_TAG:-latest}" + +if [ "${CONTAINER_FILE:+x}" ] +then + IMAGE_TAG="ephemeral-build" + "${CONTAINER_RUNTIME}" build --file "${BASEPATH}/assets/${CONTAINER_FILE}" --build-arg FROM_TAG="${FROM_TAG}" --tag ghcr.io/pulp/pulp:"${IMAGE_TAG}" . +fi + +if [ "$(getenforce)" = "Enforcing" ]; then + SELINUX="yes" +else + SELINUX="" +fi; + +"${CONTAINER_RUNTIME}" \ + run ${RM:+--rm} \ + --env S6_KEEP_ENV=1 \ + ${PULP_API_ROOT:+--env PULP_API_ROOT} \ + --detach \ + --name "pulp-ephemeral" \ + --volume "${BASEPATH}/settings:/etc/pulp${SELINUX:+:Z}" \ + --publish "8080:80" \ + --network "bridge" \ + "ghcr.io/pulp/pulp:${IMAGE_TAG}" + +# shellcheck disable=SC2064 +trap "${CONTAINER_RUNTIME} stop pulp-ephemeral" EXIT +# shellcheck disable=SC2064 +trap "${CONTAINER_RUNTIME} stop pulp-ephemeral" INT + +echo "Wait for pulp to start." +for counter in $(seq 40 -1 0) +do + if [ "$counter" = "0" ] + then + echo "FAIL." + "${CONTAINER_RUNTIME}" images + "${CONTAINER_RUNTIME}" ps -a + "${CONTAINER_RUNTIME}" logs "pulp-ephemeral" + exit 1 + fi + + sleep 3 + if curl --fail "http://localhost:8080${PULP_API_ROOT:-/pulp/}api/v3/status/" > /dev/null 2>&1 + then + echo "SUCCESS." + break + fi + echo "." +done + +# show pulpcore/plugin versions we're using +curl -s "http://localhost:8080${PULP_API_ROOT:-/pulp/}api/v3/status/" | jq '.versions|map({key: .component, value: .version})|from_entries' + +# Set admin password +"${CONTAINER_RUNTIME}" exec "pulp-ephemeral" pulpcore-manager reset-admin-password --password password + +if [ -d "${BASEPATH}/container_setup.d/" ] +then + run-parts --regex '^[0-9]+-[-_[:alnum:]]*\.sh$' "${BASEPATH}/container_setup.d/" +fi + +PULP_LOGGING="${CONTAINER_RUNTIME}" "$@" From e67ee0603b455482338ea706c22498548e3275cf Mon Sep 17 00:00:00 2001 From: Gino Lisignoli Date: Sat, 26 Jul 2025 19:11:56 +1200 Subject: [PATCH 2/5] Rewrite run_containers script, add back documentation on how to start container, fix .gitignore --- .gitignore | 2 +- README.md | 48 +++++++++++++++++++++++++++++++++----- tests/run_container.sh | 42 ++++++++++++--------------------- tests/settings/settings.py | 5 ++++ 4 files changed, 63 insertions(+), 34 deletions(-) create mode 100644 tests/settings/settings.py diff --git a/.gitignore b/.gitignore index d0a30c8b..ffdc9a0a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ cypress/videos/* dist/ node_modules/ npm-debug.log* -tests/settings +tests/settings/certs/ diff --git a/README.md b/README.md index bf081959..33c0f709 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,32 @@ A community driven UI for [Pulp](https://pulpproject.org/). ### Backend -The `tests/run_container.sh` script is provided and allows you to run a command with a [Pulp in one](https://pulpproject.org/pulp-in-one-container/) container active. -It requires Docker or Podman to be installed. -The default credentials are: -Username: admin -Password: password +You can follow the [pulp-oci-images quickstart](https://pulpproject.org/pulp-oci-images/docs/admin/tutorials/quickstart/), +TLDR: + +#### Setup: +```sh +mkdir -p ~/pulp-backend-oci/{settings/certs,pulp_storage,pgsql,containers} +cd ~/pulp-backend-oci/ +echo " +CONTENT_ORIGIN='http://$(hostname):8080' +ANSIBLE_API_HOSTNAME='http://$(hostname):8080' +ANSIBLE_CONTENT_HOSTNAME='http://$(hostname):8080/pulp/content' +" >> settings/settings.py ``` -./tests/run_container sleep inf + +#### Run: + +```sh +cd ~/pulp-backend-oci/ +podman run --publish 8080:80 \ + --replace --name pulp \ + --volume "$(pwd)/settings":/etc/pulp \ + --volume "$(pwd)/pulp_storage":/var/lib/pulp \ + --volume "$(pwd)/pgsql":/var/lib/pgsql \ + --volume "$(pwd)/containers":/var/lib/containers \ + docker.io/pulp/pulp ``` #### Check: @@ -34,6 +52,24 @@ pulp --help pulp user list ``` +### Setup (run_container.sh script) + +The `tests/run_container.sh` script is provided and allows you to run a command with a [Pulp OCI-image](https://pulpproject.org/pulp-oci-images/docs/admin/tutorials/quickstart/) container running. + +It requires Docker or Podman to be installed. + +The default credentials are: + * Username: admin + * Password: password + +``` +./tests/run_container sleep inf +``` + +The following optional environment variable is availble to be set: + +* `IMAGE_TAG`: Change the Pulp OCI image tage to use, defaults to `latest` + ### Frontend You can clone the frontend from https://github.com/pulp/pulp-ui . diff --git a/tests/run_container.sh b/tests/run_container.sh index 3b766ab8..0b6bb267 100755 --- a/tests/run_container.sh +++ b/tests/run_container.sh @@ -1,12 +1,6 @@ -#!/bin/sh +#!/bin/bash -# This file is shared between some projects please keep all copies in sync -# Known places: -# - https://github.com/pulp/pulp-cli/blob/main/.ci/run_container.sh -# - https://github.com/pulp/pulp-cli-deb/blob/main/.ci/run_container.sh -# - https://github.com/pulp/pulp-cli-ostree/blob/main/.ci/run_container.sh -# - https://github.com/pulp/squeezer/blob/develop/tests/run_container.sh -# - https://github.com/pulp/pulp-ui/blob/main/tests/run_container.sh +# This script was originally taken from the https://github.com/pulp/squeezer repository and adapted for pulp-ui set -eu @@ -15,7 +9,7 @@ export BASEPATH if [ -z "${CONTAINER_RUNTIME:+x}" ] then - if ls /usr/bin/podman + if command -v podman > /dev/null 2>&1 then CONTAINER_RUNTIME=podman else @@ -32,24 +26,23 @@ else fi IMAGE_TAG="${IMAGE_TAG:-latest}" -FROM_TAG="${FROM_TAG:-latest}" -if [ "${CONTAINER_FILE:+x}" ] +# Check if getenforce is available and set SELINUX accordingly +if command -v getenforce > /dev/null 2>&1 then - IMAGE_TAG="ephemeral-build" - "${CONTAINER_RUNTIME}" build --file "${BASEPATH}/assets/${CONTAINER_FILE}" --build-arg FROM_TAG="${FROM_TAG}" --tag ghcr.io/pulp/pulp:"${IMAGE_TAG}" . -fi - -if [ "$(getenforce)" = "Enforcing" ]; then + if [ "$(getenforce)" = "Enforcing" ] + then SELINUX="yes" -else + else SELINUX="" -fi; + fi +else + SELINUX="" +fi "${CONTAINER_RUNTIME}" \ run ${RM:+--rm} \ --env S6_KEEP_ENV=1 \ - ${PULP_API_ROOT:+--env PULP_API_ROOT} \ --detach \ --name "pulp-ephemeral" \ --volume "${BASEPATH}/settings:/etc/pulp${SELINUX:+:Z}" \ @@ -75,7 +68,7 @@ do fi sleep 3 - if curl --fail "http://localhost:8080${PULP_API_ROOT:-/pulp/}api/v3/status/" > /dev/null 2>&1 + if curl --fail "http://localhost:8080/pulp/api/v3/status/" > /dev/null 2>&1 then echo "SUCCESS." break @@ -83,15 +76,10 @@ do echo "." done -# show pulpcore/plugin versions we're using -curl -s "http://localhost:8080${PULP_API_ROOT:-/pulp/}api/v3/status/" | jq '.versions|map({key: .component, value: .version})|from_entries' +# Show pulpcore/plugin versions we're using +curl -s "http://localhost:8080/pulp/api/v3/status/" | jq '.versions|map({key: .component, value: .version})|from_entries' # Set admin password "${CONTAINER_RUNTIME}" exec "pulp-ephemeral" pulpcore-manager reset-admin-password --password password -if [ -d "${BASEPATH}/container_setup.d/" ] -then - run-parts --regex '^[0-9]+-[-_[:alnum:]]*\.sh$' "${BASEPATH}/container_setup.d/" -fi - PULP_LOGGING="${CONTAINER_RUNTIME}" "$@" diff --git a/tests/settings/settings.py b/tests/settings/settings.py new file mode 100644 index 00000000..bb490ef3 --- /dev/null +++ b/tests/settings/settings.py @@ -0,0 +1,5 @@ +CONTENT_ORIGIN = "http://localhost:8080/" +ALLOWED_EXPORT_PATHS = ["/tmp"] +CACHE_ENABLED = True +REDIS_HOST = "localhost" +REDIS_PORT = 6379 From 2293cf131d2b06466e25ab1f1d944a4756f0db97 Mon Sep 17 00:00:00 2001 From: Gino Lisignoli Date: Sat, 26 Jul 2025 19:18:44 +1200 Subject: [PATCH 3/5] Add back instuctions to change password --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 33c0f709..26038d3a 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,15 @@ curl localhost:8080/pulp/api/v3/status/ | jq or open http://localhost:8080/pulp/api/v3/status/ +#### Change password: + +```sh +podman exec -it pulp pulpcore-manager reset-admin-password --password admin +``` +```sh +docker exec -it compose-pulp_api-1 pulpcore-manager reset-admin-password --password admin +``` + #### Configure `pulp-cli`: ```sh From 7157aae48c3d1a5cecde708201c0688a9a7be44b Mon Sep 17 00:00:00 2001 From: Gino Lisignoli Date: Sat, 26 Jul 2025 19:27:30 +1200 Subject: [PATCH 4/5] Change ghcr.io to docker.io --- tests/run_container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run_container.sh b/tests/run_container.sh index 0b6bb267..c76be739 100755 --- a/tests/run_container.sh +++ b/tests/run_container.sh @@ -48,7 +48,7 @@ fi --volume "${BASEPATH}/settings:/etc/pulp${SELINUX:+:Z}" \ --publish "8080:80" \ --network "bridge" \ - "ghcr.io/pulp/pulp:${IMAGE_TAG}" + "docker.io/pulp/pulp:${IMAGE_TAG}" # shellcheck disable=SC2064 trap "${CONTAINER_RUNTIME} stop pulp-ephemeral" EXIT From 8db5407288dc65b3c46e77c080ed9b447c33e917 Mon Sep 17 00:00:00 2001 From: Gino Lisignoli Date: Mon, 4 Aug 2025 18:26:03 +1200 Subject: [PATCH 5/5] Change password to match cypress --- README.md | 4 ++-- tests/run_container.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 26038d3a..7d3fad75 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ docker exec -it compose-pulp_api-1 pulpcore-manager reset-admin-password --passw ```sh pip install pulp-cli[pygments] -pulp config create --username admin --base-url http://localhost:8080 --password password +pulp config create --username admin --base-url http://localhost:8080 --password admin pulp --help pulp user list @@ -69,7 +69,7 @@ It requires Docker or Podman to be installed. The default credentials are: * Username: admin - * Password: password + * Password: admin ``` ./tests/run_container sleep inf diff --git a/tests/run_container.sh b/tests/run_container.sh index c76be739..afd8b2db 100755 --- a/tests/run_container.sh +++ b/tests/run_container.sh @@ -80,6 +80,6 @@ done curl -s "http://localhost:8080/pulp/api/v3/status/" | jq '.versions|map({key: .component, value: .version})|from_entries' # Set admin password -"${CONTAINER_RUNTIME}" exec "pulp-ephemeral" pulpcore-manager reset-admin-password --password password +"${CONTAINER_RUNTIME}" exec "pulp-ephemeral" pulpcore-manager reset-admin-password --password admin PULP_LOGGING="${CONTAINER_RUNTIME}" "$@"