Skip to content

Instantly share code, notes, and snippets.

@funkotron
Last active December 18, 2019 17:56
Show Gist options
  • Save funkotron/6025664 to your computer and use it in GitHub Desktop.
Save funkotron/6025664 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: [email protected]
# 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."
Copy link

ghost commented Mar 25, 2014

Hi funkotron, I am trying to install a modified tree.io via docker . Can you suggest the best approach ?

@acpmasquerade
Copy link

Does the script assume that it is being run my home directory. Because I see these two errors
cat: .TREEIO_PGLITE_VOLUME_ID: No such file or directory
cat: .TREEIO_PGLITE_PWD: No such file or directory

and when I checked from another shell, these two files were created on user ~ home directory.

@hideadesign
Copy link

Hi ! How can I install this on heroku ? any idea or any help ? thanks in advance

@alfawalidou
Copy link

Hello every body, could you please confirm if should be work on latest ubuntu version, i had alot of errors during the installation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment