Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to skip migrations when the application is starting. #548

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/544.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds an option to skip migration and setting the admin password.
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
Loading