Skip to content

Commit 2159d2d

Browse files
committed
installation: dev friendly docker deployment
* Add a docker-compose-dev.yml that handles development friendly docker deployment of cernopendata. (Turns off nginx-caching, sets DEBUG environment variable, etc.) Use `docker-compose -f docker-compose-dev.yml up` to run. * Update docker-compose.yml to represent a production-like deployment of opendata.cern.ch. (closes #1769) Signed-off-by: Harri Hirvonsalo <[email protected]>
1 parent 2cd69f7 commit 2159d2d

File tree

5 files changed

+218
-37
lines changed

5 files changed

+218
-37
lines changed

Dockerfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,19 @@ RUN adduser --uid 1000 invenio --gid 0 && \
7474
chown -R invenio:root /code
7575
USER 1000
7676

77+
# uWSGI configuration
7778
ARG UWSGI_WSGI_MODULE=cernopendata.wsgi:application
78-
ENV UWSGI_WSGI_MODULE ${UWSGI_WSGI_MODULE}
79+
ENV UWSGI_WSGI_MODULE ${UWSGI_WSGI_MODULE:-cernopendata.wsgi:application}
7980
ARG UWSGI_PORT=5000
80-
ENV UWSGI_PORT ${UWSGI_PORT}
81+
ENV UWSGI_PORT ${UWSGI_PORT:-5000}
8182
ARG UWSGI_PROCESSES=2
82-
ENV UWSGI_PROCESSES ${UWSGI_PROCESSES}
83+
ENV UWSGI_PROCESSES ${UWSGI_PROCESSES:-2}
8384
ARG UWSGI_THREADS=2
84-
ENV UWSGI_THREADS ${UWSGI_THREADS}
85+
ENV UWSGI_THREADS ${UWSGI_THREADS:-2}
86+
87+
# Debug off by default
88+
ARG DEBUG=False
89+
ENV DEBUG=${DEBUG:-False}
8590

8691
# Start the CERN Open Data Portal application:
8792
CMD uwsgi --module ${UWSGI_WSGI_MODULE} --http-socket 0.0.0.0:${UWSGI_PORT} --master --processes ${UWSGI_PROCESSES} --threads ${UWSGI_THREADS} --stats /tmp/stats.socket

cernopendata/config.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,23 @@
3737
from cernopendata.modules.theme.config import *
3838

3939
# Debug
40-
DEBUG = True
41-
TEMPLATES_AUTO_RELOAD = True
40+
DEBUG = os.environ.get(
41+
'DEBUG',
42+
False
43+
)
44+
TEMPLATES_AUTO_RELOAD = DEBUG
4245

4346
# Assets
4447
# ======
4548
#: Switch of assets debug.
46-
# ASSETS_DEBUG = True
49+
# ASSETS_DEBUG = DEBUG
4750
#: Switch of automatic building.
4851
# ASSETS_AUTO_BUILD = True
4952

5053

5154
# Static file
52-
# COLLECT_STORAGE = 'flask_collect.storage.file'
53-
COLLECT_STORAGE = 'flask_collect.storage.link'
55+
COLLECT_STORAGE = 'flask_collect.storage.link' \
56+
if DEBUG else 'flask_collect.storage.file'
5457

5558
# Cache
5659
CACHE_TYPE = 'redis'
@@ -378,7 +381,10 @@
378381
#: Permission factory to control the files access from the REST interface.
379382
FILES_REST_PERMISSION_FACTORY = allow_all
380383
#: Allow URI's longer than 255 chars.
381-
FILES_REST_FILE_URI_MAX_LEN = 512
384+
FILES_REST_FILE_URI_MAX_LEN = os.environ.get(
385+
"FILES_REST_FILE_URI_MAX_LEN",
386+
512
387+
)
382388

383389
# Search
384390
# ======

docker-compose-dev.yml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# This file is part of CERN Open Data Portal.
4+
# Copyright (C) 2015, 2016, 2017 CERN.
5+
#
6+
# CERN Open Data Portal is free software; you can redistribute it
7+
# and/or modify it under the terms of the GNU General Public License as
8+
# published by the Free Software Foundation; either version 2 of the
9+
# License, or (at your option) any later version.
10+
#
11+
# CERN Open Data Portal is distributed in the hope that it will be
12+
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with CERN Open Data Portal; if not, write to the
18+
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19+
# MA 02111-1307, USA.
20+
#
21+
# In applying this license, CERN does not
22+
# waive the privileges and immunities granted to it by virtue of its status
23+
# as an Intergovernmental Organization or submit itself to any jurisdiction.
24+
25+
version: "2"
26+
27+
services:
28+
29+
# Use the following in your Python code to start debugging with wdb
30+
# ```
31+
# import wdb
32+
# wdb.set_trace()
33+
# ```
34+
wdb:
35+
image: kozea/wdb-server
36+
ports:
37+
- "1984:1984"
38+
39+
web:
40+
restart: "always"
41+
image: cernopendata/static # Use this to make sure that COD3 Python-code image is built only once.
42+
depends_on:
43+
- static # Just to make sure that latest cernopendata/static -image is build before creating this container.
44+
command: "cernopendata run -h 0.0.0.0" # In case one needs to test/work with uWSGI comment out this.
45+
environment:
46+
- DEBUG=True
47+
- WDB_SOCKET_SERVER=wdb
48+
- WDB_NO_BROWSER_AUTO_OPEN=True
49+
- APP_SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://cernopendata:dbpass123@postgresql:5432/cernopendata
50+
- APP_CACHE_REDIS_HOST=redis
51+
- APP_CACHE_REDIS_URL=redis://redis:6379/0
52+
- APP_ACCOUNTS_SESSION_REDIS_URL=redis://redis:6379/1
53+
- APP_BROKER_URL=amqp://guest:guest@rabbitmq:5672/ # Celery 3
54+
- APP_CELERY_BROKER_URL=amqp://guest:guest@rabbitmq:5672/ # Celery 4
55+
- APP_CELERY_RESULT_BACKEND=redis://redis:6379/2
56+
- APP_SEARCH_ELASTIC_HOSTS=elasticsearch
57+
- APP_PIDSTORE_DATACITE_TESTMODE=False
58+
- APP_PIDSTORE_DATACITE_DOI_PREFIX=10.5072
59+
- APP_PIDSTORE_DATACITE_USERNAME=CERN.OPENDATA
60+
- APP_PIDSTORE_DATACITE_PASSWORD=CHANGE_ME
61+
- APP_PIDSTORE_LANDING_BASE_URL=http://opendata.cern.ch/record/
62+
volumes:
63+
- ./cernopendata:/code/cernopendata
64+
- ./scripts:/code/scripts
65+
volumes_from:
66+
- static
67+
links:
68+
- postgresql
69+
- redis
70+
- elasticsearch
71+
- rabbitmq
72+
- wdb
73+
ports:
74+
- "5000:5000"
75+
76+
worker:
77+
image: cernopendata/static # Use this to make sure that COD3 Python-code image is built only once.
78+
depends_on:
79+
- static # Just to make sure that latest cernopendata/static -image is build before creating this container.
80+
restart: "always"
81+
command: "celery worker -A cernopendata.celery --loglevel=INFO"
82+
environment:
83+
- DEBUG=True
84+
- WDB_SOCKET_SERVER=wdb
85+
- WDB_NO_BROWSER_AUTO_OPEN=True
86+
- APP_SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://cernopendata:dbpass123@postgresql:5432/cernopendata
87+
- APP_CACHE_REDIS_HOST=redis
88+
- APP_CACHE_REDIS_URL=redis://redis:6379/0
89+
- APP_ACCOUNTS_SESSION_REDIS_URL=redis://redis:6379/1
90+
- APP_BROKER_URL=amqp://guest:guest@rabbitmq:5672/ # Celery 3
91+
- APP_CELERY_BROKER_URL=amqp://guest:guest@rabbitmq:5672/ # Celery 4
92+
- APP_CELERY_RESULT_BACKEND=redis://redis:6379/2
93+
- APP_SEARCH_ELASTIC_HOSTS=elasticsearch
94+
volumes:
95+
- ./cernopendata:/code/cernopendata
96+
- ./scripts:/code/scripts
97+
volumes_from:
98+
- static
99+
links:
100+
- postgresql
101+
- redis
102+
- elasticsearch
103+
- rabbitmq
104+
- wdb
105+
106+
postgresql:
107+
restart: "always"
108+
image: postgres
109+
environment:
110+
- POSTGRES_USER=cernopendata
111+
- POSTGRES_DB=cernopendata
112+
- POSTGRES_PASSWORD=dbpass123
113+
ports:
114+
- "5432:5432"
115+
116+
redis:
117+
restart: "always"
118+
image: redis
119+
ports:
120+
- "6379:6379"
121+
122+
elasticsearch:
123+
restart: "always"
124+
image: elasticsearch:5
125+
environment:
126+
- bootstrap.memory_lock=true
127+
# set to reasonable values on production
128+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
129+
ports:
130+
- "9200:9200"
131+
- "9300:9300"
132+
133+
rabbitmq:
134+
restart: "always"
135+
image: rabbitmq
136+
ports:
137+
- "4369:4369"
138+
- "5672:5672"
139+
140+
nginx:
141+
restart: "always"
142+
build: ./nginx
143+
image: cernopendata/nginx
144+
ports:
145+
- "80:80"
146+
volumes:
147+
- ./cernopendata:/code/cernopendata
148+
- ./scripts:/code/scripts
149+
volumes_from:
150+
- static
151+
links:
152+
- web
153+
154+
static:
155+
restart: "no"
156+
command: "echo 'Static running...'"
157+
build:
158+
context: .
159+
image: cernopendata/static
160+
volumes:
161+
- /usr/local/var/cernopendata/var/cernopendata-instance/static
162+
user: invenio

docker-compose.yml

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,16 @@ version: "2"
2727
services:
2828
web:
2929
restart: "always"
30-
build: .
30+
build:
31+
context: .
32+
image: cernopendata/web
33+
depends_on:
34+
- elasticsearch
35+
- postgresql
36+
- rabbitmq
37+
- redis
3138
environment:
39+
- DEBUG=False
3240
- APP_SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://cernopendata:dbpass123@postgresql:5432/cernopendata
3341
- APP_CACHE_REDIS_HOST=redis
3442
- APP_CACHE_REDIS_URL=redis://redis:6379/0
@@ -42,26 +50,28 @@ services:
4250
- APP_PIDSTORE_DATACITE_USERNAME=CERN.OPENDATA
4351
- APP_PIDSTORE_DATACITE_PASSWORD=CHANGE_ME
4452
- APP_PIDSTORE_LANDING_BASE_URL=http://opendata.cern.ch/record/
45-
- APP_FILES_REST_FILE_URI_MAX_LEN=512 # Allow URI's longer than 255 chars.
46-
- APP_COLLECT_STORAGE=flask_collect.storage.file
4753
volumes:
48-
- "./cernopendata:/code/cernopendata"
49-
- "./scripts:/code/scripts"
50-
volumes_from:
51-
- static
54+
- web_data:/usr/local/var/cernopendata/var/cernopendata-instance/static
5255
links:
5356
- postgresql
5457
- redis
5558
- elasticsearch
5659
- rabbitmq
5760
ports:
58-
- "5000:5000"
61+
- "5000"
5962

6063
worker:
61-
build: .
64+
image: cernopendata/web # Use this to make sure that COD3 Python-code image is built only once.
65+
depends_on:
66+
- elasticsearch
67+
- postgresql
68+
- rabbitmq
69+
- redis
70+
- web # Added to make sure that cernopendata/web -image is build before starting this one.
6271
restart: "always"
6372
command: "celery worker -A cernopendata.celery --loglevel=INFO"
6473
environment:
74+
- DEBUG=False
6575
- APP_SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://cernopendata:dbpass123@postgresql:5432/cernopendata
6676
- APP_CACHE_REDIS_HOST=redis
6777
- APP_CACHE_REDIS_URL=redis://redis:6379/0
@@ -71,10 +81,7 @@ services:
7181
- APP_CELERY_RESULT_BACKEND=redis://redis:6379/2
7282
- APP_SEARCH_ELASTIC_HOSTS=elasticsearch
7383
volumes:
74-
- "./cernopendata:/code/cernopendata"
75-
- "./scripts:/code/scripts"
76-
volumes_from:
77-
- static
84+
- web_data:/usr/local/var/cernopendata/var/cernopendata-instance/static
7885
links:
7986
- postgresql
8087
- redis
@@ -90,6 +97,8 @@ services:
9097
- POSTGRES_PASSWORD=dbpass123
9198
ports:
9299
- "5432"
100+
volumes:
101+
- postgresql_data:/var/lib/postgresql/data
93102

94103
redis:
95104
restart: "always"
@@ -104,35 +113,33 @@ services:
104113
- bootstrap.memory_lock=true
105114
# set to reasonable values on production
106115
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
116+
volumes:
117+
- elasticsearch_data:/usr/share/elasticsearch/data/elasticsearch
107118
ports:
108-
- "9200:9200"
109-
- "9300:9300"
119+
- "9200"
120+
- "9300"
110121

111122
rabbitmq:
112123
restart: "always"
113124
image: rabbitmq
125+
depends_on:
126+
- redis
114127
ports:
115128
- "4369"
116129
- "5672"
117130

118131
nginx:
119132
restart: "always"
120133
build: ./nginx
134+
image: cernopendata/nginx
121135
ports:
122136
- "80:80"
123137
volumes:
124-
- "./cernopendata:/code/cernopendata"
125-
- "./scripts:/code/scripts"
126-
depends_on:
127-
- static
128-
volumes_from:
129-
- static
138+
- web_data:/usr/local/var/cernopendata/var/cernopendata-instance/static
130139
links:
131140
- web
132141

133-
static:
134-
restart: "no"
135-
build: .
136-
volumes:
137-
- /usr/local/var/cernopendata/var/cernopendata-instance/static
138-
user: invenio
142+
volumes:
143+
web_data:
144+
postgresql_data:
145+
elasticsearch_data:

nginx/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# as an Intergovernmental Organization or submit itself to any jurisdiction.
2424

2525
FROM nginx:perl
26+
2627
RUN rm /etc/nginx/conf.d/default.conf
2728
ADD cernopendata.conf /etc/nginx/conf.d/
2829

0 commit comments

Comments
 (0)