I'm developing an open source application consisting of a Java web application and a postgresql database. Ideally it would be deployable similar to the process detailed in the shipyard quickstart:
Is there a recommended time to set up the database schema? I was thinking on making the Dockerfile for the database image create the schema when it is built but postgres isn't running at this time obviously.
We use Postgres and Docker where I work and we ended up doing the following:
At the top of docker-entrypoint.sh, I put in the following:
# Get the schema
url=$(curl -s -u ${GIT_USER}:${GIT_PASSWORD} "${SQL_SCRIPT_URL}" | python -c 'import sys, json; print json.load(sys.stdin)["download_url"]')
curl ${url} > db.sh
chmod +x db.sh
cp db.sh ./docker-entrypoint-initdb.d
This basically downloads a shell script from Github that initializes the schema for the database. We do this to manage versions of the schema, so when you start your container you can tell it which schema to use via an ENV variable.
Some notes about the code:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With