Last active
December 9, 2018 23:13
-
-
Save cddr/60040ff712163196ce139bc11578f349 to your computer and use it in GitHub Desktop.
Show the schema loaded by the app contained in the specified docker image
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
#!/bin/bash | |
function cleanup () { | |
docker rm -f $pg >/dev/null | |
} | |
trap cleanup EXIT | |
PARAMS="" | |
while (( "$#" )); do | |
case "$1" in | |
--pg-version) | |
PGVERSION=$2 | |
shift 2 | |
;; | |
-b|--schema-builders) | |
SCHEMA_BUILDERS=$2 | |
shift 2 | |
;; | |
-i|--image) | |
IMAGE=$2 | |
shift 2 | |
;; | |
-d|--dbname) | |
PGDATABASE=$2 | |
shift 2 | |
;; | |
--) # end argument parsing | |
shift | |
break | |
;; | |
-*|--*=) # unsupported flags | |
echo "Error: Unsupported flag $1" >&2 | |
exit 1 | |
;; | |
*) # preserve positional arguments | |
PARAMS="$PARAMS $1" | |
shift | |
;; | |
esac | |
done | |
# set positional arguments in their proper place | |
eval set -- "$PARAMS" | |
{ | |
# pull required images | |
docker pull $IMAGE | |
docker pull postgres:9.6 | |
# start a postgres db | |
pg=$(docker run -it --rm -d \ | |
-e POSTGRES_PASSWORD=admin \ | |
postgres:9.6) | |
# generate the schema by invoking the matching builder | |
migrate=$(docker run --link $pg:pg --rm \ | |
-d \ | |
-e IMAGE=$IMAGE \ | |
-v $SCHEMA_BUILDERS:/tmp/schema-builders \ | |
--entrypoint /bin/bash \ | |
$IMAGE -c "bash /tmp/schema-builders/$IMAGE") | |
} &> /dev/null | |
docker wait $migrate >/dev/null | |
# dump the schema | |
docker run \ | |
--link $pg:pg \ | |
-e PGPASSWORD=admin \ | |
--rm \ | |
postgres:9.6 \ | |
pg_dump -h pg -U postgres $PGDATABASE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment