Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync backend with boilerplate #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .env.example

This file was deleted.

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ __pycache__/
*.py[cod]
.idea/
db.sqlite3
.pytest_cache/
.env
.pytest_cache/
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: python
python:
- "3.6"
install:
- pip install pipenv
- pipenv install --dev
services:
- docker
script:
- pipenv run pytest
- docker build -t backend .
- BACKEND_IMAGE=backend docker-compose -f docker-compose-ci.yml run backend /app/scripts/dev/run_tests.sh
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ RUN apk update \
# psycopg2 dependencies
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add postgresql-dev \
&& apk add build-base linux-headers pcre-dev
&& apk add build-base linux-headers pcre-dev \
&& apk add gettext

RUN pip install awscli

EXPOSE 3031
WORKDIR /code
COPY Pipfile Pipfile.lock ./
WORKDIR /app
COPY Pipfile Pipfile.lock /app/
RUN pip install --upgrade pip
RUN pip install pipenv
RUN pipenv install --system --dev
COPY . .
COPY . /app

CMD ["./run-backend.sh"]
CMD ["/app/scripts/run-backend.sh"]
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ djangorestframework = "~=3.10"
djangorestframework-jwt = "~=1.11"
django-hashid-field = "~=2.1"
dj-database-url = "*"
uwsgi = "*"
boto3 = "==1.9.93"
"psycopg2-binary" = "*"

[dev-packages]
factory_boy = "==2.10.0"
Expand Down
111 changes: 107 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions docker-compose-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3'

services:
db:
image: postgres:9.6.8
ports:
- "5432"
env_file: test.env

localstack:
image: localstack/localstack:0.10.2
ports:
- "4567-4584:4567-4584"
environment:
- SERVICES=secretsmanager
- DEBUG=${DEBUG- }
- DATA_DIR=${DATA_DIR- }
- PORT_WEB_UI=${PORT_WEB_UI- }
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR- }
- LAMBDA_REMOTE_DOCKER=false
- KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
- DOCKER_HOST=unix:///var/run/docker.sock
- AWS_EXECUTION_ENV=True
- AWS_DEFAULT_REGION=us-east-1
- AWS_ACCESS_KEY_ID=foo
- AWS_SECRET_ACCESS_KEY=bar

backend:
image: ${BACKEND_IMAGE}
depends_on:
- db
- localstack
restart: on-failure
env_file: test.env
command: ./scripts/dev/run_tests.sh
26 changes: 0 additions & 26 deletions docker-compose.yml

This file was deleted.

Binary file modified locale/error_codes/LC_MESSAGES/django.mo
100644 → 100755
Binary file not shown.
26 changes: 23 additions & 3 deletions restauth/settings.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import os
import json
import dj_database_url
import boto3

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

secrets_manager = boto3.client(
'secretsmanager', endpoint_url=os.environ.get('SECRET_MANAGER_ENDPOINT_URL', None))

db_secret_arn = os.environ['DB_SECRET_ARN']

db_secret_value = secrets_manager.get_secret_value(SecretId=db_secret_arn)
# contains host, username, password and port
db_connection_config = json.loads(db_secret_value.get('SecretString'))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

SECRET_KEY = os.environ.get('SECRET_KEY')
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY')
DEBUG = os.environ.get('DEBUG')
ALLOWED_HOSTS = list(filter(lambda s: len(s) > 0, map(str.strip, os.environ.get('ALLOWED_HOSTS', '').split(','))))
ALLOWED_HOSTS = list(filter(lambda s: len(s) > 0, map(str.strip, os.environ.get('ALLOWED_HOSTS', '*').split(','))))


# Application definition
Expand Down Expand Up @@ -64,7 +74,17 @@
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
'default': dj_database_url.parse('sqlite:///db.sqlite3'),
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.getenv("POSTGRES_DB"),
"USER": db_connection_config.get('username'),
"PASSWORD": db_connection_config.get('password'),
"HOST": db_connection_config.get('host'),
# Persistent connections avoid the overhead of re-establishing a connection
# to the database in each request
"CONN_MAX_AGE": int(os.getenv("POSTGRES_CONN_MAX_AGE", '60')),
"PORT": db_connection_config.get('port'),
}
}


Expand Down
5 changes: 4 additions & 1 deletion restauth/urls.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
url(r'^doc/', get_swagger_view(title='Documentation')),

path('auth/', include(user_patterns)),
path('password-reset/', include(password_reset_patterns))
path('password-reset/', include(password_reset_patterns)),

path('', views.HomeView.as_view(), name='home'),
path('status/elb', views.HealthCheckView.as_view(), name='elb_status'),
]
Loading