Skip to content

Commit

Permalink
Docker setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ipmb committed Aug 30, 2019
1 parent 4e1d121 commit 592cd71
Show file tree
Hide file tree
Showing 10 changed files with 772 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.egg-info
node_modules
*.pyc
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM node:10 as client

WORKDIR /app/rh/client
COPY ./rh/client/package.json ./rh/client/yarn.lock ./
RUN NOYARNBUILD=1 yarn install
COPY ./rh/client/ ./
RUN yarn build


FROM python:3.6-buster as build
RUN pip install -U pip pipenv
WORKDIR /app
ENV PIPENV_VENV_IN_PROJECT=1 DJANGO_SETTINGS_MODULE=rh.settings.deploy SECRET_KEY=s ALLOWED_HOSTS=*
COPY Pipfile Pipfile.lock setup.py setup.cfg ./
COPY rh/__init__.py ./rh/__init__.py
RUN pipenv install --deploy
COPY . .
COPY --from=client /app/rh/client ./rh/client
RUN pipenv run manage.py collectstatic --noinput


FROM python:3.6-slim-buster
WORKDIR /app
ENV PATH=/app/.venv/bin:${PATH} DJANGO_SETTINGS_MODULE=rh.settings.deploy PORT=8000

RUN set -ex && \
apt-get update -qq && apt-get install --no-install-recommends -y libpq5 && rm -rf /var/lib/apt/lists/* && \
groupadd -r rh && useradd --uid=1000 --no-log-init -r -g rh rh && \
mkdir -p /app && chown rh:rh /app
COPY --from=build /etc/mime.types /etc/mime.types
COPY --from=build --chown=rh:rh /app ./
# stats
EXPOSE 1717/tcp
# web server
EXPOSE 8000/tcp
USER rh
CMD uwsgi --ini=uwsgi.ini

4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ dj-database-url = "==0.4.2"
django-storages = "==1.6.5"
"boto3" = "==1.6.16"
whitenoise = "==3.3.1"
uwsgi = "<2.1"
pyuwsgi = "*"
django-autoslug = "*"
django-countries = "*"
django-tagulous = {ref = "feature/django-1_11", git = "https://github.com/radiac/django-tagulous.git", editable = true}
"django-sendgrid-v5" = "*"
"psycopg2-binary" = "<=2.8"
"psycopg2" = "*"


[dev-packages]
Expand Down
704 changes: 704 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Foreman Procfile (primarily used for Heroku instances).
#

web: uwsgi --ini=uwsgi.ini --req-logger="file:/dev/null" --route=".* basicauth:RH,$BASIC_AUTH"
web: uwsgi --ini=uwsgi.ini --req-logger="file:/dev/null"
11 changes: 11 additions & 0 deletions rh/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os
import sys

def manage():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rh.settings.local")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)


if __name__ == "__main__":
manage()
27 changes: 0 additions & 27 deletions rh/client/package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion rh/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "RapidPro for Health site built with Django CMS",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "yarn run build",
"postinstall": "test -n \"$NOYARNBUILD\" || yarn run build",
"parcel": "parcel",
"build": "yarn run build_site",
"watch": "yarn run watch_site",
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
author_email='[email protected]',
url='https://github.com/rapidpro/rh/',
packages=find_packages(),
scripts=[
'scripts/manage.py'
],
entry_points={
"console_scripts": ["manage.py = rh.__main__:manage"],
},
include_package_data=True,
)
12 changes: 9 additions & 3 deletions uwsgi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
master = true
no-orphans = true
vacuum = true
auto-procname = true
strict = true
need-app = true

# Prefix log statements with date formatted in common log format:
log-date = [%%d/%%b/%%Y:%%H:%%M:%%S %%z]
log-x-forwarded-for = true
req-logger = file:$(HOME)/logs/rapidpro_for_health.access.log
# req-logger = file:$(HOME)/logs/rapidpro_for_health.access.log
# Default will log to stderr. Uncomment to log to file
# logger = file:$(HOME)/logs/ppfa.error.log


module = rh.wsgi:application
if-not-env = UWSGI_PROCESSES
processes = 2
endif =

offload-threads = 2
thunder-lock = true

Expand All @@ -31,9 +33,13 @@ max-requests = 5000
# %d = directory which contains this config file
##route = ^/docs/(?!styleguide$)(.*) static:%dbuild-docs/$1$2

procname-prefix-spaced = rapidpro_for_health:
if-env = BASIC_AUTH
route = .* basicauth:RH,$(BASIC_AUTH)
endif =

http-socket = :$(PORT)
stats = :1717
stats-http = true
post-buffering = 4096
buffer-size = 8196
harakiri = 30
Expand Down

0 comments on commit 592cd71

Please sign in to comment.