Skip to content

Commit

Permalink
Move Django static files from host directory to container. (#75)
Browse files Browse the repository at this point in the history
Set file permissions explicitly when ./manage.py collectstatic runs.
  • Loading branch information
normangilmore authored Mar 13, 2017
1 parent 3d6a6b2 commit 56afeb8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ __pycache__/
/thresher/bin/

# django artifacts
staticfiles
/staticfiles/
_postgres_data

# gunicorn artifacts
Expand Down
6 changes: 4 additions & 2 deletions init_django.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
docker-compose run thresher_api sh /home/thresher/docker/thresher_api/init_django.sh
docker-compose run thresher_api sh /home/thresher/docker/thresher_api/init_users.sh
# Must use 'exec' since ./manage.py collectstatic modifies the container
docker-compose exec thresher_api sh /home/thresher/docker/thresher_api/init_django.sh
# DB updates can use either 'run' or 'exec'
docker-compose exec thresher_api sh /home/thresher/docker/thresher_api/init_users.sh
3 changes: 2 additions & 1 deletion init_thresher.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/bash
docker-compose run thresher_api sh /home/thresher/docker/thresher_api/init_all.sh
# Must use 'exec' since ./manage.py collectstatic modifies the container
docker-compose exec thresher_api sh /home/thresher/docker/thresher_api/init_all.sh
3 changes: 2 additions & 1 deletion thresher_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_ROOT = 'staticfiles'
STATICFILES_STORAGE='thresher_backend.storage.TTStaticFilesStorage'
STATIC_ROOT = '/var/www/staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "vendor")
Expand Down
9 changes: 9 additions & 0 deletions thresher_backend/storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib.staticfiles import storage

# Configure the permissions used by ./manage.py collectstatic
# See https://docs.djangoproject.com/en/1.10/ref/contrib/staticfiles/
class TTStaticFilesStorage(storage.StaticFilesStorage):
def __init__(self, *args, **kwargs):
kwargs['file_permissions_mode'] = 0o644
kwargs['directory_permissions_mode'] = 0o755
super(TTStaticFilesStorage, self).__init__(*args, **kwargs)

0 comments on commit 56afeb8

Please sign in to comment.