Skip to content

Commit

Permalink
Add an option to skip migrations when the application is starting.
Browse files Browse the repository at this point in the history
Closes #544
  • Loading branch information
decko committed Sep 18, 2023
1 parent 49be51b commit d22620b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 19 deletions.
21 changes: 11 additions & 10 deletions images/assets/pulp-api
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ 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
/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
Expand Down
53 changes: 49 additions & 4 deletions images/assets/pulp-common-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,55 @@
#
# 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

# 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
-s|--skip-migrations)
skip_migrations=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

SKIP_MIGRATIONS=skip_migrations 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 d22620b

Please sign in to comment.