Skip to content

Commit

Permalink
Rework how the static files are handled in the deployment. Prod-like …
Browse files Browse the repository at this point in the history
…deploys should no longer reach out to the Internet during launch.
  • Loading branch information
cuttlefish committed Nov 22, 2018
1 parent 7ebeb64 commit c95d2dc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 34 deletions.
29 changes: 11 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,35 +104,28 @@ RUN pip install --no-cache-dir -U git+git://github.com/dimka665/awesome-slugify@
# Copy in the code
COPY --chown=mapstory:mapstory mapstory ./mapstory
COPY --chown=mapstory:mapstory ./*.py ./
COPY --chown=mapstory:mapstory docker/django/run.sh $APP_PATH/docker/django/
RUN ln -s $APP_PATH/docker/django/run.sh /opt/run.sh

RUN set -ex \
&& chown -R mapstory:mapstory $STATIC_ROOT \
&& chown -R mapstory:mapstory $MEDIA_ROOT \
&& mkdir -p $APP_PATH/cover \
&& chown -R mapstory:mapstory $APP_PATH/cover

USER mapstory

WORKDIR $APP_PATH/mapstory/static
RUN set -ex \
&& yarn install \
&& bower install \
&& grunt concat \
&& grunt less:development \
&& grunt copy:development \
&& /opt/run.sh --collect-static \
&& yarn cache clean \
&& rm -rf ~/.cache/bower \
&& rm -rf /tmp/phantomjs

USER root
RUN set -ex \
&& chown -R mapstory:mapstory $STATIC_ROOT \
&& chown -R mapstory:mapstory $MEDIA_ROOT \
&& mkdir -p $APP_PATH/cover \
&& chown -R mapstory:mapstory $APP_PATH/cover

COPY --chown=mapstory:mapstory docker/django/run.sh $APP_PATH/docker/django/
RUN ln -s $APP_PATH/docker/django/run.sh /opt/run.sh

USER mapstory
WORKDIR $APP_PATH
VOLUME $STATIC_ROOT
VOLUME $MEDIA_ROOT
VOLUME $APP_PATH/cover
WORKDIR $APP_PATH
EXPOSE $DJANGO_PORT
ENTRYPOINT ["/opt/run.sh"]
CMD ["--collect-static", "--init-db", "--reindex", "--serve"]
CMD ["--init-db", "--reindex", "--serve"]
5 changes: 0 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ services:
- rabbitmq
volumes:
- mapstory_media:/var/lib/mapstory/media/
- mapstory_static:/var/lib/mapstory/static/
networks:
internal:
expose:
Expand All @@ -68,7 +67,6 @@ services:
command: --celery
volumes:
- mapstory_media:/var/lib/mapstory/media/
- mapstory_static:/var/lib/mapstory/static/
networks:
internal:
expose:
Expand All @@ -80,7 +78,6 @@ services:
entrypoint: /bin/sh -c "chown -R mapstory:mapstory /var/lib/mapstory && chmod -R a+x /var/lib/mapstory"
volumes:
- mapstory_media:/var/lib/mapstory/media/
- mapstory_static:/var/lib/mapstory/static/

geoserver:
image: quay.io/mapstory/geoserver:2.12.4-1.2
Expand Down Expand Up @@ -109,7 +106,6 @@ services:
- geoserver
volumes:
- mapstory_media:/var/lib/mapstory/media/:ro
- mapstory_static:/var/lib/mapstory/static/:ro
environment:
- NGINX_NUM_WORKERS=2
- NGINX_GZIP_COMP_LEVEL=4
Expand All @@ -129,6 +125,5 @@ networks:

volumes:
geoserver:
mapstory_static:
mapstory_media:
pgadmin:
5 changes: 3 additions & 2 deletions docker/django/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ for secret in /run/secrets/env_*; do
set +a
done


export ALLOWED_HOSTS="$PUBLIC_HOST|$ALLOWED_HOSTS"
if ! [ -z "$PUBLIC_HOST" ]; then
export ALLOWED_HOSTS="$PUBLIC_HOST|$ALLOWED_HOSTS"
fi

for i do # loop over $@

Expand Down
18 changes: 9 additions & 9 deletions mapstory/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def is_valid(v):
# General Django development settings
#
SITENAME = os.environ.get('SITE_NAME', 'MapStory')
SITEURL = "%s://%s" % (os.environ['PUBLIC_PROTOCOL'],
os.environ['PUBLIC_HOST'])
SITEURL = "%s://%s" % (os.environ.get('PUBLIC_PROTOCOL', 'https'),
os.environ.get('PUBLIC_HOST', 'ERROR'))

# Defines the directory that contains the settings file as the LOCAL_ROOT
# It is used for relative settings elsewhere.
Expand Down Expand Up @@ -231,8 +231,8 @@ def is_valid(v):
#
# Database Settings
#
DATABASE_HOST = os.environ['DATABASE_HOST']
DATABASE_PASSWORD = os.environ['DATABASE_PASSWORD']
DATABASE_HOST = os.environ.get('DATABASE_HOST', 'ERROR')
DATABASE_PASSWORD = os.environ.get('DATABASE_PASSWORD', 'ERROR')
DATABASE_PORT = '5432'

if DATABASE_PASSWORD:
Expand Down Expand Up @@ -280,9 +280,9 @@ def is_valid(v):
# Geoserver Settings
#
GEOSERVER_LOCATION = "%s://%s:%d/geoserver/" % (
os.environ['PRIVATE_PROTOCOL'], os.environ['GEOSERVER_HOST_INTERNAL'], int(os.environ['GEOSERVER_PORT_INTERNAL']))
os.environ.get('PRIVATE_PROTOCOL', 'http'), os.environ.get('GEOSERVER_HOST_INTERNAL', 'ERROR'), int(os.environ.get('GEOSERVER_PORT_INTERNAL', '8000')))
GEOSERVER_PUBLIC_LOCATION = "%s://%s/geoserver/" % (
os.environ['PUBLIC_PROTOCOL'], os.environ['PUBLIC_HOST'])
os.environ.get('PUBLIC_PROTOCOL', 'https'), os.environ.get('PUBLIC_HOST', 'ERROR'))

GEOSERVER_USER = os.environ.get('GEOSERVER_USER', 'admin')
GEOSERVER_PASSWORD = os.environ.get('GEOSERVER_PASSWORD', 'geoserver')
Expand Down Expand Up @@ -587,7 +587,7 @@ def is_valid(v):
# Celery Settings
#
CELERY_BROKER_URL = "amqp://mapstory:%s@%s/%s" % (
os.environ['RABBITMQ_APPLICATION_PASSWORD'], os.environ['RABBITMQ_HOST'], os.environ['RABBITMQ_APPLICATION_VHOST'])
os.environ.get('RABBITMQ_APPLICATION_PASSWORD', 'ERROR'), os.environ.get('RABBITMQ_HOST', 'ERROR'), os.environ.get('RABBITMQ_APPLICATION_VHOST', 'ERROR'))
CELERY_TASK_ALWAYS_EAGER = str_to_bool(os.environ.get(
'CELERY_TASK_ALWAYS_EAGER', 'False')) # False makes tasks run asynchronously
CELERY_TASK_DEFAULT_QUEUE = "default"
Expand All @@ -610,8 +610,8 @@ def is_valid(v):
HAYSTACK_SEARCH = True
# Update facet counts from Haystack
HAYSTACK_FACET_COUNTS = False
HAYSTACK_URL = "%s://%s:%d" % (os.environ['PRIVATE_PROTOCOL'],
os.environ['ELASTIC_HOST'], int(os.environ['ELASTIC_PORT']))
HAYSTACK_URL = "%s://%s:%d" % (os.environ.get('PRIVATE_PROTOCOL', 'http'),
os.environ.get('ELASTIC_HOST', 'ERROR'), int(os.environ.get('ELASTIC_PORT', '9200')))
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'mapstory.search.elasticsearch_backend.MapStoryElasticsearchSearchEngine',
Expand Down

0 comments on commit c95d2dc

Please sign in to comment.