-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Django as backend API to development env:
- update docker-compose to include django and database services - add STRTA scripts for local development - bootstrap Django to be used as API backend with necessary dependencies, middleware, db config - update start command in the package.json for frontend so that it can proxy the django API locally - update README for the STRTA section - update gitignore to ignore byte-compiled python files and static files from Django
- Loading branch information
Showing
25 changed files
with
495 additions
and
7 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
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
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,35 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [[ -n "${ECHOLOCATOR_DEBUG}" ]]; then | ||
set -x | ||
fi | ||
|
||
DIR="$(dirname "${0}")/../" | ||
|
||
function usage() { | ||
echo -n \ | ||
"Usage: $(basename "$0") | ||
Pull down secrets from S3. | ||
" | ||
} | ||
|
||
# TODO: potentially as a part of this issue: https://github.com/azavea/echo-locator/issues/376 | ||
# after switching to a different bundler, we may want to copy and populate some env vars | ||
function pull_env() { | ||
pushd "${DIR}" | ||
|
||
echo "Pulling .env from ${1}" | ||
# aws s3 cp "s3://${1}/.env" ".env" | ||
|
||
popd | ||
} | ||
|
||
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then | ||
if [ "${1:-}" = "--help" ]; then | ||
usage | ||
else | ||
pull_env | ||
fi | ||
fi |
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,25 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [[ -n "${ECHOLOCATOR_DEBUG}" ]]; then | ||
set -x | ||
fi | ||
|
||
function usage() { | ||
echo -n \ | ||
"Usage: $(basename "$0") | ||
Run a Django management command | ||
" | ||
} | ||
|
||
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then | ||
if [ "${1:-}" = "--help" ]; then | ||
usage | ||
else | ||
docker-compose \ | ||
run --rm --entrypoint python \ | ||
django \ | ||
manage.py "$@" | ||
fi | ||
fi |
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,23 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [[ -n "${ECHOLOCATOR_DEBUG}" ]]; then | ||
set -x | ||
fi | ||
|
||
function usage() { | ||
echo -n \ | ||
"Usage: $(basename "$0") | ||
Attempts to setup the project's development environment. | ||
" | ||
} | ||
|
||
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then | ||
if [ "${1:-}" = "--help" ]; then | ||
usage | ||
else | ||
./scripts/bootstrap | ||
./scripts/update | ||
fi | ||
fi |
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,41 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [[ -n "${ECHOLOCATOR_DEBUG}" ]]; then | ||
set -x | ||
fi | ||
|
||
function usage() { | ||
echo -n \ | ||
"Usage: $(basename "$0") | ||
Build container images and execute database migrations. | ||
" | ||
} | ||
|
||
function cleanup() { | ||
docker-compose stop | ||
} | ||
|
||
trap cleanup ERR | ||
|
||
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then | ||
if [ "${1:-}" = "--help" ]; then | ||
usage | ||
else | ||
# Ensure container images are current | ||
docker-compose build | ||
|
||
# Bring up PostgreSQL and Django in a way that respects | ||
# configured service health checks. | ||
docker-compose up -d database django | ||
|
||
# Apply any outstanding Django migrations | ||
./scripts/manage migrate | ||
|
||
# Collect Django static files | ||
./scripts/manage collectstatic --no-input | ||
|
||
docker-compose stop | ||
fi | ||
fi |
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,28 @@ | ||
FROM quay.io/azavea/django:3.2-python3.9-slim | ||
|
||
RUN mkdir -p /usr/local/src/backend | ||
WORKDIR /usr/local/src/backend | ||
|
||
COPY requirements.txt /usr/local/src/backend/ | ||
RUN set -ex \ | ||
&& buildDeps=" \ | ||
build-essential \ | ||
" \ | ||
&& deps=" \ | ||
postgresql-client-13 \ | ||
" \ | ||
&& apt-get update && apt-get install -y $buildDeps $deps --no-install-recommends \ | ||
&& pip install --no-cache-dir -r requirements.txt \ | ||
&& apt-get purge -y --auto-remove $buildDeps | ||
|
||
COPY . /usr/local/src/backend | ||
|
||
CMD ["-b :8085", \ | ||
"--workers=1", \ | ||
"--timeout=60", \ | ||
"--access-logfile=-", \ | ||
"--access-logformat=%({X-Forwarded-For}i)s %(h)s %(l)s %(u)s %(t)s \"%(r)s\" %(s)s %(b)s \"%(f)s\" \"%(a)s\"", \ | ||
"--error-logfile=-", \ | ||
"--log-level=info", \ | ||
"--capture-output", \ | ||
"echo.wsgi"] |
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 @@ | ||
default_app_config = 'api.apps.ApiConfig' |
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,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ApiConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'api' |
Empty file.
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,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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,3 @@ | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
from rest_framework.decorators import api_view |
Empty file.
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,16 @@ | ||
""" | ||
ASGI config for echo 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.2/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'echo.settings') | ||
|
||
application = get_asgi_application() |
Oops, something went wrong.