diff --git a/CHANGES/544.feature b/CHANGES/544.feature new file mode 100644 index 00000000..9ad1e410 --- /dev/null +++ b/CHANGES/544.feature @@ -0,0 +1 @@ +Adds an option to skip migration and setting the admin password. diff --git a/images/assets/pulp-api b/images/assets/pulp-api index 9d165496..8db3cbd9 100755 --- a/images/assets/pulp-api +++ b/images/assets/pulp-api @@ -4,32 +4,37 @@ mkdir -p /var/lib/pulp/media \ /var/lib/pulp/assets \ /var/lib/pulp/tmp -/usr/bin/wait_on_postgres.py - -# Get list of installed plugins via pip -# Assumes they are all named like "pulp-file" -> "file", with no 2nd dash. -# (Was previously needed when we ran `pulpcore-manager makemigrations`) -# PLUGINS=$(pip list | awk -F '[[:space:]]+|[-]' '/pulp-/{printf $2 " " }') - -/usr/local/bin/pulpcore-manager migrate --noinput - -set +x +if [[ "${SKIP_MIGRATIONS}" = false ]]; then + echo "Running migrations..." + /usr/bin/wait_on_postgres.py + + # Get list of installed plugins via pip + # Assumes they are all named like "pulp-file" -> "file", with no 2nd dash. + # (Was previously needed when we ran `pulpcore-manager makemigrations`) + # PLUGINS=$(pip list | awk -F '[[:space:]]+|[-]' '/pulp-/{printf $2 " " }') + + /usr/local/bin/pulpcore-manager migrate --noinput +fi if [ -n "${PULP_SIGNING_KEY_FINGERPRINT}" ]; then + echo "Configuring the signing service..." /usr/local/bin/pulpcore-manager add-signing-service "${COLLECTION_SIGNING_SERVICE}" /var/lib/pulp/scripts/collection_sign.sh "${PULP_SIGNING_KEY_FINGERPRINT}" /usr/local/bin/pulpcore-manager add-signing-service "${CONTAINER_SIGNING_SERVICE}" /var/lib/pulp/scripts/container_sign.sh "${PULP_SIGNING_KEY_FINGERPRINT}" --class container:ManifestSigningService fi -ADMIN_PASSWORD_FILE=/etc/pulp/pulp-admin-password -if [[ -f "$ADMIN_PASSWORD_FILE" ]]; then - echo "pulp admin can be initialized." - PULP_ADMIN_PASSWORD=$(cat $ADMIN_PASSWORD_FILE) -fi +if [[ "${NO_ADMIN_PASSWORD}" = false ]]; then + echo "Setting the admin password..." + ADMIN_PASSWORD_FILE=/etc/pulp/pulp-admin-password + if [[ -f "$ADMIN_PASSWORD_FILE" ]]; then + echo "pulp admin can be initialized." + PULP_ADMIN_PASSWORD=$(cat $ADMIN_PASSWORD_FILE) + fi + + if [ -n "${PULP_ADMIN_PASSWORD}" ]; then + /usr/local/bin/pulpcore-manager reset-admin-password --password "${PULP_ADMIN_PASSWORD}" + fi -if [ -n "${PULP_ADMIN_PASSWORD}" ]; then - /usr/local/bin/pulpcore-manager reset-admin-password --password "${PULP_ADMIN_PASSWORD}" fi -set -x if which pulpcore-api then diff --git a/images/assets/pulp-common-entrypoint.sh b/images/assets/pulp-common-entrypoint.sh index 7acedda3..e5f6f095 100755 --- a/images/assets/pulp-common-entrypoint.sh +++ b/images/assets/pulp-common-entrypoint.sh @@ -5,10 +5,64 @@ # # We still want conatiner users to call pulp-* command names, not paths, so we # can change our scripts' locations in the future, and call special logic in this -# script based solely on theo command name. +# script based solely on the command name. -if [[ "$@" = "pulp-content" || "$@" = "pulp-api" || "$@" = "pulp-worker" || "$@" = "pulp-resource-manager" ]]; then - exec "/usr/bin/$@" +# Default value for the migration flag +skip_migrations=false +no_admin_password=false + +# Define the usage function +usage() { + echo "Usage: [pulp-api|pulp-content|pulp-worker|any command] [-s|--skip-migrations]" + exit 1 +} + +# Parse command line options using getopt +OPTS=$(getopt -o s --long skip-migrations -n 'pulp-common-entrypoint.sh' -- "$@") + +if [ $? != 0 ]; then + usage +fi + +eval set -- "$OPTS" + +# Process command line options +while true; do + case "$1" in + -sm|--skip-migrations) + skip_migrations=true + shift + ;; + -np|--no-admin-password) + no_admin_password=true + shift + ;; + --) + shift + break + ;; + *) + usage + ;; + esac +done + +# Get the command argument +command="$1" + +# Check if the skip_migrations flag is set +# Check if a command was provided +if [[ -n "$command" && "$command" = "pulp-content" || "$command" = "pulp-api" || "$command" = "pulp-worker" ]]; then + + if [ "$skip_migrations" = true ]; then + echo "Skipping migrations..." + fi + + if [ "$no_admin_password" = true ]; then + echo "Not setting the admin password..." + fi + + SKIP_MIGRATIONS=skip_migrations NO_ADMIN_PASSWORD=no_admin_password exec "/usr/bin/$command" else - exec "$@" + exec "$command" fi diff --git a/images/assets/pulp-content b/images/assets/pulp-content index 12550287..ad837d32 100755 --- a/images/assets/pulp-content +++ b/images/assets/pulp-content @@ -1,7 +1,8 @@ #!/bin/bash -x - -/usr/bin/wait_on_postgres.py -/usr/bin/wait_on_database_migrations.sh +if [ "${SKIP_MIGRATIONS}" = false ]; then + /usr/bin/wait_on_postgres.py + /usr/bin/wait_on_database_migrations.sh +fi if which pulpcore-content then diff --git a/images/assets/pulp-worker b/images/assets/pulp-worker index 886baa30..e94fc62e 100755 --- a/images/assets/pulp-worker +++ b/images/assets/pulp-worker @@ -1,7 +1,9 @@ #!/bin/bash -x -/usr/bin/wait_on_postgres.py -/usr/bin/wait_on_database_migrations.sh +if [ "${SKIP_MIGRATIONS}" = false ]; then + /usr/bin/wait_on_postgres.py + /usr/bin/wait_on_database_migrations.sh +fi export PULP_SETTINGS=/etc/pulp/settings.py export PATH=/usr/local/bin:/usr/bin/