From 514d0098ad5ed5ef21c0b2abfeb4a34d457ebde1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=27rysiek=27=20Wo=C5=BAniak?= Date: Sat, 3 Jan 2015 23:36:09 +0100 Subject: [PATCH] kind-of working --- postgres/Dockerfile | 20 ++++----- postgres/prep.sh | 24 ++++++++++ quassel/Dockerfile | 12 ++--- quassel_docker.sh | 104 +++++++++++++++++++++++++++++++++++++------- 4 files changed, 128 insertions(+), 32 deletions(-) create mode 100755 postgres/prep.sh diff --git a/postgres/Dockerfile b/postgres/Dockerfile index 4b39c5b..6b598b8 100644 --- a/postgres/Dockerfile +++ b/postgres/Dockerfile @@ -20,17 +20,6 @@ RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get upgrade & # Note: The official Debian and Ubuntu images automatically ``apt-get clean`` # after each ``apt-get`` -# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed`` -USER postgres - -# Create a PostgreSQL role named ``quassel`` with no password (UNIX sockets FTW!) and -# then create a database `quassel` owned by the ``quassel`` role. -#RUN /usr/lib/postgresql/9.3/bin/initdb /etc/postgresql/9.3/main/ && \ - -RUN /etc/init.d/postgresql start && \ - psql --command "CREATE USER quassel;" && \ - psql --command "CREATE DATABASE quassel WITH OWNER quassel TEMPLATE template0 ENCODING 'UTF8';" && \ - /etc/init.d/postgresql stop # Only quassel needs to connectm eh? #RUN echo "host quassel quassel quassel-docker-quassel trust" >> /etc/postgresql/9.3/main/pg_hba.conf @@ -39,11 +28,20 @@ RUN echo "host quassel quassel 172.17.0.0/16 trust" >> /etc/postgresql/9.3/m # Well... RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf +# prep script +ADD prep.sh /root/prep.sh +# just in case this is a test drive -- production environments will need to re-run prep.sh for the external volume +RUN ls -l /root && /bin/bash /root/prep.sh + # Expose the PostgreSQL port EXPOSE 5432 # Add VOLUMEs to allow backup of config, logs and databases VOLUME ["/var/lib/postgresql/"] +# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed`` +USER postgres + # Set the default command to run when starting the container +CMD [] ENTRYPOINT ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/etc/postgresql/9.3/main/"] diff --git a/postgres/prep.sh b/postgres/prep.sh new file mode 100755 index 0000000..fb6e5f4 --- /dev/null +++ b/postgres/prep.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# removing the database cluster if it exists and prepping everything for posgresql operation +# be careful, Will Robinson! + +# we need to be root for this +if [[ `whoami` != 'root' ]]; then + echo "we need to be root for this, quitting" + exit 1 +fi + +# work the directory +cd /var/lib/postgresql +chown postgres:postgres ./ +chmod 0700 ./ + +# initdb as postgres +su -c '/usr/lib/postgresql/9.3/bin/initdb /var/lib/postgresql/9.3/main' postgres + +# let quassel db +/etc/init.d/postgresql start +su -c 'psql --command "CREATE USER quassel;"' postgres +su -c "psql --command \"CREATE DATABASE quassel WITH OWNER quassel TEMPLATE template0 ENCODING 'UTF8';\"" postgres +/etc/init.d/postgresql stop \ No newline at end of file diff --git a/quassel/Dockerfile b/quassel/Dockerfile index a23d158..96215bc 100644 --- a/quassel/Dockerfile +++ b/quassel/Dockerfile @@ -9,9 +9,11 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get upgrade && apt-get libqca2-plugin-ossl libicu52 \ postgresql-client -USER quasselcore -# use ENTRYPOINT instead of CMD so that we can easily pass additional arguments to the run command -ENTRYPOINT ["quasselcore", "--configdir=/var/lib/quassel/"] - -VOLUME ["/var/lib/quassel"] +VOLUME ["/var/lib/quassel/quasselcore.conf"] EXPOSE 4242 + +USER quasselcore + +# use ENTRYPOINT instead of CMD so that we can easily pass additional arguments to the run command +CMD [] +ENTRYPOINT ["quasselcore", "--configdir=/var/lib/quassel/"] diff --git a/quassel_docker.sh b/quassel_docker.sh index 8080d63..bb99426 100755 --- a/quassel_docker.sh +++ b/quassel_docker.sh @@ -8,28 +8,100 @@ quassel_image="$project_name/quassel" quassel_container="$project_name-quassel" # postgres data dir -pgdata="`pwd`/postgres/data" +postgresdata="`pwd`/postgres/data" +quasselconf="`pwd`/quassel/quasselcore.conf" # prep work +# build postgres image +buildpostgres="docker build -t $postgres_image postgres" + +# build postgres container +buildquassel="docker build -t $quassel_image quassel" + # postgres docker -runpostgres="docker run -h $postgres_container --name $postgres_container -v $pgdata:/var/lib/postgresql/ --rm $postgres_image" +runpostgres="docker run -h $postgres_container --name $postgres_container -v $postgresdata:/var/lib/postgresql/ -d $postgres_image" # quassel docker -runquassel="docker run -h $quassel_container --link=$quassel_container:$postgres_container --name $quassel_container --rm $quassel_image" +runquassel="docker run -h $quassel_container --link=$postgres_container:$postgres_container -v $quasselconf:/var/lib/quassel/quasselcore.conf --name $quassel_container -d $quassel_image" -echo """ -will run: - - $runpostgres - - $runquassel -""" +# kill all +killall="docker kill $quassel_container $postgres_container" -echo "running the postgres container..." -$runpostgres -echo "running the quassel container..." -$runquassel -echo "all done" +# remove all +rmall="docker rm -v $quassel_container $postgres_container" -# root access to both containers: -# docker run --entrypoint /bin/sh -u root -h $postgres_container -t -i --name $postgres_container --rm $postgres_image -c /bin/bash -# docker run --entrypoint /bin/sh -u root -h $quassel_container --link=$quassel_container:$postgres_container -t -i --name $quassel_container --rm $quassel_image -c /bin/bash \ No newline at end of file +# do we want to build stuff? +if [[ "$1" == "--build" ]]; then + echo " + + building + + will run: + - $buildpostgres + - $buildquassel + " + + echo + echo "building the postgres container..." + $buildpostgres + + echo + echo "building the quassel container..." + $buildquassel + + echo " + + all built. remember to prep the postgres environment if needed: + - docker run --entrypoint /bin/bash -u root -t -i -v `pwd`/postgres/data:/var/lib/postgresql/ --rm $postgres_image + + root access to both containers: + - docker run --entrypoint /bin/sh -u root -h $postgres_container -t -i --name $postgres_container --rm $postgres_image -c /bin/bash + - docker run --entrypoint /bin/sh -u root -h $quassel_container --link=$postgres_container:$postgres_container -t -i --name $quassel_container --rm $quassel_image -c /bin/bash + " + +fi + +# do we want to clean stuff up? +if [[ "$1" == "" || "$1" == "--clean-up" ]]; then + echo " + + cleaning up + + will run: + - $killall + - $rmall + " + + $killall + $rmall +fi + +# do we want to run stuff? +if [[ "$1" == "" || "$1" == "--run" ]]; then + + echo " + + running the containers + + will run: + - $runpostgres + - $runquassel + " + + echo + echo "running the postgres container..." + $runpostgres + + echo + echo "running the quassel container..." + $runquassel + + echo " + + all done, containers running: + - $postgres_container (`docker inspect --format '{{ .NetworkSettings.IPAddress }}' $postgres_container`) + - $quassel_container (`docker inspect --format '{{ .NetworkSettings.IPAddress }}' $quassel_container`) + " + +fi \ No newline at end of file