Add a postgres database container.
- Set environemnt variables for Postgresql database in the compose file - Set environment variables for uwsgi in the compose file - Check if the postgresql container is up and accepting connections before running any actual services.
This commit is contained in:
@@ -4,7 +4,9 @@ MAINTAINER Abhilash Raj
|
||||
|
||||
# Install the latest master branch of the mailman directly
|
||||
# from the Gitlab.
|
||||
RUN pip install git+https://gitlab.com/mailman/mailman.git
|
||||
RUN apt-get update && apt-get install -y postgresql-client \
|
||||
&& pip install git+https://gitlab.com/mailman/mailman.git \
|
||||
psycopg2
|
||||
|
||||
ADD assets/run.sh /opt/run.sh
|
||||
|
||||
@@ -17,4 +19,4 @@ WORKDIR /opt/mailman
|
||||
|
||||
EXPOSE 8001
|
||||
|
||||
CMD /opt/run.sh
|
||||
CMD ["/opt/run.sh"]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#! /bin/bash
|
||||
set -e
|
||||
|
||||
# Check if the configuration file is present.
|
||||
if [[ ! -e /opt/mailman/mailman.cfg ]]; then
|
||||
@@ -6,6 +7,30 @@ if [[ ! -e /opt/mailman/mailman.cfg ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -e /opt/mailman/mailman-hyperkitty.cfg ]]; then
|
||||
echo "/opt/mailman/mailman-hyperkitty.cfg configuration file not found..."
|
||||
echo "Hyperkitty will not be enabled or will not work properly..."
|
||||
fi
|
||||
|
||||
# Check if the master lock exists for the mailman.
|
||||
# It means that that either some other mailman process is running or
|
||||
# the last time mailman did not exit clean.
|
||||
if [[ -e /opt/mailman/core/var/locks/master.lck ]]; then
|
||||
echo "The mailman's master lock file still exists at /opt/mailman/core/var/locks/master.lck"
|
||||
echo "Please remove the lock file before trying to run this container again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the database is available yet. Do not start the container before the
|
||||
# postgresql boots up.
|
||||
until psql $DATABASE_URL -c '\l'; do
|
||||
>&2 echo "Postgres is unavailable - sleeping"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
>&2 echo "Postgres is up - continuing"
|
||||
|
||||
|
||||
# Run mailman using the pidproxy command which spawns off mailman
|
||||
# and forwards any signal you send it to the master runner in mailman.
|
||||
/opt/pidproxy.py /opt/mailman/var/master.pid mailman -C /opt/mailman/mailman.cfg start --force
|
||||
|
||||
@@ -1,22 +1,47 @@
|
||||
version: '2'
|
||||
|
||||
services:
|
||||
mailman-core:
|
||||
build:
|
||||
context: ./core
|
||||
image: mailman-core:latest
|
||||
image: maxking/mailman-core:latest
|
||||
container_name: mailman-core
|
||||
volumes:
|
||||
- /opt/mailman/core:/opt/mailman/
|
||||
links:
|
||||
- database:database
|
||||
depends_on:
|
||||
- database
|
||||
environment:
|
||||
- DATABASE_URL=postgres://mailman:mailmanpass@database/mailmandb
|
||||
|
||||
mailman-web:
|
||||
build:
|
||||
context: ./web
|
||||
image: mailman-web:latest
|
||||
image: maxking/mailman-web:latest
|
||||
container_name: mailman-web
|
||||
ports:
|
||||
- "8000:8000"
|
||||
depends_on:
|
||||
- mailman-core
|
||||
- database
|
||||
links:
|
||||
- mailman-core:mailman-core
|
||||
- database:database
|
||||
volumes:
|
||||
- /opt/mailman/web:/opt/mailman-web-data
|
||||
environment:
|
||||
- UWSGI_WSGI_FILE=wsgi.py
|
||||
- UWSGI_HTTP=:8000
|
||||
- UWSGI_WORKERS=2
|
||||
- UWSGI_THREADS=4
|
||||
- DATABASE_URL=postgres://mailman:mailmanpass@database/mailmandb
|
||||
|
||||
database:
|
||||
environment:
|
||||
POSTGRES_DB: mailmandb
|
||||
POSTGRES_USER: mailman
|
||||
POSTGRES_PASSWORD: mailmanpass
|
||||
restart: always
|
||||
image: postgres:9.6
|
||||
volumes:
|
||||
- /opt/mailman/database:/var/lib/postgresql/data
|
||||
|
||||
@@ -5,6 +5,7 @@ MAINTAINER Abhilash Raj
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y ruby-sass \
|
||||
git \
|
||||
postgresql-client \
|
||||
&& python -m pip install git+https://gitlab.com/mailman/mailmanclient.git \
|
||||
git+https://gitlab.com/mailman/postorius.git \
|
||||
git+https://gitlab.com/mailman/django-mailman3.git \
|
||||
@@ -15,21 +16,13 @@ RUN apt-get update \
|
||||
|
||||
ADD mailman-web /opt/mailman-web
|
||||
|
||||
ADD assets/run.sh /opt/run.sh
|
||||
|
||||
WORKDIR /opt/mailman-web
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
# ENV DJANGO_SETTINGS_MODULE=mailman-web.settings
|
||||
|
||||
ENV UWSGI_WSGI_FILE=wsgi.py UWSGI_HTTP=:8000 UWSGI_WORKERS=2 \
|
||||
UWSGI_THREADS=4
|
||||
|
||||
CMD python manage.py collectstatic --noinput \
|
||||
&& python manage.py migrate \
|
||||
&& uwsgi --http-auto-chunked --http-keepalive
|
||||
|
||||
#ADD assets/run.sh /opt/run.sh
|
||||
|
||||
#ENTRYPOINT /opt/run.sh
|
||||
|
||||
# CMD ["uwsgi", "--http-auto-chunked", "--http-keepalive"]
|
||||
CMD ["/opt/run.sh"]
|
||||
|
||||
31
web/assets/run.sh
Executable file
31
web/assets/run.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#! /bin/bash
|
||||
set -e
|
||||
|
||||
# Check if the database is available yet. Do not start the container before the
|
||||
# postgresql boots up.
|
||||
until psql $DATABASE_URL -c '\l'; do
|
||||
>&2 echo "Postgres is unavailable - sleeping"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
>&2 echo "Postgres is up - continuing"
|
||||
|
||||
# Check if the settings file is available and can be imported.
|
||||
|
||||
|
||||
# Check if we are in the correct directory before running commands.
|
||||
if [[ ! $(pwd) == '/opt/mailman-web' ]]; then
|
||||
echo "Running in the wrong directory...switching to /opt/mailman-web"
|
||||
cd /opt/mailman-web
|
||||
fi
|
||||
|
||||
|
||||
# Collect static for the django installation.
|
||||
python manage.py collectstatic --noinput
|
||||
|
||||
# Migrate all the data to the database if this is a new installation, otherwise
|
||||
# this command will upgrade the database.
|
||||
python manage.py migrate
|
||||
|
||||
# Run the web server.
|
||||
uwsgi --http-auto-chunked --http-keepalive
|
||||
Reference in New Issue
Block a user