From 13f3811e4277af3aef58d88a22a76eaed597f67d Mon Sep 17 00:00:00 2001 From: Sameer Naik Date: Mon, 29 Sep 2014 20:16:07 +0530 Subject: [PATCH] launch a postgresql container if we can connect to the host docker When the database connection parameters are not specified, the image will try to spin up a redis container if it is able to communicate with the host docker. This is only possible if the following two options are specified in the docker run command: `-v /var/run/docker.sock:/run/docker.sock` `-v $(which docker):/bin/docker` This is primarily added to get the quick start guide to work without much of a hassel. --- assets/init | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/assets/init b/assets/init index 5bc3b72c..461eddb7 100755 --- a/assets/init +++ b/assets/init @@ -149,9 +149,38 @@ elif [ -n "${POSTGRESQL_PORT_5432_TCP_ADDR}" ]; then DB_NAME=${DB_NAME:-${POSTGRESQL_ENV_DB}} fi -# set default user and database -DB_USER=${DB_USER:-root} -DB_NAME=${DB_NAME:-gitlabhq_production} +## +## For the sake of getting the quick start guide to work, +## we attempt to spin up a postgresql container if possible. +## +## NOTE: this is only meant for getting the quick start guide to work . +## +if [ -z "${DB_HOST}" -a -n "$(which docker)" -a -S /var/run/docker.sock ]; then + echo "Database connection details not specified." + echo "Will try to spin up a new postgresql image with the name postgresql-gitlab." + echo "Please manually configure the database connection in production." + case "$(docker inspect --format {{.State.Running}} postgresql-gitlab 2>/dev/null)" in + true) + echo "Using existing postgresql container..." + ;; + false) + echo "Starting up existing postgresql container..." + docker start postgresql-gitlab >/dev/null 2>/dev/null + ;; + *) + echo "Starting up a new postgresql container..." + docker run --name='postgresql-gitlab' -d \ + -e 'DB_USER=gitlab_user' -e 'DB_PASS=gitlab_pass' -e 'DB_NAME=gitlab_db' \ + sameersbn/postgresql:latest >/dev/null 2>/dev/null + ;; + esac + DB_TYPE=postgres + DB_HOST=$(docker inspect --format {{.NetworkSettings.IPAddress}} postgresql-gitlab 2>/dev/null) + DB_PORT=5432 + DB_USER=gitlab_user + DB_PASS=gitlab_pass + DB_NAME=gitlab_db +fi if [ -z "${DB_HOST}" ]; then echo "ERROR: " @@ -173,6 +202,10 @@ case "${DB_TYPE}" in ;; esac +# set default user and database +DB_USER=${DB_USER:-root} +DB_NAME=${DB_NAME:-gitlabhq_production} + ## ## For the sake of getting the quick start guide to work, ## we attempt to spin up a redis container if possible.