Skip to content

Commit

Permalink
Merge pull request #1 from jsatt/modernize
Browse files Browse the repository at this point in the history
Modernize
  • Loading branch information
jsatt authored Jan 4, 2021
2 parents 0b74b6d + 0c83c99 commit a6e632b
Show file tree
Hide file tree
Showing 39 changed files with 2,853 additions and 66 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**/__pycache__
**/*.pyc
.tox
.vim/
.vim*
.git/
*.sql
*.sql.gz
.mypy_cache/
.pytest_cache/
.ipython/
docker-compose.yml
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
root = true

[*]
end_of_line = lf
insert_final_newline = false
charset = utf-8
trim_trailing_whitespace = true

[*.py]
indent_style = space
indent_size = 4
max_line_length = 119

[*.yaml,*.yml]
indent_style = space
indent_size = 2

[*.js,*.json]
indent_style = space
indent_size = 2
65 changes: 65 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# How are you using Docker for development?
# full - Docker for running app and all dependencies (recommmended)
# deps - Docker for running dependencies, but running app natively
# none - Running app and all dependencies natively
DEV_DOCKER_WORKFLOW=full
#DEV_DOCKER_WORKFLOW=deps
#DEV_DOCKER_WORKFLOW=none

## ENVIRONMENT CONFIG
# choose a debugger tool, pdb, ipdb, bpdb, etc.
#PYTHONBREAKPOINT=ipdb.set_trace
# put ipython configs somewhere persistent, so you have history between Docker reboots
# Not needed for deps or none workflows.
#IPYTHONDIR=/usr/src/app/.ipython

## DOCKER COMPOSE SETTINGS

#COMPOSE_APP_PATH=.
#COMPOSE_CACHE_PORT=637
#COMPOSE_DB_PORT=5432
#COMPOSE_PYTHON_PKG_PATH=
#COMPOSE_TASK_CONCURRENCY=500
#COMPOSE_TASK_LOG_LEVEL=info
#COMPOSE_WEB_LOG_LEVEL=info
#COMPOSE_WEB_PORT=8002
#COMPOSE_WEB_WORKERS=4

## DJANGO SETTINGS

ALLOWED_HOSTS=*
#BASE_URL=
#CACHE_URL=redis://127.0.0.1:6370/0
#DATABASE_CONNECTION_AGE=60
#DATABASE_URL=
#DATABASE_PASSWORD=
DEBUG=True
#MEDIA_ROOT=
#MEDIA_URL=
#SECRET_KEY=keepitsecret
#SESSION_CACHE_URL=redis://127.0.0.1:6370/1
#SESSION_ENGINE=cache
#STATIC_ROOT=
#STATIC_URL=/static/

## DEPENDENCY SETTINGS

#CELERY_BROKER_URL=redis://127.0.0.1:6370/2
#CELERY_RESULT_BACKEND=redis://127.0.0.1:6370/3
#DD_ENV=development
#DD_SERVICE=
#DD_TAGS=
#DD_AGENT_SERVICE_HOST=dd-agent
#DD_AGENT_SERVICE_PORT=8126
#DD_STATSD_SERVICE_PORT=8125
#DD_LOGS_INJECTION=True
#DD_VERSION=
#LOG_FORMAT=
#LOG_FORMATTER=plain
#LOG_LEVEL=DEBUG
#SENTRY_DSN=
#SENTRY_ENVIRONMENT=development
#SENTRY_EVENT_LEVEL=ERROR
#SENTRY_LOG_LEVEL=INFO
#USE_DATADOG=True
#USE_SENTRY=True
17 changes: 15 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
*.swp
# config
.env

# python
__pycache__
*.pyc
settings_override.py
.ipython/

# editors
*.sw[mnop]
*.orig

# linters
.mypy_cache
.coverage
htmlcov/
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM python:3.8

ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV POETRY_VIRTUALENVS_CREATE=0

RUN adduser --uid 1000 --gecos --quiet --disabled-password app_user

RUN mkdir -p /usr/src/app \
&& chown app_user.app_user /usr/src/app
WORKDIR /usr/src/app

COPY --chown=app_user requirements.txt ./

ARG PIP_ARGS=
RUN set -eux \
&& apt update \
&& apt upgrade -y \
&& apt install -y curl\
&& pip3 install -r requirements.txt $PIP_ARGS \
&& apt autoremove -y \
&& rm -rf /root/.cache/pip /var/cache/apt

COPY --chown=app_user . .

USER app_user

CMD ["/usr/local/bin/gunicorn", "base_app.asgi:application", "-k", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000"]

16 changes: 16 additions & 0 deletions base_app/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for eligibility project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'base_app.settings')

application = get_asgi_application()
21 changes: 11 additions & 10 deletions base_app/celery.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from __future__ import absolute_import

import os

from celery import Celery

from celery import Celery, signals
from ddtrace import patch_all
from django.conf import settings

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'base_app.settings')

if settings.USE_DATADOG and sys.argv[0].endswith('celery'): # pragma: no cover
patch_all()
app = Celery('base_app')
app.config_from_object(settings, namespace='CELERY')
app.autodiscover_tasks()


# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object(settings)
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@signals.setup_logging.connect
def disable_celery_logging_override(**kwargs): # pragma: no cover
# let Celery use logging configured by Django rather then set up it's own
pass
Loading

0 comments on commit a6e632b

Please sign in to comment.