diff --git a/README.md b/README.md index 63a8e06..3cf953d 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ like to upgrade to, then change your docker image to match: ### "One shot" mode -If you just want to perform the upgrade without starting PostgreSQL +If you just want to perform the upgrade without running PostgreSQL afterwards, then you can use "[One Shot](https://github.com/pgautoupgrade/docker-pgautoupgrade/issues/13)" mode. To do that, add an environment variable called `PGAUTO_ONESHOT` diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 8549adc..a032f9a 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -575,9 +575,11 @@ _main() { UPGRADE_PERFORMED=1 - echo "**********************************************************" - echo "Automatic upgrade process finished with no errors reported" - echo "**********************************************************" + echo "***************************************************************************************" + echo "Automatic upgrade process finished upgrading the data format to PostgreSQL ${PGTARGET}." + echo "The database has not yet been reindexed nor updated the query planner stats. Those " + echo "will be done by a background task shortly. " + echo "***************************************************************************************" fi ### The main pgautoupgrade scripting ends here ### @@ -614,6 +616,9 @@ _main() { fi fi fi + + # Run a sync before exiting, just to ensure everything is flushed to disk before docker terminates the process + sync } if ! _is_sourced; then diff --git a/pgautoupgrade-postupgrade.sh b/pgautoupgrade-postupgrade.sh index 4e628d3..3c6afa6 100755 --- a/pgautoupgrade-postupgrade.sh +++ b/pgautoupgrade-postupgrade.sh @@ -84,4 +84,7 @@ else echo "*************************************************************************************************" echo "Post upgrade tasks have finished successfully. PostgreSQL should now be fully updated and online" echo "*************************************************************************************************" -fi \ No newline at end of file +fi + +# Run a sync before exiting, just to ensure everything is flushed to disk before docker terminates the process +sync \ No newline at end of file diff --git a/test.sh b/test.sh index 2b22615..4ed757f 100755 --- a/test.sh +++ b/test.sh @@ -6,6 +6,20 @@ FAILURE=0 # Array of PostgreSQL versions for testing PG_VERSIONS=(9.5 9.6 10 11 12 13 14 15 16 17) +# Useful output display +banner() { + set +x + CHAR=$1 + MSG=$2 + NUMSTARS=$((${#MSG}+1)) + echo + for i in $(seq 2 "$NUMSTARS"); do printf "%s" "${CHAR}"; done; echo + echo "${MSG}" + for i in $(seq 2 "$NUMSTARS"); do printf "%s" "${CHAR}"; done; echo + echo + set -x +} + # Stop any existing containers from previous test runs test_down() { docker compose -f test/docker-compose-pgauto.yml down @@ -31,21 +45,42 @@ test_run() { # Verify the PostgreSQL data files are now the target version PGVER=$(sudo cat postgres-data/PG_VERSION) if [ "$PGVER" != "${TARGET}" ]; then - echo - echo "****************************************************************************" - echo "Automatic upgrade of PostgreSQL from version ${VERSION} to ${TARGET} FAILED!" - echo "****************************************************************************" - echo + banner '*' "Standard automatic upgrade of PostgreSQL from version ${VERSION} to ${TARGET} FAILED!" FAILURE=1 else - echo - echo "*******************************************************************************" - echo "Automatic upgrade of PostgreSQL from version ${VERSION} to ${TARGET} SUCCEEDED!" - echo "*******************************************************************************" - echo + banner '*' "Standard automatic upgrade of PostgreSQL from version ${VERSION} to ${TARGET} SUCCEEDED!" fi - # Shut down containers from previous test runs + # Shut down any containers that are still running + docker compose -f docker-compose-pgauto.yml down --remove-orphans + + # Delete the upgraded PostgreSQL data directory + sudo rm -rf postgres-data + + ## + ## Tests for one shot mode + ## + banner '-' "Testing 'one shot' automatic upgrade mode for PostgreSQL ${VERSION} to ${TARGET}" + + # Create the PostgreSQL database using a specific version of PostgreSQL + docker compose -f "docker-compose-pg${VERSION}.yml" run --rm server create_db + + # Shut down all of the containers + docker compose -f "docker-compose-pg${VERSION}.yml" down --remove-orphans + + # Run the PostgreSQL container in one shot mode + TARGET_TAG="${TARGET}-${FLAVOR}" docker compose -f docker-compose-pgauto.yml run --rm -e PGAUTO_ONESHOT=yes postgres + + # Verify the PostgreSQL data files are now the target version + PGVER=$(sudo cat postgres-data/PG_VERSION) + if [ "$PGVER" != "${TARGET}" ]; then + banner '*' "'One shot' automatic upgrade of PostgreSQL from version ${VERSION} to ${TARGET} FAILED!" + FAILURE=1 + else + banner '*' "'One shot' automatic upgrade of PostgreSQL from version ${VERSION} to ${TARGET} SUCCEEDED!" + fi + + # Shut down any containers that are still running docker compose -f docker-compose-pgauto.yml down # If running on CI, delete the Postgres Docker image to avoid space problems @@ -76,12 +111,8 @@ done # Check for failure if [ "${FAILURE}" -ne 0 ]; then - echo - echo "FAILURE: Automatic upgrade of PostgreSQL failed in one of the tests. Please investigate." - echo + banner ' ' "FAILURE: Automatic upgrade of PostgreSQL failed in one of the tests. Please investigate." exit 1 else - echo - echo "SUCCESS: Automatic upgrade testing of PostgreSQL to all versions up to $PGTARGET passed without issue." - echo + banner ' ' "SUCCESS: Automatic upgrade testing of PostgreSQL to all versions up to $PGTARGET passed without issue." fi diff --git a/test/docker-compose-pg10.yml b/test/docker-compose-pg10.yml index 5736de3..1517d4e 100644 --- a/test/docker-compose-pg10.yml +++ b/test/docker-compose-pg10.yml @@ -1,4 +1,3 @@ -version: "2.1" x-redash-service: &redash-service image: redash/redash:10.1.0.b50633 depends_on: diff --git a/test/docker-compose-pg11.yml b/test/docker-compose-pg11.yml index 5983813..3037db5 100644 --- a/test/docker-compose-pg11.yml +++ b/test/docker-compose-pg11.yml @@ -1,4 +1,3 @@ -version: "2.1" x-redash-service: &redash-service image: redash/redash:10.1.0.b50633 depends_on: diff --git a/test/docker-compose-pg12.yml b/test/docker-compose-pg12.yml index b76b1e1..f8a7459 100644 --- a/test/docker-compose-pg12.yml +++ b/test/docker-compose-pg12.yml @@ -1,4 +1,3 @@ -version: "2.1" x-redash-service: &redash-service image: redash/redash:10.1.0.b50633 depends_on: diff --git a/test/docker-compose-pg13.yml b/test/docker-compose-pg13.yml index 63f5331..d854e70 100644 --- a/test/docker-compose-pg13.yml +++ b/test/docker-compose-pg13.yml @@ -1,4 +1,3 @@ -version: "2.1" x-redash-service: &redash-service image: redash/redash:10.1.0.b50633 depends_on: diff --git a/test/docker-compose-pg14.yml b/test/docker-compose-pg14.yml index 039d12a..94d982a 100644 --- a/test/docker-compose-pg14.yml +++ b/test/docker-compose-pg14.yml @@ -1,4 +1,3 @@ -version: "2.1" x-redash-service: &redash-service image: redash/redash:10.1.0.b50633 depends_on: diff --git a/test/docker-compose-pg15.yml b/test/docker-compose-pg15.yml index ac73007..0cc83d2 100644 --- a/test/docker-compose-pg15.yml +++ b/test/docker-compose-pg15.yml @@ -1,4 +1,3 @@ -version: "2.1" x-redash-service: &redash-service image: redash/redash:10.1.0.b50633 depends_on: diff --git a/test/docker-compose-pg16.yml b/test/docker-compose-pg16.yml index 2f29927..96e0bed 100644 --- a/test/docker-compose-pg16.yml +++ b/test/docker-compose-pg16.yml @@ -1,4 +1,3 @@ -version: "2.1" x-redash-service: &redash-service image: redash/redash:10.1.0.b50633 depends_on: diff --git a/test/docker-compose-pg9.5.yml b/test/docker-compose-pg9.5.yml index dd37bd7..92ad396 100644 --- a/test/docker-compose-pg9.5.yml +++ b/test/docker-compose-pg9.5.yml @@ -1,4 +1,3 @@ -version: "2.1" x-redash-service: &redash-service image: redash/redash:10.1.0.b50633 depends_on: diff --git a/test/docker-compose-pg9.6.yml b/test/docker-compose-pg9.6.yml index ee2db83..228e5f6 100644 --- a/test/docker-compose-pg9.6.yml +++ b/test/docker-compose-pg9.6.yml @@ -1,4 +1,3 @@ -version: "2.1" x-redash-service: &redash-service image: redash/redash:10.1.0.b50633 depends_on: diff --git a/test/docker-compose-pgauto.yml b/test/docker-compose-pgauto.yml index 495903c..f3cb600 100644 --- a/test/docker-compose-pgauto.yml +++ b/test/docker-compose-pgauto.yml @@ -1,4 +1,3 @@ -version: "2.1" x-redash-service: &redash-service image: redash/redash:10.1.0.b50633 depends_on: