diff --git a/.gitignore b/.gitignore index be7293a0..ffdc9a0a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ cypress/videos/* dist/ node_modules/ npm-debug.log* +tests/settings/certs/ diff --git a/README.md b/README.md index a3595759..7d3fad75 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@ 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: -#### setup: +#### Setup: ```sh mkdir -p ~/pulp-backend-oci/{settings/certs,pulp_storage,pgsql,containers} @@ -21,7 +21,7 @@ ANSIBLE_CONTENT_HOSTNAME='http://$(hostname):8080/pulp/content' " >> settings/settings.py ``` -#### run: +#### Run: ```sh cd ~/pulp-backend-oci/ @@ -34,7 +34,7 @@ podman run --publish 8080:80 \ docker.io/pulp/pulp ``` -#### check: +#### Check: ```sh curl localhost:8080/pulp/api/v3/status/ | jq @@ -42,7 +42,7 @@ curl localhost:8080/pulp/api/v3/status/ | jq or open http://localhost:8080/pulp/api/v3/status/ -#### change password: +#### Change password: ```sh podman exec -it pulp pulpcore-manager reset-admin-password --password admin @@ -51,7 +51,7 @@ podman exec -it pulp pulpcore-manager reset-admin-password --password admin 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] @@ -61,7 +61,25 @@ pulp --help pulp user list ``` -### frontend +### 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: admin + +``` +./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 . @@ -72,12 +90,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..afd8b2db --- /dev/null +++ b/tests/run_container.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# This script was originally taken from the https://github.com/pulp/squeezer repository and adapted for pulp-ui + +set -eu + +BASEPATH="$(dirname "$(readlink -f "$0")")" +export BASEPATH + +if [ -z "${CONTAINER_RUNTIME:+x}" ] +then + if command -v podman > /dev/null 2>&1 + 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}" + +# Check if getenforce is available and set SELINUX accordingly +if command -v getenforce > /dev/null 2>&1 +then + if [ "$(getenforce)" = "Enforcing" ] + then + SELINUX="yes" + else + SELINUX="" + fi +else + SELINUX="" +fi + +"${CONTAINER_RUNTIME}" \ + run ${RM:+--rm} \ + --env S6_KEEP_ENV=1 \ + --detach \ + --name "pulp-ephemeral" \ + --volume "${BASEPATH}/settings:/etc/pulp${SELINUX:+:Z}" \ + --publish "8080:80" \ + --network "bridge" \ + "docker.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/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/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 admin + +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