Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 25 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
FROM python:3.7
COPY ./ /tmp/simdb/
RUN cd /tmp/simdb/ && \
pip3 install . && \
pip3 install flask flask_caching flask_cors flask_restx gunicorn psycopg2-binary && \
rm -rf /tmp/simdb

ENTRYPOINT ["gunicorn", "--bind=0.0.0.0:5000", "--workers=1", "simdb.remote.wsgi:app"]
EXPOSE 5000
ARG PYVER=3.12
FROM ghcr.io/astral-sh/uv:python${PYVER}-trixie-slim

ENV UV_NO_DEV=1
ENV SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
libldap2-dev \
libsasl2-dev \
libmagic1 \
&& rm -rf /var/lib/apt/lists/*

COPY uv.lock pyproject.toml alembic.ini ./
COPY src/ ./src/
COPY alembic/ ./alembic/
RUN uv sync --locked --extra all

ENV SIMDB_SITE_CONFIG_PATH=/app/config/simdb.cfg

CMD ["uv", "run", "simdb_server"]

36 changes: 36 additions & 0 deletions config/simdb.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[flask]
flask_env = development
debug = True
testing = True
secret_key = CHANGE ME

[authentication]
type=none

[server]
upload_folder = /data/simdb/simulations
port = 5000
ssl_enabled = False
authentication_type = None
admin_password=CHANGE_ME
imas_remote_host = localhost

[database]
type = postgres
host = postgres
port = 5432
username = simdb
password = simdb
database = simdb

[validation]
path = ./validation
auto_validate = True
error_on_fail = True

[celery]
broker_url = redis://redis:6379/0
result_backend = redis://redis:6379/0

[partition]
data = /data/simdb/partition
54 changes: 54 additions & 0 deletions docker-compose-pyver.yml
Comment thread
Yannicked marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This docker-compose-pyver.yml extends the base docker-compose.yml
# to run three web services for different PYVER (3.11 and 3.13, 3.12 is the default)
# but they all use the same redis and postgres service.
# Run `docker compose -f docker-compose-workers.yml up` to start it up.
include:
- docker-compose.yml

services:
migrations-311:
extends:
service: migrations
build:
args:
PYVER: "3.11"

migrations-313:
extends:
service: migrations
build:
args:
PYVER: "3.13"

web-311:
extends:
service: web
build:
args:
PYVER: "3.11"
ports: !override
- "5001:5000"
depends_on: !override
# !override is necessary to remove the original migrations from depends_on
redis:
condition: service_healthy
postgres:
condition: service_healthy
migrations-311:
condition: service_completed_successfully

web-313:
extends:
service: web
build:
args:
PYVER: "3.13"
ports: !override
- "5003:5000"
depends_on: !override
redis:
condition: service_healthy
postgres:
condition: service_healthy
migrations-313:
condition: service_completed_successfully
109 changes: 85 additions & 24 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,94 @@
version: "3.9"
services:
db:
image: postgres
migrations:
build: .
volumes:
- db_data:/var/lib/postgresql/data
- ./config:/app/config:ro
environment:
POSTGRES_DB: simdb
POSTGRES_USER: simdb
POSTGRES_PASSWORD: simdb
simdb:
DATABASE_URL: postgresql+psycopg2://simdb:simdb@postgres:5432/simdb
depends_on:
- postgres
command: uv run alembic upgrade head
restart: "no"

web:
build: .
environment:
SIMDB_DATABASE_TYPE: postgres
SIMDB_DATABASE_HOST: db
SIMDB_DATABASE_PORT: 5432
SIMDB_SERVER_UPLOAD_FOLDER: /simulations
ports:
- "5000:5000"
volumes:
- simulations:/simulations
- ./validation:/app/validation:ro
- ./config:/app/config:ro
- ./tmp/partition_data:/data/simdb/partition:ro
- ./upload_folder:/data/simdb/simulations
depends_on:
- db
nginx:
image: nginx
ports:
- 80:80
redis:
condition: service_healthy
postgres:
condition: service_healthy
migrations:
condition: service_completed_successfully
restart: unless-stopped

worker:
profiles: [with_workers]
# docker compose --profile with_workers enables this service
build: .
command: uv run simdb_worker
volumes:
- ./config:/app/config:ro
- ./tmp/partition_data:/data/simdb/partition:ro
- ./upload_folder:/data/simdb/simulations
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
migrations:
condition: service_completed_successfully
restart: unless-stopped

beat:
profiles: [with_workers]
# docker compose --profile with_workers enables this service
build: .
command: uv run simdb_beat
volumes:
- ./config:/app/config:ro
depends_on:
- simdb
redis:
condition: service_healthy
postgres:
condition: service_healthy
migrations:
condition: service_completed_successfully
restart: unless-stopped

redis:
image: redis:8-alpine
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 1s
timeout: 5s
retries: 5
restart: unless-stopped

postgres:
Comment thread
Yannicked marked this conversation as resolved.
image: postgres:16-alpine
environment:
- POSTGRES_USER=simdb
- POSTGRES_PASSWORD=simdb
- POSTGRES_DB=simdb
volumes:
- ./docker/proxy_params:/etc/nginx/proxy_params
- ./docker/simdb.nginx:/etc/nginx/conf.d/default.conf
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U simdb"]
interval: 1s
timeout: 5s
retries: 5
restart: unless-stopped

volumes:
db_data: {}
simulations: {}
redis_data:
postgres_data:

2 changes: 1 addition & 1 deletion scripts/simdb_server
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from simdb.remote.wsgi import run

run(port=5000)
run()
4 changes: 2 additions & 2 deletions src/simdb/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ def load(self, file: Optional[TextIO] = None) -> None:
self._load_environmental_vars()

# Import configuration options from files defined by environment variables
path = self.get_string_option("user.config-path", default="")
path = self.get_string_option("user.config.path", default="")
if path:
self._user_config_path = Path(path)
self._user_config_dir = self._user_config_path.parent

path = self.get_string_option("site.config-path", default="")
path = self.get_string_option("site.config.path", default="")
if path:
self._site_config_path = Path(path)
self._site_config_dir = self._site_config_path.parent
Expand Down
2 changes: 1 addition & 1 deletion src/simdb/remote/scripts/app.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ type = sqlite

[validation]
auto_validate = True
error_on_fail = True
error_on_fail = True
8 changes: 6 additions & 2 deletions src/simdb/remote/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_prefix=1)


def run(*, port=5000):
def run():
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_prefix=1)
config = app.simdb_config

port = config.get_option("server.port")
if not isinstance(port, int) or isinstance(port, bool):
raise TypeError(f"Invalid server.port value: expected int, got {type(port)}")

if config.get_option("server.ssl_enabled"):
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.load_cert_chain(
Expand All @@ -27,4 +31,4 @@ def run(*, port=5000):


if __name__ == "__main__":
run(port=5000)
run()
Loading
Loading