Skip to content

Instantly share code, notes, and snippets.

@josephbolus
Forked from funkotron/docker_create_treeio.sh
Created November 9, 2015 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephbolus/0405f4e6f251f6f4be0b to your computer and use it in GitHub Desktop.
Save josephbolus/0405f4e6f251f6f4be0b to your computer and use it in GitHub Desktop.
Using Docker (requires docker to be installed http://www.docker.io/gettingstarted/ ), spawn a postgresql instance and a dynamically configured treeio instance.
#!/bin/bash
# Description: Using Docker (requires docker to be installed http://www.docker.io/gettingstarted/ ), spawn a postgresql instance and a dynamically configured treeio instance
# Also requires postgresql client tools http://www.postgresql.org/download/linux/ubuntu/
# Run chmod +x to make this file executable then run it: ./docker_create_treeio.sh
# Author: Adam Awan
# Email: adam@tree.io
# Set the port to forward for Tree.io
TREEIO_PORT="80"
# Create a PostgreSQL Instance
echo "Retrieving adam/pglite PostgreSQL Container..."
docker pull adam/pglite
echo "Running adam/pglite PostgreSQL Container..."
EXISTING_VOLUME=`cat .TREEIO_PGLITE_VOLUME_ID`
if [ -z $EXISTING_VOLUME ]; then
VOLUME_OPTION="-v /data"
else
EXISTING_VOLUME="-volumes-from $EXISTING_VOLUME"
fi
EXISTING_PASSWORD=`cat .TREEIO_PGLITE_PWD`
PGID=$(docker run -d -p 5432 $VOLUME_OPTION $EXISTING_VOLUME adam/pglite /init $EXISTING_PASSWORD)
while ! docker logs $PGID 2>/dev/null | grep PG_PASSWORD | grep -q ^PG_PASSWORD= ; do sleep 1 ; done
eval $(docker logs $PGID 2>/dev/null)
PG_PORT=$(docker port $PGID 5432)
if [ -z $EXISTING_VOLUME ]; then
# This is the first volume so save the ID and Password for later accesss
echo $PGID > $HOME/.TREEIO_PGLITE_VOLUME_ID
echo $PG_PASSWORD > $HOME/.TREEIO_PGLITE_PWD
fi
PG_HOST=`ifconfig | grep "docker" -A 1 | grep "inet" | cut -d\: -f2 | cut -d\ -f1`
echo "A new PostgreSQL instance is listening at IP $PG_HOST on port $PG_PORT. The admin user is postgres, the admin password is $PG_PASSWORD."
# Sleep for a second to give it a chance to spin up
sleep 1
echo "Pulling the treeio container..."
docker pull adam/treeio
echo "If running Vagrant you will need to forward port $TREEIO_PORT"
TREEID=$(docker run -d -p 22 -p $TREEIO_PORT:5000 adam/treeio /usr/sbin/treeio $PG_HOST $PG_PORT $PG_PASSWORD)
SSHPORT=$(docker port $TREEID 22)
echo "treeio running with container ID $TREEID"
echo "treeio SSH running on port $SSHPORT"
echo "WARNING! You must change the root password of your treeio container - currently it is 'treeio'."
echo "You can ssh to your container by running: ssh -p $SSHPORT root@localhost"
echo "Once connected run passwd to change your password."
echo "treeio is running at http://localhost:$TREEIO_PORT with username 'admin' and password 'admin'."
echo "Container setup complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment