Skip to content

Commit

Permalink
Merge pull request #3324 from mathesar-foundation/docker-compose
Browse files Browse the repository at this point in the history
Revamped docker compose
  • Loading branch information
mathemancer authored Jan 17, 2024
2 parents d2e9603 + 590a947 commit 1a14e80
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 138 deletions.
23 changes: 2 additions & 21 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,14 @@

file_server {
precompressed br zstd gzip
root {$MEDIA_ROOT:/mathesar/media/}
root {$MEDIA_ROOT:/code/media/}
}
}
handle_path /static/* {
file_server {
precompressed br zstd gzip
root {$STATIC_ROOT:/mathesar/static/}
root {$STATIC_ROOT:/code/static/}
}
}
# Rewrite and reverse proxy upgrade endpoint calls to Watchtower;
# Accepts only POST requests, rewrites them to GET.
@upgrade_request {
path /api/ui/v0/upgrade/
method POST
}
handle @upgrade_request {
rewrite * /v1/update
method * GET
reverse_proxy watchtower:8080 {
header_up Authorization "Bearer mytoken"
transport http {
# We want keepalive connections to stay open as long as a dockerhub pull
# might take, because Watchtower responds to the upgrade request only when
# it's finished upgrading.
keepalive 0.5h
}
}
}
reverse_proxy mathesar_service:8000
}
15 changes: 13 additions & 2 deletions config/settings/common_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,21 @@ def pipe_delim(pipe_string):
# See pipe_delim above for why we use pipes as delimiters
DATABASES = {
db_key: db_url(url_string)
for db_key, url_string in decouple_config('MATHESAR_DATABASES', cast=Csv(pipe_delim))
for db_key, url_string in decouple_config('MATHESAR_DATABASES', default='', cast=Csv(pipe_delim))
}

DATABASES[decouple_config('DJANGO_DATABASE_KEY', default="default")] = decouple_config('DJANGO_DATABASE_URL', cast=db_url, default='sqlite:///db.sqlite3')
# POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST & POSTGRES_PORT are required env variables for forming a pg connection string for the django database
# lack of any one of these will result in the internal django database to be sqlite.
POSTGRES_DB = decouple_config('POSTGRES_DB', default=None)
POSTGRES_USER = decouple_config('POSTGRES_USER', default=None)
POSTGRES_PASSWORD = decouple_config('POSTGRES_PASSWORD', default=None)
POSTGRES_HOST = decouple_config('POSTGRES_HOST', default=None)
POSTGRES_PORT = decouple_config('POSTGRES_PORT', default=None)

if POSTGRES_DB and POSTGRES_USER and POSTGRES_PASSWORD and POSTGRES_HOST and POSTGRES_PORT:
DATABASES['default'] = db_url(f'postgres://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_HOST}:{POSTGRES_PORT}/{POSTGRES_DB}')
else:
DATABASES['default'] = db_url('sqlite:///db.sqlite3')

for db_key, db_dict in DATABASES.items():
# Engine should be '.postgresql' or '.postgresql_psycopg2' for all db(s),
Expand Down
4 changes: 2 additions & 2 deletions config/settings/production.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from config.settings.common_settings import * # noqa

# Override default settings


DEBUG = False
MATHESAR_MODE = 'PRODUCTION'
# Use a local.py module for settings that shouldn't be version tracked
try:
from .local import * # noqa
Expand Down
9 changes: 0 additions & 9 deletions dev-run.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
#!/usr/bin/env bash
# Start the database
if [[ -z "${DJANGO_DATABASE_URL}" ]]; then
echo "Starting inbuilt database"
./db-run.sh
export DJANGO_DATABASE_URL='postgres://postgres:mathesar@localhost:5432/mathesar_django'
if [[ -z "${MATHESAR_DATABASES}" ]]; then
export MATHESAR_DATABASES='(mathesar_tables|postgresql://postgres:mathesar@localhost:5432/mathesar)'
fi
fi

# For deployments, the DockerFile is configured to build the
# client. Hence, instead of using this script, the web server
Expand Down
26 changes: 5 additions & 21 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,6 @@ services:
timeout: 1s
retries: 30
start_period: 5s
test-service:
extends:
file: docker-compose.yml
service: service
environment:
- DJANGO_DATABASE_URL=postgres://mathesar:mathesar@mathesar_dev_db:5432/mathesar_django
- MATHESAR_DATABASES=(mathesar_tables|postgresql://mathesar:mathesar@mathesar_dev_db:5432/mathesar)
container_name: mathesar_service_test
image: mathesar/mathesar-test:latest
build:
context: .
dockerfile: Dockerfile
args:
PYTHON_REQUIREMENTS: requirements-dev.txt
depends_on:
- dev-db
# On testing, the HTTP port is exposed to other containers, and the host.
ports:
- "8000:8000"
# A Django development webserver + Svelte development server used when developing Mathesar.
# The code changes are hot reloaded and debug flags are enabled to aid developers working on Mathesar.
# It is not recommended to use this service in production environment.
Expand All @@ -61,13 +42,16 @@ services:
environment:
- MODE=${MODE-DEVELOPMENT}
- DEBUG=${DEBUG-True}
- DJANGO_ALLOW_ASYNC_UNSAFE=true
- DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE-config.settings.development}
- ALLOWED_HOSTS=${ALLOWED_HOSTS-*}
- SECRET_KEY=${SECRET_KEY}
- DJANGO_DATABASE_URL=postgres://mathesar:mathesar@mathesar_dev_db:5432/mathesar_django
- MATHESAR_DATABASES=(mathesar_tables|postgresql://mathesar:mathesar@mathesar_dev_db:5432/mathesar)
- DJANGO_SUPERUSER_PASSWORD=password
- POSTGRES_DB=mathesar_django
- POSTGRES_USER=mathesar
- POSTGRES_PASSWORD=mathesar
- POSTGRES_HOST=mathesar_dev_db
- POSTGRES_PORT=5432
entrypoint: ./dev-run.sh
volumes:
- .:/code/
Expand Down
Loading

0 comments on commit 1a14e80

Please sign in to comment.