Skip to content

Commit 74aea07

Browse files
Use data directory for media files if exists.
1 parent 19e1311 commit 74aea07

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

.s2i/action_hooks/deploy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ echo " -----> Current working directory."
2020

2121
pwd
2222

23+
# If necessaary create the media directory if persistent volume being used.
24+
25+
if [ -d /opt/app-root/data ]; then
26+
if [ ! -d /opt/app-root/data/media/images ]; then
27+
echo " -----> Creating directory for uploaded image files."
28+
29+
mkdir -p /opt/app-root/data/media/images
30+
fi
31+
fi
32+
2333
# Run the application specific deploy steps for this project. If an
2434
# external database is being used, only perform the database migration
2535
# and do not run full setup. When external database is used the setup to

katacoda/settings.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
1717
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1818

19+
# If persistent volume mounted, use it for database and media.
20+
if os.path.isdir('/opt/app-root/data'):
21+
DATA_DIR = '/opt/app-root/data'
22+
else:
23+
DATA_DIR = BASE_DIR
1924

2025
# Quick-start development settings - unsuitable for production
2126
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
@@ -122,15 +127,10 @@ def database_url():
122127
}
123128

124129
else:
125-
if os.path.isdir('/opt/app-root/data'):
126-
DATABASE_DIR = '/opt/app-root/data'
127-
else:
128-
DATABASE_DIR = BASE_DIR
129-
130130
DATABASES = {
131131
'default': {
132132
'ENGINE': 'django.db.backends.sqlite3',
133-
'NAME': os.path.join(DATABASE_DIR, 'db.sqlite3'),
133+
'NAME': os.path.join(DATA_DIR, 'db.sqlite3'),
134134
}
135135
}
136136

@@ -175,7 +175,7 @@ def database_url():
175175
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
176176

177177
MEDIA_URL = '/media/'
178-
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
178+
MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
179179

180180
LOGGING = {
181181
'version': 1,

0 commit comments

Comments
 (0)