Self hosted FLOSS fitness/workout, nutrition and weight tracker
First draft of a deployment setting with docker
Roland Geider66ae26666708
diff --git a/extras/docker/production/README b/extras/docker/production/READMEnew file mode 100644index 000000000..a4ecd765e--- /dev/null+++ b/extras/docker/production/README@@ -0,0 +1 @@+http://capside.com/labs/deploying-full-django-stack-with-docker-compose/diff --git a/extras/docker/production/application/Dockerfile b/extras/docker/production/application/Dockerfilenew file mode 100644index 000000000..e34919e53--- /dev/null+++ b/extras/docker/production/application/Dockerfile@@ -0,0 +1,89 @@+#+# Docker image for wger development+#+# Please consult the documentation for usage+# docker build -t wger/devel .+# docker run -ti --name wger.devel --publish 8000:8000 wger/devel+# (in docker) source ~/venv/bin/activate+# (in docker) python manage.py runserver 0.0.0.0:8000+#+#+++FROM wger/base++MAINTAINER Roland Geider <[email protected]>+EXPOSE 8000++# Set locale to UTF8, otherwise problems with the encoding can occur, e.g.+# when using the invoke/wger commands and bower+RUN locale-gen en_US.UTF-8+ENV LANG en_US.UTF-8+ENV LANGUAGE en_US:en+ENV LC_ALL en_US.UTF-8+++# Install dependencies+RUN apt-get install -y vim tmux sqlite3 python3-pip #python3-setuptools++# Set up the application+RUN git clone https://github.com/wger-project/wger.git /home/wger/src++WORKDIR /home/wger/src+RUN pip3 install --upgrade pip \+ && pip3 install -r requirements_devel.txt \+ && pip3 install gunicorn redis django_redis psycopg2 \+ && python3 setup.py develop \+ && chown -R wger:wger .++USER wger+RUN wger create_settings \+ --settings-path /home/wger/src/settings.py \+ --database-path /home/wger/db/database.sqlite \+ && wger bootstrap \+ --settings-path /home/wger/src/settings.py \+ --no-start-server++# Install node modules for JS linting and download the exercise images+#+# Note: it seems there are problems with node and docker, so it's necessary+# to delete the node_modules folder and install everything again+# -> https://github.com/npm/npm/issues/9863+# -> https://github.com/npm/npm/issues/13306+RUN cd wger \+ && rm -r node_modules \+ && npm install bower \+ && npm install \+ && cd .. \+ && mkdir ~/media \+ && sed -i "/^MEDIA_ROOT/c\MEDIA_ROOT='\/home\/wger\/media'" settings.py \+ && echo STATIC_ROOT=\'/home/wger/static\' >> settings.py \+ && echo CACHES = { >> settings.py \+ && echo " 'default': {" >> settings.py \+ && echo " 'BACKEND': 'django_redis.cache.RedisCache'," >> settings.py \+ && echo " 'TIMEOUT': '48000'," >> settings.py \+ && echo " 'LOCATION': 'redis://redis:6379/0'," >> settings.py \+ && echo " 'OPTIONS': {" >> settings.py \+ && echo " 'CLIENT_CLASS': 'django_redis.client.DefaultClient'" >> settings.py \+ && echo " }" >> settings.py \+ && echo " }" >> settings.py \+ && echo " }" >> settings.py \+ && python3 manage.py collectstatic --noinput+#+#CACHES = {+# "default": {+# "BACKEND": "django_redis.cache.RedisCache",+# "LOCATION": "redis://redis:6379/0",+# "OPTIONS": {+# "CLIENT_CLASS": "django_redis.client.DefaultClient",+# }+# }+#}+++# && python manage.py download-exercise-images+++#ENTRYPOINT ["python3"]+CMD ["gunicorn", "wger.wsgi:application", "-w", "2", "-b", ":8000"]+#CMD ["manage.py", "runserver", "0.0.0.0:8000"]diff --git a/extras/docker/production/docker-compose.yml b/extras/docker/production/docker-compose.ymlnew file mode 100644index 000000000..459ab14da--- /dev/null+++ b/extras/docker/production/docker-compose.yml@@ -0,0 +1,57 @@+version: '2'+services:+ ### Application+ web:+ restart: always+ build: ./application/+ expose:+ - "8000"+ links:+ - postgres:postgres+ - redis:redis+ env_file: env+ volumes:+ - /home/wger/static+ depends_on:+ - postgres+ - redis++ ### Reverse proxy+ nginx:+ restart: always+ build: ./nginx/+ ports:+ - "80:80"+ volumes_from:+ - web+ links:+ - web:web++ ### Database+ postgres:+ restart: always+ image: postgres:latest+ volumes_from:+ - data+ volumes:+ - ./postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d+ - ./backups/postgresql:/backup+ env_file:+ - env+ expose:+ - "5432"++ ### Cache+ redis:+ restart: always+ image: redis:latest+ expose:+ - "6379"++ ### Data volume+ data:+ restart: always+ image: alpine+ volumes:+ - /var/lib/postgresql+ command: "true"diff --git a/extras/docker/production/env b/extras/docker/production/envnew file mode 100644index 000000000..c00f63fc0--- /dev/null+++ b/extras/docker/production/env@@ -0,0 +1,5 @@+DB_NAME=myproject_web+DB_USER=myproject_web+DB_PASS=shoov3Phezaimahsh7eb2Tii4ohkah8k+DB_SERVICE=postgres+DB_PORT=5432diff --git a/extras/docker/production/nginx/Dockerfile b/extras/docker/production/nginx/Dockerfilenew file mode 100644index 000000000..db9381f86--- /dev/null+++ b/extras/docker/production/nginx/Dockerfile@@ -0,0 +1,4 @@+FROM tutum/nginx++RUN rm /etc/nginx/sites-enabled/default+ADD sites-enabled/ /etc/nginx/sites-enableddiff --git a/extras/docker/production/nginx/sites-enabled/wger b/extras/docker/production/nginx/sites-enabled/wgernew file mode 100644index 000000000..543f80e88--- /dev/null+++ b/extras/docker/production/nginx/sites-enabled/wger@@ -0,0 +1,18 @@+server {++ listen 80;+ server_name not.configured.example.com;+ charset utf-8;++ location /static {+ alias /home/wger/static/;+ }++ location / {+ proxy_pass http://web:8000;+ proxy_set_header Host $host;+ proxy_set_header X-Real-IP $remote_addr;+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;+ }++}diff --git a/extras/docker/production/postgres/docker-entrypoint-initdb.d/wger_project.sh b/extras/docker/production/postgres/docker-entrypoint-initdb.d/wger_project.shnew file mode 100644index 000000000..5110a2526--- /dev/null+++ b/extras/docker/production/postgres/docker-entrypoint-initdb.d/wger_project.sh@@ -0,0 +1,2 @@+psql -U postgres -c "CREATE USER $DB_USER PASSWORD '$DB_PASS'"+psql -U postgres -c "CREATE DATABASE $DB_NAME OWNER $DB_USER"