Skip to content

Commit

Permalink
Add reasonable initial tests of 'one shot' mode
Browse files Browse the repository at this point in the history
  • Loading branch information
justinclift committed Oct 3, 2024
1 parent db51d2d commit dcbed7e
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
11 changes: 8 additions & 3 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pgautoupgrade-postupgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,7 @@ else
echo "*************************************************************************************************"
echo "Post upgrade tasks have finished successfully. PostgreSQL should now be fully updated and online"
echo "*************************************************************************************************"
fi
fi

# Run a sync before exiting, just to ensure everything is flushed to disk before docker terminates the process
sync
65 changes: 48 additions & 17 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion test/docker-compose-pg10.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2.1"
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
Expand Down
1 change: 0 additions & 1 deletion test/docker-compose-pg11.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2.1"
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
Expand Down
1 change: 0 additions & 1 deletion test/docker-compose-pg12.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2.1"
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
Expand Down
1 change: 0 additions & 1 deletion test/docker-compose-pg13.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2.1"
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
Expand Down
1 change: 0 additions & 1 deletion test/docker-compose-pg14.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2.1"
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
Expand Down
1 change: 0 additions & 1 deletion test/docker-compose-pg15.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2.1"
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
Expand Down
1 change: 0 additions & 1 deletion test/docker-compose-pg16.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2.1"
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
Expand Down
1 change: 0 additions & 1 deletion test/docker-compose-pg9.5.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2.1"
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
Expand Down
1 change: 0 additions & 1 deletion test/docker-compose-pg9.6.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2.1"
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
Expand Down
1 change: 0 additions & 1 deletion test/docker-compose-pgauto.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2.1"
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
Expand Down

0 comments on commit dcbed7e

Please sign in to comment.