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."
@X4
Copy link

X4 commented Jul 22, 2013

The error in that script starts on line 13:

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`
...

Because the files .TREEIO_PGLITE_VOLUME_ID and .TREEIO_PGLITE_PWD don't exist on my machine.

@sermtech
Copy link

@funkotron Man, thanks so much. I really hope more people realize the relevance of this script. Tree.io is a great project, one of the most complete for project management (and free) and your script made it effortless to install. Thanks again.

@funkotron
Copy link
Author

@X4 I apologise I've only just seen your comment. For some reason I don't get notifications of comments on this page.

I don't think that is the error. It's expected if those files don't exist the command will not store anything in the variables but should not crash.

I believe it hangs on the next command which waits for the pglite container to be run and greps for the password that gets returned via stdout:

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

I will add more print statements in between to confirm this and will try and re-run on my machine with the dot files deleted.

@funkotron
Copy link
Author

They really need to add notifications for gists isaacs/github#21

@dtk1985
Copy link

dtk1985 commented Nov 27, 2013

Hi

Thanks for releasing treeio in docker container. I've run your script, it created the container successfully but I'm getting errors when i try to view the app in browser. (ubuntu server 13.04 x64)

OperationalError at /

invalid port number: "0.0.0.0:49153"

Request Method: GET
Request URL: http://derzsidavid.tk/
Django Version: 1.3
Exception Type: OperationalError
Exception Value:

invalid port number: "0.0.0.0:49153"

Exception Location: /usr/local/lib/python2.7/dist-packages/psycopg2/init.py in connect, line 164
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:

['/usr/local/bin',
'/srv/treeio',
'/srv/treeio/treeio',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/pymodules/python2.7']

Server time: Wed, 27 Nov 2013 12:16:50 +0000

it looks like the port is 0.0.0.0:49153 instead of just 49153. what do i need to modify to use the correct port?

ffound the solution @http://docs.docker.io/en/latest/use/basics/

| awk -F: '{ print $2 }') goes before the end bracket in lines PG_PORT & SSHPORT. thanks again

thanks
David

@dimaape
Copy link

dimaape commented Jan 22, 2014

Hi, funkotron! Thanks for the greate container! Installation was such a joy. But now i cant upload any file, cant generate pdfs, chat dont work =/ Do you have any suggestions how to solve this?
Thank you in advance!

@davidbasswwu
Copy link

Hi funkotron - your Docker image is not listed in https://index.docker.io/search?q=treeio

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