use cpanfile to install dependencies, run worker in another docker container

This commit is contained in:
Markus Witt 2019-05-03 22:50:59 +02:00
parent 46e85324df
commit 2b5780499c
4 changed files with 58 additions and 43 deletions

View file

@ -1,6 +1,5 @@
Dockerfile Dockerfile
.dockerignore .dockerignore
examples/
.gitignore .gitignore
README.md README.md
travelynx.conf travelynx.conf

View file

@ -2,28 +2,16 @@ FROM debian:stretch-slim
ARG DEBIAN_FRONTEND=noninteractive ARG DEBIAN_FRONTEND=noninteractive
COPY cpanfile /app/cpanfile
WORKDIR /app
RUN apt-get update && apt-get install --no-install-recommends -y \ RUN apt-get update && apt-get install --no-install-recommends -y \
cpanminus \ cpanminus \
build-essential \ build-essential \
libpq-dev \ libpq-dev \
git \ git \
ssmtp \ cron \
&& cpanm -in --no-man-pages \ && cpanm -in --no-man-pages --installdeps . \
Cache::File \
Crypt::Eksblowfish \
DateTime \
DateTime::Format::Strptime \
DBI \
DBD::Pg \
Email::Sender \
Geo::Distance \
Geo::Distance::XS \
Mojolicious \
Mojolicious::Plugin::Authentication \
Travel::Status::DE::IRIS \
UUID::Tiny \
JSON \
Mojo::Pg \
&& rm -rf ~/.cpanm \ && rm -rf ~/.cpanm \
&& apt-get purge -y \ && apt-get purge -y \
build-essential \ build-essential \
@ -31,6 +19,5 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
&& apt-get autoremove -y && apt-get autoremove -y
COPY . /app COPY . /app
WORKDIR /app
CMD ["/app/docker-run.sh"] CMD ["/app/docker-run.sh"]

View file

@ -4,6 +4,17 @@ x-common-env: &common-env
TRAVELYNX_DB_NAME: travelynx TRAVELYNX_DB_NAME: travelynx
TRAVELYNX_DB_USERNAME: travelynx TRAVELYNX_DB_USERNAME: travelynx
TRAVELYNX_DB_PASSWORD: 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: services:
database: database:
image: postgres:11 image: postgres:11
@ -14,16 +25,16 @@ services:
volumes: volumes:
- ./examples/docker/postgres-init.sh:/docker-entrypoint-initdb.d/init.sh - ./examples/docker/postgres-init.sh:/docker-entrypoint-initdb.d/init.sh
travelynx: travelynx:
build: . <<: *common-config
ports: ports:
- "8000:8093" - "8000:8093"
networks:
- backend
volumes:
- ./examples/docker/travelynx.conf:/app/travelynx.conf
environment: environment:
<<: *common-env <<: *common-env
TRAVELYNX_MAIL_DISABLE: 1 cron:
TRAVELYNX_SECRET: 12345678 <<: *common-config
environment:
<<: *common-env
CRON: 1
networks: networks:
backend: backend:

View file

@ -4,6 +4,14 @@ set -eu
WAIT_DB_HOST=${TRAVELYNX_DB_HOST} WAIT_DB_HOST=${TRAVELYNX_DB_HOST}
WAIT_DB_PORT=5432 WAIT_DB_PORT=5432
check_config() {
if [ ! -f travelynx.conf ]
then
echo "The configuration file is missing"
exit 1
fi
}
wait_for_db() { wait_for_db() {
set +e set +e
for i in $(seq 1 ${WAIT_DB_TIMEOUT:-5}) for i in $(seq 1 ${WAIT_DB_TIMEOUT:-5})
@ -11,30 +19,40 @@ wait_for_db() {
(echo >/dev/tcp/${WAIT_DB_HOST}/${WAIT_DB_PORT}) &>/dev/null (echo >/dev/tcp/${WAIT_DB_HOST}/${WAIT_DB_PORT}) &>/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
break break
else
echo "Can't reach DB @ ${WAIT_DB_HOST}:${WAIT_DB_PORT}"
fi fi
sleep 1 sleep 1
done done
set -e set -e
} }
if [ ! -f travelynx.conf ] run_app() {
then if [ \
echo "The configuration file is missing" "${TRAVELYNX_MAIL_DISABLE:-0}" -eq 0 \
exit 1 -a "${TRAVELYNX_MAIL_HOST:-unset}" != "unset" \
fi ]
then
export EMAIL_SENDER_TRANSPORT=SMTP
export EMAIL_SENDER_TRANSPORT_HOST=${TRAVELYNX_MAIL_HOST}
export EMAIL_SENDER_TRANSPORT_PORT=${TRAVELYNX_MAIL_PORT:-25}
fi
if [ \ perl index.pl database migrate
"${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
exec /usr/local/bin/hypnotoad -f index.pl
}
run_cron() {
exec perl index.pl worker
}
check_config
wait_for_db wait_for_db
perl index.pl database migrate if [ "${CRON:-0}" -ne "0" ]
then
run_cron
fi
exec /usr/local/bin/hypnotoad -f index.pl run_app