-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Docker Compose setup for development (#128)
* Add a Docker Compose setup. * Make app and docs ports configurable. * Add .dockerignore. * Wait for postgres in app container. * Run app container in /app. * Add docs to contributing. * Add settings.LOGIN_URL. * Make GID, UID customizable and document it. * Move LOGIN_URL to settings.py. * Add redirect from / to /dashboard/. * Auto-run migrations on 'docker compose up'. Thanks, Atul Varma
- Loading branch information
Showing
9 changed files
with
198 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.venv | ||
.vscode | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
venv | ||
.eggs | ||
.pytest_cache | ||
*.egg-info | ||
.DS_Store |
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,30 @@ | ||
FROM python:3.9 | ||
|
||
WORKDIR /app | ||
|
||
# Set up the minimum structure needed to install | ||
# django_sql_dashboard's dependencies and the package itself | ||
# in development mode. | ||
COPY setup.py README.md . | ||
RUN mkdir django_sql_dashboard && pip install -e '.[test]' | ||
|
||
# We need to have postgres installed in this container | ||
# because the automated test suite actually spins up | ||
# (and shuts down) a database inside the container. | ||
RUN apt-get update && apt-get install -y \ | ||
postgresql postgresql-contrib \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install dependencies needed for editing documentation. | ||
COPY docs/requirements.txt . | ||
RUN pip install -r requirements.txt | ||
|
||
ARG GID=1000 | ||
ARG UID=1000 | ||
|
||
# Set up a non-root user. Aside from being best practice, | ||
# we also need to do this because the test suite refuses to | ||
# run as the root user. | ||
RUN groupadd -g ${GID} appuser && useradd -r -u ${UID} -g appuser appuser | ||
|
||
USER appuser |
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,34 @@ | ||
version: "2" | ||
services: | ||
app: | ||
build: . | ||
links: | ||
- db | ||
volumes: | ||
- .:/app | ||
environment: | ||
- DATABASE_URL=postgres://appuser:test123@db/test_project | ||
- DJANGO_SETTINGS_MODULE=config.settings_interactive | ||
- PYTHONUNBUFFERED=yup | ||
working_dir: /app | ||
entrypoint: ["./test_project/wait-for-postgres.sh"] | ||
ports: | ||
- "${APP_PORT:-8000}:${APP_PORT:-8000}" | ||
command: bash -c "python test_project/manage.py migrate && python test_project/manage.py runserver 0.0.0.0:${APP_PORT:-8000}" | ||
docs: | ||
build: . | ||
volumes: | ||
- .:/app | ||
working_dir: /app/docs | ||
ports: | ||
- "${DOCS_PORT:-8001}:${DOCS_PORT:-8001}" | ||
command: make SPHINXOPTS="--host 0.0.0.0 --port ${DOCS_PORT:-8001}" livehtml | ||
db: | ||
# Note that this database is only used when we use | ||
# test_project interactively; automated tests spin up | ||
# their own database inside the app container. | ||
image: postgres:13-alpine | ||
environment: | ||
- POSTGRES_PASSWORD=test123 | ||
- POSTGRES_USER=appuser | ||
- POSTGRES_DB=test_project |
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 |
---|---|---|
|
@@ -97,3 +97,5 @@ | |
# https://docs.djangoproject.com/en/3.1/howto/static-files/ | ||
|
||
STATIC_URL = "/static/" | ||
|
||
LOGIN_URL = "/admin/login/" |
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,12 @@ | ||
# Normally test_project is used as scaffolding for | ||
# django_sql_dashboard's automated tests. However, it can | ||
# be useful during development to have a sample project to | ||
# tinker with interactively. These Django settings can be | ||
# useful when we want to do that. | ||
|
||
from .settings import * | ||
|
||
# Just have our dashboard use the exact same credentials for | ||
# our database, there's no need to bother with read-only | ||
# permissions when using test_project interactively. | ||
DATABASES["dashboard"] = DATABASES["default"] |
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
from django.contrib import admin | ||
from django.urls import include, path | ||
from django.views.generic.base import RedirectView | ||
|
||
import django_sql_dashboard | ||
|
||
|
||
urlpatterns = [ | ||
path("dashboard/", include(django_sql_dashboard.urls)), | ||
path("admin/", admin.site.urls), | ||
path("", RedirectView.as_view(url="/dashboard/")), | ||
] |
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,11 @@ | ||
#!/bin/sh | ||
# wait-for-postgres.sh | ||
|
||
set -e | ||
|
||
until psql $DATABASE_URL -c '\q'; do | ||
>&2 echo "Postgres is unavailable - sleeping" | ||
sleep 1 | ||
done | ||
|
||
exec "$@" |