-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to run regulations_example in Docker
- Loading branch information
1 parent
57ab428
commit ecd0bd8
Showing
20 changed files
with
1,186 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
FROM python:3.7-slim | ||
|
||
# Install packages needed to run your application (not build deps): | ||
# We need to recreate the /usr/share/man/man{1..8} directories first because | ||
# they were clobbered by a parent image. | ||
RUN set -ex \ | ||
&& RUN_DEPS=" \ | ||
libexpat1 \ | ||
libjpeg62-turbo \ | ||
libpcre3 \ | ||
libpq5 \ | ||
mime-support \ | ||
postgresql-client \ | ||
procps \ | ||
zlib1g \ | ||
" \ | ||
&& seq 1 8 | xargs -I{} mkdir -p /usr/share/man/man{} \ | ||
&& apt-get update && apt-get install -y --no-install-recommends $RUN_DEPS \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN mkdir /code/ | ||
RUN mkdir /code/static | ||
RUN mkdir /code/media | ||
WORKDIR /code/ | ||
ADD . /code/ | ||
|
||
RUN set -ex \ | ||
&& BUILD_DEPS=" \ | ||
build-essential \ | ||
git \ | ||
libexpat1-dev \ | ||
libjpeg62-turbo-dev \ | ||
libpcre3-dev \ | ||
libpq-dev \ | ||
zlib1g-dev \ | ||
" \ | ||
&& apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \ | ||
&& python3.7 -m venv /venv \ | ||
&& /venv/bin/pip install -U pip \ | ||
&& /venv/bin/pip install --no-cache-dir -r /code/regulations_example/requirements.txt \ | ||
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
EXPOSE 8000 | ||
|
||
# Add custom environment variables needed by Django or your settings file here: | ||
ENV DJANGO_SETTINGS_MODULE=regulations_example.settings | ||
|
||
# Tell uWSGI where to find your wsgi file: | ||
ENV UWSGI_WSGI_FILE=regulations_example/wsgi.py | ||
|
||
# Base uWSGI configuration (you shouldn't need to change these): | ||
ENV UWSGI_VIRTUALENV=/venv UWSGI_HTTP=:8000 UWSGI_MASTER=1 UWSGI_HTTP_AUTO_CHUNKED=1 UWSGI_HTTP_KEEPALIVE=1 UWSGI_UID=1000 UWSGI_GID=2000 UWSGI_LAZY_APPS=1 UWSGI_WSGI_ENV_BEHAVIOR=holy | ||
|
||
# Number of uWSGI workers and threads per worker (customize as needed): | ||
ENV UWSGI_WORKERS=2 UWSGI_THREADS=4 | ||
|
||
# uWSGI uploaded media file serving configuration: | ||
ENV UWSGI_STATIC_MAP="/media/=/code/regulations_example/media/" | ||
|
||
# Call collectstatic with dummy environment variables: | ||
RUN DATABASE_URL=postgres://none /venv/bin/python manage.py collectstatic --noinput | ||
|
||
# make sure static files are writable by uWSGI process | ||
RUN mkdir -p /code/regulations_example/media/images && chown -R 1000:2000 /code/regulations_example/media | ||
|
||
# mark the destination for images as a volume | ||
VOLUME ["/code/regulations_example/media/images/"] | ||
|
||
# start uWSGI, using a wrapper script to allow us to easily add more commands to container startup: | ||
ENTRYPOINT ["/code/docker-entrypoint.sh"] | ||
|
||
# Start uWSGI | ||
CMD ["/venv/bin/uwsgi", "--show-config"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
version: '2' | ||
|
||
services: | ||
db: | ||
environment: | ||
POSTGRES_DB: app_db | ||
POSTGRES_USER: app_user | ||
POSTGRES_PASSWORD: changeme | ||
restart: always | ||
image: postgres:9.6 | ||
expose: | ||
- "5432" | ||
elasticsearch: | ||
image: elasticsearch:2.3 | ||
restart: always | ||
expose: | ||
- "9200" | ||
app: | ||
environment: | ||
DJANGO_SECRET_KEY: changeme | ||
DATABASE_URL: postgres://app_user:changeme@db/app_db | ||
ELASTICSEARCH_ENDPOINT: elasticsearch | ||
build: | ||
context: . | ||
dockerfile: ./Dockerfile | ||
volumes: | ||
- ./:/code | ||
links: | ||
- db:db | ||
- elasticsearch:elasticsearch | ||
ports: | ||
- "8000:8000" | ||
depends_on: | ||
- db | ||
- elasticsearch | ||
volumes: | ||
media-root: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
until psql $DATABASE_URL -c '\l'; do | ||
>&2 echo "Postgres is unavailable - sleeping" | ||
sleep 1 | ||
done | ||
|
||
>&2 echo "Postgres is up - continuing" | ||
|
||
if [ "$1" = '/venv/bin/uwsgi' ]; then | ||
/venv/bin/python manage.py migrate --noinput | ||
fi | ||
|
||
if [ "x$DJANGO_LOAD_INITIAL_DATA" = 'xon' ]; then | ||
/venv/bin/python manage.py load_initial_data | ||
fi | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "regulations_example.settings.dev") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from wagtail.api.v2.endpoints import PagesAPIEndpoint | ||
from wagtail.api.v2.router import WagtailAPIRouter | ||
from wagtail.images.api.v2.endpoints import ImagesAPIEndpoint | ||
from wagtail.documents.api.v2.endpoints import DocumentsAPIEndpoint | ||
|
||
# Create the router. "wagtailapi" is the URL namespace | ||
api_router = WagtailAPIRouter('wagtailapi') | ||
|
||
# Add the three endpoints using the "register_endpoint" method. | ||
# The first parameter is the name of the endpoint (eg. pages, images). This | ||
# is used in the URL of the endpoint | ||
# The second parameter is the endpoint class that handles the requests | ||
api_router.register_endpoint('pages', PagesAPIEndpoint) | ||
api_router.register_endpoint('images', ImagesAPIEndpoint) | ||
api_router.register_endpoint('documents', DocumentsAPIEndpoint) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Django>=2.2,<2.3 | ||
django-dotenv==1.4.1 | ||
wagtail>=2.5,<2.6 | ||
Pillow<6.0,>=4.0.0 | ||
elasticsearch==2.4.1 | ||
dj-database-url==0.4.1 | ||
uwsgi>=2.0.17,<2.1 | ||
psycopg2>=2.7,<3.0 | ||
wagtail-treemodeladmin>=1.0.4,<1.1 | ||
regdown>=1.0.1,<1.2 | ||
whitenoise==3.2.2 |
Oops, something went wrong.