-
Notifications
You must be signed in to change notification settings - Fork 2
Try running TEKDB locally with docker #210
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
base: main
Are you sure you want to change the base?
Changes from all commits
3d2e247
a802708
d2f3550
b4f224c
a4f3daf
c0f2143
f5af575
c153dd7
5b31f6c
d22dc0c
0463e13
8244f52
d896048
c4679e6
75b42b2
10d2628
11d6c85
a7cb16c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Python | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *.pyo | ||
| *.pyd | ||
|
|
||
| # Virtual environments | ||
| env/ | ||
| venv/ | ||
| .venv/ | ||
|
|
||
| # Editor & OS files | ||
| .DS_Store | ||
| .vscode/ | ||
| .idea/ | ||
|
|
||
| # Git | ||
| .git | ||
| .gitignore | ||
|
|
||
| # Build/dist | ||
| build/ | ||
| dist/ | ||
| *.egg-info | ||
|
|
||
| # Static/local settings | ||
| media/ | ||
| static/ | ||
| local_settings.py | ||
| *.sqlite3 | ||
| *.log | ||
|
|
||
| # Node | ||
| node_modules/ | ||
|
|
||
| # Docker | ||
| Dockerfile | ||
| docker-compose*.yml | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| FROM python:3.11-slim | ||
|
|
||
| # Prevent Python from writing .pyc files and enable unbuffered stdout/stderr | ||
| ENV PYTHONDONTWRITEBYTECODE=1 | ||
| ENV PYTHONUNBUFFERED=1 | ||
| ENV PIP_NO_CACHE_DIR=1 | ||
|
|
||
| # Install system dependencies | ||
| RUN apt-get update \ | ||
| && apt-get install -y --no-install-recommends \ | ||
| postgresql-client \ | ||
| gcc \ | ||
| gdal-bin \ | ||
| libgdal-dev \ | ||
| libgeos-dev \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Set working directory | ||
| WORKDIR /usr/src/app | ||
|
|
||
| # Copy requirements first (cache pip install step when dependencies don't change) | ||
| COPY requirements.txt requirements_linux.txt /usr/src/app/ | ||
|
|
||
| # Upgrade pip and install Python dependencies | ||
| RUN pip install --upgrade pip \ | ||
| && pip install -r requirements.txt -r requirements_linux.txt | ||
|
|
||
| # Copy the application code | ||
| COPY . /usr/src/app | ||
|
|
||
| # Copy and make entrypoint executable. The repository contains `docker/entrypoint.sh` | ||
| # which runs collectstatic, migrations and launches uWSGI. | ||
| COPY entrypoint.sh /usr/local/bin/entrypoint.sh | ||
| RUN chmod +x /usr/local/bin/entrypoint.sh | ||
|
|
||
| # Expose the port the app runs on (entrypoint starts django development server or uWSGI on 8000) | ||
| EXPOSE 8000 | ||
|
|
||
| # Default settings module (can be overridden at runtime) | ||
| ENV DJANGO_SETTINGS_MODULE=TEKDB.settings | ||
|
|
||
| ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] | ||
|
|
||
| # use development server by default | ||
| CMD ["dev"] |
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Exit on errors | ||
| set -e | ||
|
|
||
| # If a SQL_HOST is provided, wait for Postgres to become available before running | ||
| # migrations. This prevents race conditions when using docker-compose where the | ||
| # web container starts before the DB is ready. | ||
| if [ -n "$SQL_HOST" ]; then | ||
| echo "Waiting for database at ${SQL_HOST}:${SQL_PORT:-5432}..." | ||
| # pg_isready is available after installing postgresql-client in the image | ||
| until pg_isready -h "$SQL_HOST" -p "${SQL_PORT:-5432}" >/dev/null 2>&1; do | ||
| echo "Postgres is unavailable - sleeping" | ||
| sleep 1 | ||
| done | ||
| echo "Postgres is up" | ||
| fi | ||
|
|
||
| echo "Collecting static files..." | ||
| python manage.py collectstatic --noinput | ||
| echo "Applying database migrations..." | ||
| python manage.py migrate --noinput | ||
| # Load default users only if no users exist | ||
| echo "Checking for existing users..." | ||
| if [ "$(python manage.py shell -c 'from django.contrib.auth import get_user_model; print(get_user_model().objects.count())')" = "0" ]; then | ||
| python manage.py loaddata TEKDB/fixtures/default_users_fixture.json | ||
| fi | ||
| # Load default lookups only if no lookups exist. Use LookupPlanningUnit as the check. | ||
| echo "Checking for existing lookups..." | ||
| if [ "$(python manage.py shell -c 'from TEKDB.models import LookupPlanningUnit; print(LookupPlanningUnit.objects.count())')" = "0" ]; then | ||
| python manage.py loaddata TEKDB/fixtures/default_lookups_fixture.json | ||
| fi | ||
|
|
||
| if [ "$1" = "prod" ]; then | ||
| echo "Starting uWSGI (HTTP) on :8000" | ||
| uwsgi --http :8000 --master --enable-threads --module TEKDB.wsgi | ||
| elif [ "$1" = "dev" ]; then | ||
| echo "Starting python development server on :8000" | ||
| python manage.py runserver 0.0.0.0:8000 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rhodges added some logic to the entrypoint to support dev or prod servers. The |
||
| else | ||
| # Default to the passed command if not 'prod' or 'dev' | ||
| exec "$@" | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,5 +31,8 @@ urllib3>=1.26.5 | |
| #OPTIONAL, BUT LOVELY FOR DEBUGGING | ||
| ipdb | ||
| ipython | ||
|
|
||
| # Serve static files in production containers | ||
|
||
| whitenoise>=6.0.0,<7.0.0 | ||
| # FORMATTING AND LINTING | ||
| ruff | ||
| ruff | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| DEBUG=1 | ||
| SECRET_KEY=foo | ||
| ALLOWED_HOSTS=localhost,127.0.0.1,[::1] | ||
| SQL_ENGINE=django.contrib.gis.db.backends.postgis | ||
| SQL_DATABASE=tekdb | ||
| SQL_USER=postgres | ||
| SQL_PASSWORD=tekdb_password | ||
| SQL_HOST=db | ||
| SQL_PORT=5432 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| services: | ||
| db: | ||
| image: postgis/postgis:15-3.4 | ||
| restart: always | ||
| platform: linux/amd64 | ||
| environment: | ||
| POSTGRES_DB: ${SQL_DATABASE} | ||
| POSTGRES_USER: ${SQL_USER} | ||
| POSTGRES_PASSWORD: ${SQL_PASSWORD} | ||
| volumes: | ||
| - tekdb_db_data:/var/lib/postgresql/data | ||
| ports: | ||
| - "5432:5432" | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U ${SQL_USER} -d ${SQL_DATABASE} -h localhost -p ${SQL_PORT}"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
|
|
||
| web: | ||
| build: | ||
| context: ../TEKDB/ | ||
| dockerfile: ../TEKDB/Dockerfile | ||
| command: ["prod"] | ||
| restart: unless-stopped | ||
| depends_on: | ||
| - db | ||
| env_file: | ||
| - .env.dev | ||
| environment: | ||
| ALLOWED_HOSTS: ${ALLOWED_HOSTS} | ||
| DEBUG: ${DEBUG} | ||
| SQL_ENGINE: ${SQL_ENGINE} | ||
| SQL_HOST: ${SQL_HOST} | ||
| SQL_PORT: ${SQL_PORT} | ||
| SQL_DATABASE: ${SQL_DATABASE} | ||
| SQL_USER: ${SQL_USER} | ||
| SQL_PASSWORD: ${SQL_PASSWORD} | ||
| SECRET_KEY: ${SECRET_KEY} | ||
| ports: | ||
| - "8000:8000" | ||
| volumes: | ||
| - ../TEKDB:/usr/src/app | ||
|
|
||
| volumes: | ||
| tekdb_db_data: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| services: | ||
| db: | ||
| image: postgis/postgis:15-3.4 | ||
| restart: always | ||
| platform: linux/amd64 | ||
| environment: | ||
| POSTGRES_DB: ${SQL_DATABASE} | ||
| POSTGRES_USER: ${SQL_USER} | ||
| POSTGRES_PASSWORD: ${SQL_PASSWORD} | ||
| volumes: | ||
| - tekdb_db_data:/var/lib/postgresql/data | ||
| ports: | ||
| - "5432:5432" | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U ${SQL_USER} -d ${SQL_DATABASE} -h localhost -p ${SQL_PORT}"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
|
|
||
| web: | ||
| build: | ||
| context: ../TEKDB/ | ||
| dockerfile: ../TEKDB/Dockerfile | ||
| restart: unless-stopped | ||
| depends_on: | ||
| - db | ||
| env_file: | ||
| - .env.dev | ||
| environment: | ||
| ALLOWED_HOSTS: ${ALLOWED_HOSTS} | ||
| DEBUG: ${DEBUG} | ||
| SQL_ENGINE: ${SQL_ENGINE} | ||
| SQL_HOST: ${SQL_HOST} | ||
| SQL_PORT: ${SQL_PORT} | ||
| SQL_DATABASE: ${SQL_DATABASE} | ||
| SQL_USER: ${SQL_USER} | ||
| SQL_PASSWORD: ${SQL_PASSWORD} | ||
| SECRET_KEY: ${SECRET_KEY} | ||
| ports: | ||
| - "8000:8000" | ||
| volumes: | ||
| - ../TEKDB:/usr/src/app | ||
|
|
||
| volumes: | ||
| tekdb_db_data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .dockerignore file excludes
Dockerfileanddocker-compose*.ymlfiles from the Docker build context. While docker-compose.yml doesn't need to be in the image, the Dockerfile exclusion is unusual and could cause issues if the build process references it. Consider removing theDockerfileline from .dockerignore.