Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Optionally use S3 for static assets

Scott Peshak073561977bc7
diff --git a/extras/docker/apache/Dockerfile b/extras/docker/apache/Dockerfile
index 423ce954a..22316cd7a 100644
--- a/extras/docker/apache/Dockerfile
+++ b/extras/docker/apache/Dockerfile
@@ -43,9 +43,10 @@ RUN a2dissite 000-default.conf \
# Configure cron
COPY ${DOCKER_DIR}/crontab /etc/cron.d/wger
COPY ${DOCKER_DIR}/venvwrapper /home/wger/venvwrapper
+COPY ${DOCKER_DIR}/entrypoint.sh /home/wger/entrypoint.sh
RUN chmod 0644 /etc/cron.d/wger \
- && chmod +x /home/wger/venvwrapper \
+ && chmod +x /home/wger/venvwrapper /home/wger/entrypoint.sh \
&& touch /var/log/cron.log
COPY --chown=wger:www-data . /home/wger/src
@@ -84,5 +85,4 @@ RUN chmod o+w -R ~/db/ \
USER root
-ENTRYPOINT ["/usr/sbin/apache2ctl"]
-CMD ["-D", "FOREGROUND"]
+ENTRYPOINT ["/home/wger/entrypoint.sh"]
diff --git a/extras/docker/apache/entrypoint.sh b/extras/docker/apache/entrypoint.sh
new file mode 100755
index 000000000..537d08ff7
--- /dev/null
+++ b/extras/docker/apache/entrypoint.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ "${USE_S3}" = "TRUE" ]; then
+ python manage.py collectstatic --no-input
+fi
+
+/usr/sbin/apache2ctl -D FOREGROUND
diff --git a/requirements.txt b/requirements.txt
index 7cb06b3a0..8b035ed82 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -11,6 +11,7 @@ Django>=1.11,<2.0
django_compressor==2.2
django_extensions>=2.1
django-sorted-m2m>=2.0
+django-storages>=1.7
easy-thumbnails==2.6
icalendar==4.0.3
invoke==0.17
@@ -22,6 +23,7 @@ requests
setuptools>=18.5
sphinx
psycopg2
+boto3
# Production
psycopg2
diff --git a/wger/settings_global.py b/wger/settings_global.py
index c7dcecf3b..30addc744 100644
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@ -45,6 +45,7 @@ INSTALLED_APPS = (
'django.contrib.sites',
'django.contrib.staticfiles',
'django_extensions',
+ 'storages',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
@@ -305,12 +306,30 @@ THUMBNAIL_ALIASES = {
},
}
+STATIC_ROOT = ''
+USE_S3 = os.getenv('USE_S3') == 'TRUE'
+
+if USE_S3:
+ # aws settings
+ AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
+ AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
+ AWS_STORAGE_BUCKET_NAME = os.getenv('AWS_STORAGE_BUCKET_NAME')
+ AWS_DEFAULT_ACL = 'public-read'
+ AWS_S3_CUSTOM_DOMAIN = os.getenv('WGER_CDN_DOMAIN')
+ AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
+ # s3 static settings
+ AWS_LOCATION = 'static'
+ STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
+ STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
+ COMPRESS_URL = STATIC_URL
+ COMPRESS_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
+else:
+ STATIC_URL = '/static/'
+
#
# Django compressor
#
-STATIC_ROOT = ''
-STATIC_URL = '/static/'
# The default is not DEBUG, override if needed
# COMPRESS_ENABLED = True