Skip to content

Commit

Permalink
Make it possible to run regulations_example in Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
willbarton committed Jan 28, 2020
1 parent 57ab428 commit ecd0bd8
Show file tree
Hide file tree
Showing 20 changed files with 1,186 additions and 4 deletions.
75 changes: 75 additions & 0 deletions Dockerfile
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"]

56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,62 @@ Building blocks for interactive regulations in Wagtail.
## Usage


### Components

Wagtail Regulations provides the building blocks to create and serve
interactive US federal regulations on existing Wagtail sites.
It is intended to integrate into sites that may have their base templates,
design language and components, and Wagtail base pages. It also provides
everything needed to stand-up a new interactive regulations site using the
US Web Design System.

The basic components are as follows:

#### Regulation content

Wagtail Regulations includes Django models that represent regulations, their
effective versions, subparts, and sections.

Regulation content is stored in `Section` objects in Markdown outside of the
Wagtail page tree.

#### Regulation pages

Regulation pages are routable Wagtail pages that live in the Wagtail page
tree and serve the regulation content from the
[regulation content](#regulation-content). Regulation pages can be used two
ways:

1. By inheriting from the abstract `wagtailregulations.RegulationPage` model
directly.
2. By creating a new page model using any `Page` subclass and
`RegulationPageMixin`.


#### Regulation search

Regulation content is indexed and searchable using Haystack.


#### Regulation API

The API provides access to the regulation pages and their content so that a
frontend can consume it.


#### Frontend

The frontend serves the regulation content and search to end users.


#### eCFR Parser



### Putting it all together



## Getting help

Please add issues to the [issue tracker](https://github.com/cfpb/wagtail-regulations/issues).
Expand Down
38 changes: 38 additions & 0 deletions docker-compose.yml
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:

19 changes: 19 additions & 0 deletions docker-entrypoint.sh
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 "$@"
11 changes: 11 additions & 0 deletions manage.py
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)
15 changes: 15 additions & 0 deletions regulations_example/api.py
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)
11 changes: 11 additions & 0 deletions regulations_example/requirements.txt
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
Loading

0 comments on commit ecd0bd8

Please sign in to comment.