Add a DockerFile (#272)

Can be used to deploy the latest version from
PyPI in a production environment or from the
master branch in a dev environment.
This commit is contained in:
0livd 2017-10-25 23:37:55 +02:00 committed by Alexis Metaireau
parent 293735eca7
commit b4961f646a
4 changed files with 93 additions and 1 deletions

View file

@ -30,6 +30,7 @@ Added
- Projects can be edited/deleted from the dashboard (#262) - Projects can be edited/deleted from the dashboard (#262)
- ACTIVATE_ADMIN_DASHBOARD setting (#262) - ACTIVATE_ADMIN_DASHBOARD setting (#262)
- Link to the dashboard in the navigation bar (#262) - Link to the dashboard in the navigation bar (#262)
- Dockerfile
Removed Removed
======= =======

34
Dockerfile Normal file
View file

@ -0,0 +1,34 @@
FROM python:3.6-alpine
RUN mkdir /ihatemoney &&\
mkdir -p /etc/ihatemoney &&\
pip install --no-cache-dir gunicorn pymysql
WORKDIR /ihatemoney
COPY . .
ARG INSTALL_FROM_PYPI="False"
RUN if [ "$INSTALL_FROM_PYPI" = True ]; then\
pip install --no-cache-dir ihatemoney ; else\
pip install --no-cache-dir -e . ; \
fi
ENV DEBUG="False" \
SQLALCHEMY_DATABASE_URI="sqlite:////database/ihatemoney.db" \
SQLALCHEMY_TRACK_MODIFICATIONS="False" \
SECRET_KEY="tralala" \
MAIL_DEFAULT_SENDER="('Budget manager', 'budget@notmyidea.org')" \
MAIL_SERVER="localhost" \
MAIL_PORT=25 \
MAIL_USE_TLS=False \
MAIL_USE_SSL=False \
MAIL_USERNAME=None \
MAIL_PASSWORD=None \
ACTIVATE_DEMO_PROJECT="True" \
ADMIN_PASSWORD="" \
ALLOW_PUBLIC_PROJECT_CREATION="True" \
ACTIVATE_ADMIN_DASHBOARD="False" \
GUNICORN_NUM_WORKERS="3"
VOLUME /database
EXPOSE 8000
CMD ["/ihatemoney/conf/confandrun.sh"]

23
conf/confandrun.sh Executable file
View file

@ -0,0 +1,23 @@
#!/bin/sh
cat <<EOF >> /etc/ihatemoney/ihatemoney.cfg
DEBUG = $DEBUG
SQLALCHEMY_DATABASE_URI = "$SQLALCHEMY_DATABASE_URI"
SQLACHEMY_DEBUG = DEBUG
SQLALCHEMY_TRACK_MODIFICATIONS = $SQLALCHEMY_TRACK_MODIFICATIONS
SECRET_KEY = "$SECRET_KEY"
MAIL_SERVER = "$MAIL_SERVER"
MAIL_PORT = $MAIL_PORT
MAIL_USE_TLS = $MAIL_USE_TLS
MAIL_USE_SSL = $MAIL_USE_SSL
MAIL_USERNAME = "$MAIL_USERNAME"
MAIL_PASSWORD = "$MAIL_PASSWORD"
MAIL_DEFAULT_SENDER = "$MAIL_DEFAULT_SENDER"
ACTIVATE_DEMO_PROJECT = $ACTIVATE_DEMO_PROJECT
ADMIN_PASSWORD = "$ADMIN_PASSWORD"
ALLOW_PUBLIC_PROJECT_CREATION = $ALLOW_PUBLIC_PROJECT_CREATION
ACTIVATE_ADMIN_DASHBOARD = $ACTIVATE_ADMIN_DASHBOARD
EOF
gunicorn ihatemoney.wsgi:application \
-b 0.0.0.0:8000 \
--log-syslog \
-w "$GUNICORN_NUM_WORKERS"

View file

@ -56,7 +56,7 @@ Deploy it
========= =========
Now, if you want to deploy it on your own server, you have many options. Now, if you want to deploy it on your own server, you have many options.
Two of them are documented at the moment. Three of them are documented at the moment.
*Of course, if you want to contribute another configuration, feel free to open a *Of course, if you want to contribute another configuration, feel free to open a
pull-request against this repository!* pull-request against this repository!*
@ -113,6 +113,40 @@ With Nginx, Gunicorn and Supervisord
.. [#nginx-vhosts] typically, */etc/nginx/conf.d/* or .. [#nginx-vhosts] typically, */etc/nginx/conf.d/* or
*/etc/nginx/sites-available*, depending on your distribution. */etc/nginx/sites-available*, depending on your distribution.
With Docker
-----------
Build the image::
docker build -t ihatemoney --build-arg INSTALL_FROM_PYPI=True .
Start a daemonized Ihatemoney container::
docker run -d -p 8000:8000 ihatemoney
Ihatemoney is now available on http://localhost:8000.
All Ihatemoney settings can be passed with ``-e`` parameters
e.g. with a secure ``SECRET_KEY``, an external mail server and an external database::
docker run -d -p 8000:8000 \
-e SECRET_KEY="supersecure" \
-e SQLALCHEMY_DATABASE_URI="mysql+pymysql://user:pass@172.17.0.5/ihm" \
-e MAIL_SERVER=smtp.gmail.com \
-e MAIL_PORT=465 \
-e MAIL_USERNAME=your-email@gmail.com \
-e MAIL_PASSWORD=your-password \
-e MAIL_USE_SSL=True \
ihatemoney
A volume can also be specified to persist the default database file::
docker run -d -p 8000:8000 -v /host/path/to/database:/database ihatemoney
The following gunicorn parameters are also available::
GUNICORN_NUM_WORKERS (default: 3)
Configuration Configuration
============= =============