quasseldocker/quassel_docker.sh
2015-01-05 17:14:25 +01:00

150 lines
3.2 KiB
Bash
Executable file

#!/bin/bash
#
# vars
#
# config vars
setup_volumes=true
setup_ports=false
# some basic vars
project_name="quasseldocker"
postgres_image="$project_name/postgres"
postgres_container="$project_name-postgres"
quassel_image="$project_name/quassel"
quassel_container="$project_name-quassel"
# postgres data dir
postgresdata="`pwd`/postgres/data"
quasselconf="`pwd`/quassel/quasselcore.conf"
#
# prep work
#
# should we set-up the volumes?
if [ "$setup_volumes" = true ]; then
postgres_volume="-v $postgresdata:/var/lib/postgresql/"
quassel_volume="-v $quasselconf:/var/lib/quassel/quasselcore.conf"
fi
# should we set-up the port forwarding to the host system?
quassel_port=""
if [ "$setup_ports" = true ]; then
quassel_port="-p 4242:4242"
fi
# 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 $postgres_volume -d $postgres_image"
# quassel docker
runquassel="docker run -h $quassel_container --link=$postgres_container:$postgres_container $quassel_volume $quassel_port --name $quassel_container -d $quassel_image"
# kill all
killall="docker kill $quassel_container $postgres_container"
# remove all
rmall="docker rm -v $quassel_container $postgres_container"
# info
info="
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 $quassel_volume --name $quassel_container --rm $quassel_image -c /bin/bash"
# help
if [[ "$1" == "--help" ]]; then
echo "
quasseldocker management script
usage:
$0 [ --kill | --run | --build | --help ]
options:
--build - build both (postgres; quassel) containers
--help - display this message
--kill - only kill and delete both containers
--run - only run both containers
running $0 without options will kill both containers (postgres, quassel), and then create and run both of them
$info
"
fi
# 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. $info"
fi
# do we want to kill all quassel-related dockers?
if [[ "$1" == "" || "$1" == "--kill" ]]; then
echo "
killing quassel-related dockers
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