Skip to content

Commit

Permalink
Add an option to skip migrations and avoid setting the admin password…
Browse files Browse the repository at this point in the history
… when the application is starting.

Closes pulp#544
  • Loading branch information
decko committed Sep 18, 2023
1 parent 49be51b commit 83d8501
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 27 deletions.
41 changes: 23 additions & 18 deletions images/assets/pulp-api
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 58 additions & 4 deletions images/assets/pulp-common-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions images/assets/pulp-content
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions images/assets/pulp-worker
Original file line number Diff line number Diff line change
@@ -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/
Expand Down

0 comments on commit 83d8501

Please sign in to comment.