Repository navigation
feat(postgres): adding upgrade scripts to the postgres #12
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| #set -eof pipefail | ||
|
|
||
| cleanup() { | ||
| kill-containers "${SWIFT_DATA}" "${SWIFT_JOB}" "${PG_JOB}" | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| waitting-install-apk() { | ||
| sleep 30s | ||
| apk_running="apk" | ||
| puts-step "Installing apk, coffee" | ||
| while true | ||
| do | ||
| apk_running=$(docker exec "${PG_JOB}" "ps -ef|grep apk|grep -v grep") | ||
| if [ -z "$apk_running" ] ; then | ||
| break | ||
| fi | ||
| puts-step "..." | ||
| sleep 10s | ||
| done | ||
| echo "Install apk process is complete" | ||
| } | ||
|
|
||
| TEST_ROOT=$(dirname "${BASH_SOURCE[0]}")/ | ||
| # shellcheck source=/dev/null | ||
| source "${TEST_ROOT}/test.sh" | ||
|
|
||
| # make sure we are in this dir | ||
| CURRENT_DIR=$(cd "$(dirname "$0")"|| exit; pwd) | ||
|
|
||
| create-postgres-creds | ||
|
|
||
| puts-step "fetching openstack credentials" | ||
|
|
||
| # turn creds into something that we can use. | ||
| mkdir -p "${CURRENT_DIR}"/tmp/swift | ||
|
|
||
| # guess which value to use for tenant: | ||
| TENANT="" | ||
|
|
||
| echo "test:tester" > "${CURRENT_DIR}"/tmp/swift/username | ||
| echo "testing" > "${CURRENT_DIR}"/tmp/swift/password | ||
| echo "${TENANT}" > "${CURRENT_DIR}"/tmp/swift/tenant | ||
| echo "http://swift:8080/auth/v1.0" > "${CURRENT_DIR}"/tmp/swift/authurl | ||
| echo "1" > "${CURRENT_DIR}"/tmp/swift/authversion | ||
| echo "deis-swift-test" > "${CURRENT_DIR}"/tmp/swift/database-container | ||
|
|
||
| # boot swift | ||
| SWIFT_DATA=$(docker run -d -v /srv --name SWIFT_DATA busybox) | ||
|
|
||
| SWIFT_JOB=$(docker run -d --name onlyone --hostname onlyone --volumes-from SWIFT_DATA -t deis/swift-onlyone:git-8516d23) | ||
|
|
||
| test-upgrade-from(){ | ||
| PGDATA_DIR=${CURRENT_DIR}/tmp/postgres/tmp_$(date +%s) | ||
| mkdir -p "$PGDATA_DIR" | ||
|
|
||
| docker run --rm \ | ||
| -v "${PGDATA_DIR}:/var/lib/postgres/pg_data" \ | ||
| -e PGDATA=/var/lib/postgres/pg_data \ | ||
| "$1" \ | ||
| bash -c "chown -R postgres /var/lib/postgres/pg_data && su-exec postgres initdb" | ||
|
|
||
| PG_CMD="docker run -d --link ${SWIFT_JOB}:swift -e BACKUP_FREQUENCY=3s \ | ||
| -e DATABASE_STORAGE=swift \ | ||
| -e PGCTLTIMEOUT=1200 \ | ||
| -e PGDATA=/var/lib/postgres/pg_data \ | ||
| -v ${PGDATA_DIR}:/var/lib/postgres/pg_data \ | ||
| -v ${CURRENT_DIR}/tmp/creds:/var/run/secrets/deis/database/creds \ | ||
| -v ${CURRENT_DIR}/tmp/swift:/var/run/secrets/deis/objectstore/creds \ | ||
| $IMAGE" | ||
| PG_JOB=$($PG_CMD) | ||
| sleep 90s | ||
| puts-step "sleeping for 90s while postgres is restore..." | ||
|
|
||
| check-postgres "${PG_JOB}" | ||
| puts-step "postgres upgrade from $1" | ||
| } | ||
|
|
||
| test-upgrade-from-wal() { | ||
| PG_CMD="docker run -d --link ${SWIFT_JOB}:swift -e BACKUP_FREQUENCY=3s \ | ||
| -e DATABASE_STORAGE=swift \ | ||
| -e PGCTLTIMEOUT=1200 \ | ||
| -v ${CURRENT_DIR}/tmp/creds:/var/run/secrets/deis/database/creds \ | ||
| -v ${CURRENT_DIR}/tmp/swift:/var/run/secrets/deis/objectstore/creds \ | ||
| $1" | ||
|
|
||
| start-postgres "$PG_CMD" | ||
| # display logs for debugging purposes | ||
| puts-step "displaying swift logs" | ||
| docker logs "${SWIFT_JOB}" | ||
| check-postgres "${PG_JOB}" | ||
| puts-step "shutting off postgres, then rebooting to test data recovery" | ||
| kill-containers "${PG_JOB}" | ||
|
|
||
| PG_CMD="docker run -d --link ${SWIFT_JOB}:swift -e BACKUP_FREQUENCY=3s \ | ||
| -e DATABASE_STORAGE=swift \ | ||
| -e PGCTLTIMEOUT=1200 \ | ||
| -v ${CURRENT_DIR}/tmp/creds:/var/run/secrets/deis/database/creds \ | ||
| -v ${CURRENT_DIR}/tmp/swift:/var/run/secrets/deis/objectstore/creds \ | ||
| $IMAGE" | ||
|
|
||
| start-postgres "${PG_CMD}" | ||
|
|
||
| check-postgres "${PG_JOB}" | ||
| } | ||
|
|
||
| IMAGE="$1" | ||
|
|
||
| test-upgrade-from postgres:9.4-alpine | ||
| kill-containers "${PG_JOB}" | ||
|
|
||
| test-upgrade-from postgres:9.5-alpine | ||
| kill-containers "${PG_JOB}" | ||
|
|
||
| test-upgrade-from postgres:9.6-alpine | ||
| kill-containers "${PG_JOB}" | ||
|
|
||
| test-upgrade-from postgres:10-alpine | ||
| kill-containers "${PG_JOB}" | ||
|
|
||
| test-upgrade-from postgres:11-alpine | ||
| kill-containers "${PG_JOB}" | ||
|
|
||
| test-upgrade-from-wal hephy/postgres:v2.7.1 | ||
|
|
||
| puts-step "tests PASSED!" | ||
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| POSTGRES_OLD_VERSION=$(cat "$1"/PG_VERSION) | ||
|
|
||
| install-old-postgres() { | ||
| if [ "$POSTGRES_OLD_VERSION" == "9.4" ];then | ||
| echo 'http://dl-cdn.alpinelinux.org/alpine/v3.3/main' >> /etc/apk/repositories | ||
| apk add --update --virtual .upgrade-deps postgresql=9.4.15-r0 | ||
| elif [ "$POSTGRES_OLD_VERSION" == "9.5" ];then | ||
| echo 'http://dl-cdn.alpinelinux.org/alpine/v3.4/main' >> /etc/apk/repositories | ||
| apk add --update --virtual .upgrade-deps postgresql=9.5.13-r0 | ||
| elif [ "$POSTGRES_OLD_VERSION" == "9.6" ];then | ||
| echo 'http://dl-cdn.alpinelinux.org/alpine/v3.6/main' >> /etc/apk/repositories | ||
| apk add --update --virtual .upgrade-deps postgresql=9.6.10-r0 | ||
| elif [ "$POSTGRES_OLD_VERSION" == "10" ];then | ||
| echo 'http://dl-cdn.alpinelinux.org/alpine/v3.8/main' >> /etc/apk/repositories | ||
| apk add --update --virtual .upgrade-deps postgresql=10.5-r0 | ||
| else | ||
| echo "Upgrading from ${POSTGRES_OLD_VERSION} is not supported" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| remove-old-postgres() { | ||
| apk del .upgrade-deps | ||
| } | ||
|
|
||
| if [ "$POSTGRES_OLD_VERSION" != "$PG_MAJOR" ] ; then | ||
| echo | ||
| echo 'PostgreSQL executing the pg_upgrade script.' | ||
| echo | ||
|
|
||
| cd /tmp||exit | ||
| install-old-postgres | ||
|
|
||
| su-exec postgres /usr/bin/pg_ctl \ | ||
| -D "$1" \ | ||
| -o "-c listen_addresses=''" \ | ||
| -w start | ||
|
|
||
| su-exec postgres /usr/bin/pg_ctl \ | ||
| -D "$1" \ | ||
| -w stop | ||
|
|
||
| su-exec postgres pg_upgrade \ | ||
|
Cryptophobia marked this conversation as resolved.
Resolved
|
||
| --old-datadir="$1" \ | ||
| --new-datadir="$2" \ | ||
| --old-bindir=/usr/bin \ | ||
| --new-bindir=/usr/local/bin | ||
|
|
||
| remove-old-postgres | ||
| rm -rf /var/cache/apk/* | ||
|
|
||
| echo | ||
| echo 'PostgreSQL upgrade process complete; ready for start up.' | ||
| echo | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.