Skip to content

Commit

Permalink
Merge branch 'feuerrot-dockerize'
Browse files Browse the repository at this point in the history
Addresses #4
  • Loading branch information
derf committed May 5, 2019
2 parents 4696f8d + a1a0f33 commit 8c23c96
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
@@ -0,0 +1,5 @@
Dockerfile
.dockerignore
.gitignore
README.md
travelynx.conf
61 changes: 61 additions & 0 deletions .gitignore
@@ -1 +1,62 @@
/travelynx.conf

# Created by https://www.gitignore.io/api/vim,perl
# Edit at https://www.gitignore.io/?templates=vim,perl

### Perl ###
!Build/
.last_cover_stats
/META.yml
/META.json
/MYMETA.*
*.o
*.pm.tdy
*.bs

# Devel::Cover
cover_db/

# Devel::NYTProf
nytprof.out

# Dizt::Zilla
/.build/

# Module::Build
_build/
Build
Build.bat

# Module::Install
inc/

# ExtUtils::MakeMaker
/blib/
/_eumm/
/*.gz
/Makefile
/Makefile.old
/MANIFEST.bak
/pm_to_blib
/*.zip

### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

# End of https://www.gitignore.io/api/vim,perl
23 changes: 23 additions & 0 deletions Dockerfile
@@ -0,0 +1,23 @@
FROM debian:stretch-slim

ARG DEBIAN_FRONTEND=noninteractive

COPY cpanfile /app/cpanfile
WORKDIR /app

RUN apt-get update && apt-get install --no-install-recommends -y \
cpanminus \
build-essential \
libpq-dev \
git \
cron \
&& cpanm -in --no-man-pages --installdeps . \
&& rm -rf ~/.cpanm \
&& apt-get purge -y \
build-essential \
cpanminus \
&& apt-get autoremove -y

COPY . /app

CMD ["/app/docker-run.sh"]
40 changes: 40 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,40 @@
version: "3.6"
x-common-env: &common-env
TRAVELYNX_DB_HOST: database
TRAVELYNX_DB_NAME: travelynx
TRAVELYNX_DB_USERNAME: travelynx
TRAVELYNX_DB_PASSWORD: travelynx
TRAVELYNX_SECRET: 12345678
TRAVELYNX_MAIL_DISABLE: 1
MOJO_MODE: development

x-common-config: &common-config
volumes:
- ./examples/docker/travelynx.conf:/app/travelynx.conf
build: .
networks:
- backend

services:
database:
image: postgres:11
networks:
- backend
environment:
<<: *common-env
volumes:
- ./examples/docker/postgres-init.sh:/docker-entrypoint-initdb.d/init.sh
travelynx:
<<: *common-config
ports:
- "8000:8093"
environment:
<<: *common-env
cron:
<<: *common-config
environment:
<<: *common-env
CRON: 1

networks:
backend:
58 changes: 58 additions & 0 deletions docker-run.sh
@@ -0,0 +1,58 @@
#!/bin/bash
set -eu

WAIT_DB_HOST=${TRAVELYNX_DB_HOST}
WAIT_DB_PORT=5432

check_config() {
if [ ! -f travelynx.conf ]
then
echo "The configuration file is missing"
exit 1
fi
}

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
else
echo "Can't reach DB @ ${WAIT_DB_HOST}:${WAIT_DB_PORT}"
fi
sleep 1
done
set -e
}

run_app() {
if [ \
"${TRAVELYNX_MAIL_DISABLE:-0}" -eq 0 \
-a "${TRAVELYNX_MAIL_HOST:-unset}" != "unset" \
]
then
export EMAIL_SENDER_TRANSPORT=SMTP
export EMAIL_SENDER_TRANSPORT_HOST=${TRAVELYNX_MAIL_HOST}
export EMAIL_SENDER_TRANSPORT_PORT=${TRAVELYNX_MAIL_PORT:-25}
fi

perl index.pl database migrate

exec /usr/local/bin/hypnotoad -f index.pl
}

run_cron() {
exec perl index.pl worker
}

check_config
wait_for_db

if [ "${CRON:-0}" -ne "0" ]
then
run_cron
fi

run_app
8 changes: 8 additions & 0 deletions examples/docker/postgres-init.sh
@@ -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
26 changes: 26 additions & 0 deletions examples/docker/travelynx.conf
@@ -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"),
],
};

0 comments on commit 8c23c96

Please sign in to comment.