docker: add docker-compose configuration

🔥docker🔥compose🔥
This commit is contained in:
Markus Witt 2019-04-21 23:13:03 +02:00
parent 7df47bdc4e
commit 46e85324df
4 changed files with 82 additions and 1 deletions

29
docker-compose.yml Normal file
View file

@ -0,0 +1,29 @@
version: "3.6"
x-common-env: &common-env
TRAVELYNX_DB_HOST: database
TRAVELYNX_DB_NAME: travelynx
TRAVELYNX_DB_USERNAME: travelynx
TRAVELYNX_DB_PASSWORD: travelynx
services:
database:
image: postgres:11
networks:
- backend
environment:
<<: *common-env
volumes:
- ./examples/docker/postgres-init.sh:/docker-entrypoint-initdb.d/init.sh
travelynx:
build: .
ports:
- "8000:8093"
networks:
- backend
volumes:
- ./examples/docker/travelynx.conf:/app/travelynx.conf
environment:
<<: *common-env
TRAVELYNX_MAIL_DISABLE: 1
TRAVELYNX_SECRET: 12345678
networks:
backend:

View file

@ -1,6 +1,22 @@
#!/bin/sh
#!/bin/bash
set -eu
WAIT_DB_HOST=${TRAVELYNX_DB_HOST}
WAIT_DB_PORT=5432
wait_for_db() {
set +e
for i in $(seq 1 ${WAIT_DB_TIMEOUT:-5})
do
(echo >/dev/tcp/${WAIT_DB_HOST}/${WAIT_DB_PORT}) &>/dev/null
if [ $? -eq 0 ]; then
break
fi
sleep 1
done
set -e
}
if [ ! -f travelynx.conf ]
then
echo "The configuration file is missing"
@ -17,6 +33,8 @@ then
export EMAIL_SENDER_TRANSPORT_PORT=${TRAVELYNX_MAIL_PORT:-25}
fi
wait_for_db
perl index.pl database migrate
exec /usr/local/bin/hypnotoad -f index.pl

View file

@ -0,0 +1,8 @@
#!/bin/sh
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER ${TRAVELYNX_DB_USERNAME} PASSWORD '${TRAVELYNX_DB_PASSWORD}';
CREATE DATABASE ${TRAVELYNX_DB_NAME};
GRANT ALL PRIVILEGES ON DATABASE ${TRAVELYNX_DB_NAME} TO ${TRAVELYNX_DB_USERNAME};
EOSQL

View file

@ -0,0 +1,26 @@
{
cache => {
schedule => $ENV{TRAVELYNX_IRIS_CACHE} // '/var/cache/travelynx/iris',
realtime => $ENV{TRAVELYNX_IRISRT_CACHE} // '/var/cache/travelynx/iris-rt',
},
db => {
host => $ENV{TRAVELYNX_DB_HOST} // 'die("Please set TRAVELYNX_DB_HOST")',
database => $ENV{TRAVELYNX_DB_NAME} // 'travelynx',
user => $ENV{TRAVELYNX_DB_USERNAME} // 'travelynx',
password => $ENV{TRAVELYNX_DB_PASSWORD} // die("Please set TRAVELYNX_DB_PASSWORD"),
},
hypnotoad => {
accepts => $ENV{TRAVELYNX_HYPNOTOAD_ACCEPTS} // 100,
clients => $ENV{TRAVELYNX_HYPNOTOAD_CLIENTS} // 10,
listen => [ $ENV{TRALELYNX_HYPNOTOAD_LISTEN} // 'http://*:8093' ],
pid_file => '/tmp/travelynx.pid',
workers => $ENV{TRAVELYNX_HYPNOTOAD_WORKERS} // 2,
spare => $ENV{TRAVELYNX_HYPNOTOAD_SPARE} // 2,
},
mail => {
disabled => $ENV{TRAVELYNX_MAIL_DISABLE} // 0,
},
secrets => [
$ENV{TRAVELYNX_SECRET} // die("Please set TRAVELYNX_SECRET"),
],
};