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

Revamped docker compose #3324

Merged
merged 26 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0dbd074
rm some unnecessary env variables
Anish9901 Nov 15, 2023
791f66d
aggregate required env variables for ease of use of the user
Anish9901 Nov 15, 2023
0aade43
cleaned up compose file and deprecated DJANGO_DATABASE_URL
Anish9901 Nov 16, 2023
f42874f
document env variables and add a bunch of todos
Anish9901 Nov 17, 2023
67db259
add caddy
Anish9901 Nov 20, 2023
8b85b31
figured out caddy, volumes, also added prereqs
Anish9901 Nov 21, 2023
fde57e0
rename required config -> config
Anish9901 Nov 21, 2023
1da788d
add info about volumes
Anish9901 Nov 23, 2023
c0efee4
minor fixes
Anish9901 Nov 27, 2023
d6df73d
add info about all the services, deleted test compose and rm dependen…
Anish9901 Nov 28, 2023
e405a04
fix merge conflicts
Anish9901 Nov 28, 2023
bd7646c
fix merge conflicts
Anish9901 Nov 28, 2023
6dd4d54
Merge branch 'develop' into docker-compose
Anish9901 Nov 28, 2023
4ca91f0
added POSTGRES_HOST and POSTGRES_PORT & removed dependency of dev com…
Anish9901 Nov 29, 2023
e9b3226
flake8: fix indent
Anish9901 Nov 29, 2023
36f7ed7
Merge branch 'develop' into docker-compose
mathemancer Dec 14, 2023
f54d592
Merge branch 'develop' into docker-compose
mathemancer Dec 18, 2023
d536a51
Add defaults to avoid breakage when no DB vars are set
mathemancer Dec 19, 2023
2dd505d
tidy up comment style for reduced line width
mathemancer Dec 19, 2023
9bd39c7
add other default variables in entrypoint script
mathemancer Dec 19, 2023
48295fd
Merge branch 'develop' into docker-compose
mathemancer Jan 5, 2024
e40b767
format and tidy the docker compose YAML file
mathemancer Jan 5, 2024
18eb10f
Add deprecation warning to MATHESAR_DATABASES
mathemancer Jan 5, 2024
5a961ab
Change handling of sudo recommendation
mathemancer Jan 14, 2024
1a22b73
add default for MATHESAR_DATABASES
mathemancer Jan 17, 2024
590a947
Merge branch 'develop' into docker-compose
mathemancer Jan 17, 2024
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
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
Loading