From b604c243c8db64dd5678dee5094b74a233ced724 Mon Sep 17 00:00:00 2001 From: Viswamedha Nalabotu Date: Thu, 26 Feb 2026 12:08:16 +0000 Subject: [PATCH] Added prod start script, tweaked swarm values for inference containers --- compose/dev/docker-compose.yml | 32 +++++++++-------------- compose/prod/django/start | 27 +++++++++++++++++++ compose/prod/docker-compose.inference.yml | 6 +++-- 3 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 compose/prod/django/start diff --git a/compose/dev/docker-compose.yml b/compose/dev/docker-compose.yml index a03d00f..d5a8013 100644 --- a/compose/dev/docker-compose.yml +++ b/compose/dev/docker-compose.yml @@ -4,12 +4,11 @@ services: build: context: ../../ dockerfile: compose/dev/django/Dockerfile - env_file: - - ../../.env + env_file: ../../.env volumes: - ../../:/app ports: - - '0.0.0.0:8000:8000' + - "8000:8000" depends_on: fyp-postgres-dev: condition: service_healthy @@ -23,27 +22,26 @@ services: dockerfile: compose/dev/node/Dockerfile environment: NODE_ENV: development - CHOKIDAR_USEPOLLING: 'true' + CHOKIDAR_USEPOLLING: "true" stdin_open: true volumes: - ../../site:/app:delegated - /app/node_modules ports: - - '0.0.0.0:5173:5173' + - "5173:5173" fyp-postgres-dev: container_name: fyp-postgres-dev image: pgvector/pgvector:pg15 - env_file: - - ../../.env + env_file: ../../.env environment: POSTGRES_HOST_AUTH_METHOD: trust volumes: - fyp_postgres_data:/var/lib/postgresql/data ports: - - '0.0.0.0:5432:5432' + - "5432:5432" healthcheck: - test: ['CMD-SHELL', 'pg_isready -h 127.0.0.1 -p 5432 -U ${POSTGRES_USER} -d ${POSTGRES_DB}'] + test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -p 5432 -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] interval: 5s timeout: 3s retries: 5 @@ -52,7 +50,7 @@ services: container_name: fyp-redis-dev image: redis:7-alpine ports: - - '0.0.0.0:6379:6379' + - "6379:6379" volumes: - fyp_redis_data:/data healthcheck: @@ -66,8 +64,7 @@ services: build: context: ../../ dockerfile: compose/dev/celery/Dockerfile - env_file: - - ../../.env + env_file: ../../.env volumes: - ../../:/app depends_on: @@ -75,22 +72,18 @@ services: condition: service_healthy fyp-postgres-dev: condition: service_healthy - fyp-inference-dev: container_name: fyp-inference-dev build: context: ../../ dockerfile: compose/dev/inference/Dockerfile - env_file: - - ../../.env + env_file: ../../.env volumes: - ../../:/app - ../../models:/app/models - hf_cache:/root/.cache/huggingface deploy: - mode: replicated - replicas: 1 resources: reservations: devices: @@ -104,15 +97,14 @@ services: - HF_HOME=/root/.cache/huggingface - HF_HUB_OFFLINE=1 ports: - - "0.0.0.0:8001:8001" + - "8001:8001" depends_on: fyp-redis-dev: condition: service_healthy fyp-postgres-dev: condition: service_healthy - volumes: fyp_postgres_data: fyp_redis_data: - hf_cache: \ No newline at end of file + hf_cache: diff --git a/compose/prod/django/start b/compose/prod/django/start new file mode 100644 index 0000000..ce1e1a9 --- /dev/null +++ b/compose/prod/django/start @@ -0,0 +1,27 @@ +#!/bin/bash + +set -o errexit +set -o pipefail +set -o nounset + +DB_HOST="${POSTGRES_HOST}" +DB_PORT="${POSTGRES_PORT}" + +echo "Waiting for database at ${DB_HOST}:${DB_PORT}..." +wait-for-it ${DB_HOST}:${DB_PORT} --timeout=30 --strict || { + echo "Timed out waiting for database" >&2 + exit 1 +} + +echo "Database is available, continuing startup..." + +python manage.py makemigrations +python manage.py migrate --noinput + +for fixture in /app/data/*.json; do + echo "Loading fixture: $fixture" + python manage.py loaddata "$fixture" +done + +python manage.py collectstatic --noinput +exec daphne -b 0.0.0.0 -p 8000 config.asgi:application diff --git a/compose/prod/docker-compose.inference.yml b/compose/prod/docker-compose.inference.yml index e06df96..3a04c33 100644 --- a/compose/prod/docker-compose.inference.yml +++ b/compose/prod/docker-compose.inference.yml @@ -6,8 +6,6 @@ services: dockerfile: compose/dev/inference/Dockerfile restart: unless-stopped deploy: - mode: replicated - replicas: 1 resources: reservations: devices: @@ -20,6 +18,10 @@ services: - INFERENCE_HTTP_HOST=0.0.0.0 - INFERENCE_HTTP_PORT=8001 - NVIDIA_VISIBLE_DEVICES=all + - WATCHFILES_FORCE_POLLING=true + - PYTHONPATH=/app + - HF_HOME=/root/.cache/huggingface + - HF_HUB_OFFLINE=1 ports: - '0.0.0.0:58001:8001' volumes: