Skip to content

Commit 1fdc811

Browse files
committed
env: cleanup and reorder app settings and env varaibles
1 parent 01351e1 commit 1fdc811

9 files changed

Lines changed: 81 additions & 97 deletions

File tree

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ RUN /bin/bash /srv/app/bin/setup_plugins.sh
5252
# Install Vamp plugins
5353
RUN /bin/bash /srv/app/bin/install_vamp_plugins.sh
5454

55-
# Install bower
56-
#RUN npm install -g bower
57-
5855
# Install timeside
5956
WORKDIR /srv/lib/timeside
6057
RUN pip3 install -U setuptools pip numpy
@@ -64,5 +61,9 @@ RUN pip3 install -r requirements.txt
6461
COPY . /srv/lib/timeside/
6562
RUN pip3 install -e .
6663

64+
# Install npm modules
65+
#RUN npm install -g bower
66+
RUN npm install --prefix /srv/app
67+
6768
WORKDIR /srv/app
6869

app/bin/app.sh

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
SCRIPT_DIR="$(dirname "$0")"
44
source "$SCRIPT_DIR/app_base.sh"
55

6-
# fix log access
7-
mkdir -p '/var/log/app/'
8-
chown -R $uid:$gid '/var/log/app/'
9-
106
# waiting for db
117
su $uid -g $gid -s /bin/bash -c "python3 $manage wait-for-db"
128

@@ -22,17 +18,14 @@ su $uid -g $gid -s /bin/bash -c "python3 $manage timeside-analysis-subprocessor-
2218
# python $manage update_index --workers $processes &
2319
# fi
2420

25-
# NPM modules install
26-
npm install --prefix /srv/app
27-
2821
# app start
2922
if [ "$1" = "--runserver" ]
3023
then
3124
su $uid -g $gid -s /bin/bash -c "python3 $manage runserver 0.0.0.0:8000"
3225
else
3326

3427
# fix static access
35-
chown -R $uid:$gid '/srv/static'
28+
chown -R $uid:$gid $static
3629

3730
# collect static files
3831
su $uid -g $gid -s /bin/bash -c "python3 $manage collectstatic --noinput"
@@ -42,5 +35,5 @@ else
4235

4336
uwsgi --socket :$port --wsgi-file $wsgi --chdir $app --master \
4437
--processes $processes --threads $threads \
45-
--uid $uid --gid $gid --logto $log --touch-reload $wsgi
38+
--uid $uid --gid $gid --logto $app_log_file --touch-reload $wsgi
4639
fi

app/bin/app_base.sh

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,49 @@
11
#!/bin/bash
22

3-
# paths
4-
app='/srv/app'
5-
src='/srv/src'
6-
manage=$app'/manage.py'
7-
wsgi=$app'/wsgi.py'
8-
static='/srv/static/'
9-
media='/srv/media/'
10-
log='/var/log/uwsgi/app.log'
11-
worker_logfile='/var/log/celery/worker.log'
12-
loglevel='DEBUG'
13-
143
# uwsgi params
154
port=8000
165
processes=4
176
threads=4
187
autoreload=3
19-
# uwsgi and celery params
8+
9+
# uid / gid params for app and worker
2010
uid='www-data'
2111
gid='www-data'
2212

23-
# install more apps
24-
# pip install -U django-cors-headers
25-
# ...
13+
# paths
14+
app='/srv/app'
15+
src='/srv/src'
16+
static='/srv/static/'
17+
media='/srv/media/'
18+
log='/var/log/app'
19+
20+
# entrypoints
21+
manage=$app'/manage.py'
22+
wsgi=$app'/wsgi.py'
23+
24+
# levels
25+
log_level='DEBUG'
26+
27+
# log paths
28+
app_log_dir='/var/log/app'
29+
app_log_file=$app_log_dir'/app.log'
30+
worker_log_dir='/var/log/celery'
31+
worker_log_file=$worker_log_dir'/worker.log'
32+
33+
# check and fix dirs
34+
mkdir -p $app_log_dir
35+
chown -R $uid:$gid $app_log_dir
36+
mkdir -p $worker_log_dir
37+
chown -R $uid:$gid $worker_log_dir
2638

27-
# always take the last youtube-dl version
39+
# install the last version of those packages
2840
pip3 install -U youtube-dl
2941

3042
# Install plugins
3143
bash /srv/app/bin/setup_plugins.sh
3244

3345
# fix media access rights
34-
find $media -maxdepth 1 -path ${media}import -prune -o -type d -not -user www-data -exec chown www-data:www-data {} \;
46+
find $media -maxdepth 1 -path ${media}import -prune -o -type d -not -user $uid -exec chown $uid:$gid {} \;
3547

3648
# wait for other services
3749
# bash $app/bin/wait.sh

app/bin/worker.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,5 @@
33
SCRIPT_DIR="$(dirname "$0")"
44
source "$SCRIPT_DIR/app_base.sh"
55

6-
# fix celery log access
7-
mkdir -p '/var/log/celery/'
8-
chown -R $uid:$gid '/var/log/celery/'
9-
10-
python3 manage.py timeside-celery-worker --loglevel $loglevel --logfile $worker_logfile --uid $uid --gid $gid
6+
python3 manage.py timeside-celery-worker --loglevel $log_level --logfile $worker_log_file --uid $uid --gid $gid
117

app/settings.py

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
import os
2+
import sys
13
import environ
24

5+
from worker import app
6+
7+
8+
sys.dont_write_bytecode = True
9+
310
# set default values and casting
4-
env = environ.Env(DEBUG=(bool, False),
5-
CELERY_TASK_ALWAYS_EAGER=(bool, False),
6-
)
11+
env = environ.Env()
12+
713
# Django settings for server project.
814
DEBUG = env('DEBUG') # False if not in os.environ
9-
DEBUG=True
10-
11-
import os
12-
import sys
13-
sys.dont_write_bytecode = True
1415

1516
ADMINS = (
1617
('Guillaume Pellerin', 'guillaume.pellerin@ircam.fr'),
@@ -20,9 +21,9 @@
2021

2122
MANAGERS = ADMINS
2223

23-
# Full filesystem path to the project.
24-
# project_root = environ.Path(__file__) - 1
25-
# data_root = project_root - 2
24+
EMAIL_HOST = env('EMAIL_HOST')
25+
EMAIL_SUBJECT_PREFIX = env('EMAIL_SUBJECT_PREFIX')
26+
DEFAULT_FROM_EMAIL = env('DEFAULT_FROM_EMAIL')
2627

2728
DATABASES = {
2829
'default': {
@@ -66,6 +67,10 @@
6667
# If you set this to False, Django will not use timezone-aware datetimes.
6768
USE_TZ = True
6869

70+
71+
# App path
72+
APP_PATH = '/srv/app/'
73+
6974
# Absolute filesystem path to the directory that will hold user-uploaded files.
7075
# Example: "/home/media/media.lawrence.com/media/"
7176
MEDIA_ROOT = '/srv/media/'
@@ -85,8 +90,11 @@
8590
# Example: "http://media.lawrence.com/static/"
8691
STATIC_URL = '/static/'
8792

93+
ROOT_URLCONF = 'urls'
94+
8895
# django-npm
89-
NPM_ROOT_PATH = '/srv/app/'
96+
NPM_ROOT_PATH = APP_PATH
97+
9098

9199
# Additional locations of static files
92100
STATICFILES_DIRS = (
@@ -95,6 +103,9 @@
95103
# Don't forget to use absolute paths, not relative paths.
96104
)
97105

106+
# Python dotted path to the WSGI application used by Django's runserver.
107+
WSGI_APPLICATION = 'wsgi.application'
108+
98109
# List of finder classes that know how to find static files in
99110
# various locations.
100111
STATICFILES_FINDERS = (
@@ -127,6 +138,7 @@
127138
},
128139
},
129140
]
141+
130142
MIDDLEWARE = (
131143
'corsheaders.middleware.CorsMiddleware',
132144
'django.middleware.common.CommonMiddleware',
@@ -140,13 +152,6 @@
140152
'debug_toolbar.middleware.DebugToolbarMiddleware',
141153
)
142154

143-
ROOT_URLCONF = 'urls'
144-
145-
# Python dotted path to the WSGI application used by Django's runserver.
146-
WSGI_APPLICATION = 'wsgi.application'
147-
148-
149-
150155
INSTALLED_APPS = (
151156
'django.contrib.auth',
152157
'django.contrib.contenttypes',
@@ -233,19 +238,15 @@
233238
}
234239

235240
CELERY_IMPORTS = ("timeside.server.tasks",)
236-
237-
CELERY_BACKEND_URL = 'redis://redis:6379/0'
241+
CELERY_BACKEND_URL = 'redis://broker:6379/0'
238242
CELERY_BROKER_TRANSPORT = 'redis'
239-
CELERY_BROKER_URL = 'redis://redis:6379/0'
243+
CELERY_BROKER_URL = 'redis://broker:6379/0'
240244
CELERY_RESULT_BACKEND = 'django-db'
241245
CELERY_CACHE_BACKEND = 'django-cache'
242246
CELERY_TASK_SERIALIZER = "json"
243247
CELERY_ACCEPT_CONTENT = ['application/json']
244248
CELERY_TASK_ALWAYS_EAGER = env('CELERY_TASK_ALWAYS_EAGER') # If this is True, all tasks will be executed locally by blocking until the task returns.
245249

246-
247-
from worker import app
248-
249250
BOWER_COMPONENTS_ROOT = '/srv/static/'
250251
BOWER_PATH = '/usr/local/bin/bower'
251252
BOWER_INSTALLED_APPS = (
@@ -263,9 +264,10 @@
263264
CORS_ALLOW_CREDENTIALS = True
264265

265266
SESSION_COOKIE_SAMESITE = None
266-
SESSION_COOKIE_SECURE = True
267+
SESSION_COOKIE_SECURE = False if os.environ.get('DEBUG') == 'True' else True
268+
267269
CSRF_COOKIE_SAMESITE = None
268-
CSRF_COOKIE_SECURE = True
270+
CSRF_COOKIE_SECURE = False if os.environ.get('DEBUG') == 'True' else True
269271

270272
X_FRAME_OPTIONS = 'ALLOWALL'
271273
XS_SHARING_ALLOWED_METHODS = ['POST','GET','OPTIONS', 'PUT', 'DELETE']
@@ -275,11 +277,4 @@
275277
'SHOW_TOOLBAR_CALLBACK': lambda x : True
276278
}
277279

278-
279-
LOGIN_REDIRECT_URL = '/'
280-
281-
EMAIL_HOST = '134.158.33.163'
282-
EMAIL_SUBJECT_PREFIX = '[TimeSide-SANDBOX]'
283-
DEFAULT_FROM_EMAIL = 'root@cchum-kvm-telemeta-dev.in2p3.fr'
284-
285280
TIMESIDE_DEFAULT_DECODER = 'aubio_decoder'

docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ app:
5656
- ./app:/srv/app
5757
- ./timeside:/srv/lib/timeside/timeside
5858
- ./lib/plugins:/srv/lib/plugins
59-
- ./etc/apt/sources.list:/etc/apt/sources.list
6059
volumes_from:
6160
- var
6261
env_file:
@@ -67,7 +66,7 @@ app:
6766
expose:
6867
- "8000"
6968
ports:
70-
- "9070:8000"
69+
- "9030:8000"
7170

7271

7372
worker:

env/debug.env

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
# DATABASE
2-
3-
POSTGRES_PASSWORD=mysecretpassword
4-
5-
# -- DJANGO
6-
71
DEBUG=True
82

93
SECRET_KEY=ghv8us2587n97dq&w$c((o5rj_$-9#d-8j#57y_a9og8wux1h7
104

11-
# replace broker by localhost if you start your app outside docker-compose
12-
CELERY_BROKER_URL=redis://broker:6379/0
13-
145
# If this is True, all tasks will be executed locally by blocking until the task returns.
156
CELERY_TASK_ALWAYS_EAGER=False
7+
8+
# CACHE
9+
bower_storage__packages=/srv/cache/bower
10+
PIP_DOWNLOAD_CACHE=/srv/cache/pip
11+
CONDA_ENVS_PATH=/srv/cache/miniconda/envs:/opt/miniconda/envs
12+
13+
# EMAIL
14+
EMAIL_HOST = 'localhost'
15+
EMAIL_SUBJECT_PREFIX = '[TimeSide]'
16+
DEFAULT_FROM_EMAIL = 'no-reply@example.com'

env/debug.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,9 @@
2424
app:
2525
env_file:
2626
- env/debug.env
27-
volumes:
28-
- ./app:/srv/app
29-
- .:/srv/lib/timeside
30-
- ./timeside:/srv/lib/timeside/timeside
31-
- ./lib/plugins:/srv/lib/plugins
32-
- ./etc/apt/sources.list:/etc/apt/sources.list
3327
command: /bin/bash bin/app.sh --runserver
34-
ports:
35-
- 9030:8000
3628

3729
worker:
3830
env_file:
3931
- env/debug.env
40-
volumes:
41-
- ./lib:/srv/lib/plugins
42-
- ./:/srv/lib/timeside/
4332

env/prod.env

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
# DATABASE
2-
31
POSTGRES_PASSWORD=mysecretpassword
42

5-
# DJANGO
6-
73
DEBUG=False
84

95
SECRET_KEY=ghv8us2587n97dq&w$c((o5rj_$-9#d-8j#57y_a9og8wux1h7
106

11-
# replace broker by localhost if you start your app outside docker-compose
12-
CELERY_BROKER_URL=redis://broker:6379/0
13-
147
# If this is True, all tasks will be executed locally by blocking until the task returns.
158
CELERY_TASK_ALWAYS_EAGER=False
169

@@ -20,3 +13,8 @@ PYTHONWARNINGS=ignore::DeprecationWarning
2013
bower_storage__packages=/srv/cache/bower
2114
PIP_DOWNLOAD_CACHE=/srv/cache/pip
2215
CONDA_ENVS_PATH=/srv/cache/miniconda/envs:/opt/miniconda/envs
16+
17+
# EMAIL
18+
EMAIL_HOST = 'localhost'
19+
EMAIL_SUBJECT_PREFIX = '[TimeSide]'
20+
DEFAULT_FROM_EMAIL = 'no-reply@example.com'

0 commit comments

Comments
 (0)