diff --git a/compose/dev/django/Dockerfile b/compose/dev/django/Dockerfile new file mode 100644 index 0000000..74b4373 --- /dev/null +++ b/compose/dev/django/Dockerfile @@ -0,0 +1,23 @@ +FROM python:3.12-bookworm + +RUN apt-get update && apt-get install --no-install-recommends -y \ + build-essential \ + libpq-dev \ + wait-for-it \ + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ + && rm -rf /var/lib/apt/lists/* + +ENV VIRTUAL_ENV=/venv \ + PATH=/venv/bin:$PATH + +RUN python -m venv /venv + +WORKDIR /app + +COPY requirements/django.txt . +RUN pip install --no-cache-dir --requirement django.txt + +COPY ./compose/dev/django/start /start +RUN sed -i 's/\r$//g' /start && chmod +x /start + +CMD ["/start"] \ No newline at end of file diff --git a/compose/dev/django/start b/compose/dev/django/start new file mode 100644 index 0000000..ce1e1a9 --- /dev/null +++ b/compose/dev/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/dev/docker-compose.yml b/compose/dev/docker-compose.yml new file mode 100644 index 0000000..a337dff --- /dev/null +++ b/compose/dev/docker-compose.yml @@ -0,0 +1,59 @@ +services: + fyp-django: + container_name: fyp-django-dev + build: + context: ../../ + dockerfile: compose/dev/django/Dockerfile + env_file: + - ../../.env + volumes: + - ../../:/app + ports: + - '0.0.0.0:8000:8000' + depends_on: + fyp-postgres-dev: + condition: service_healthy + fyp-node-dev: + condition: service_started + + fyp-node-dev: + container_name: fyp-node-dev + build: + context: ../../ + dockerfile: compose/dev/node/Dockerfile + environment: + NODE_ENV: development + CHOKIDAR_USEPOLLING: 'true' + stdin_open: true + volumes: + - ../../src:/app/src:delegated + - ../../index.html:/app/index.html:delegated + - ../../vite.config.ts:/app/vite.config.ts:delegated + - ../../tsconfig.json:/app/tsconfig.json:delegated + - ../../build:/app/build:delegated + - ../../package.json:/app/package.json:delegated + - ../../package-lock.json:/app/package-lock.json:delegated + - /app/node_modules + ports: + - '0.0.0.0:5173:5173' + + fyp-postgres-dev: + container_name: fyp-postgres-dev + image: postgres:15-alpine + env_file: + - ../../.env + environment: + POSTGRES_HOST_AUTH_METHOD: trust + volumes: + - postgres_data:/var/lib/postgresql/data + ports: + - '0.0.0.0:5432:5432' + healthcheck: + test: ['CMD-SHELL', "pg_isready -h 127.0.0.1 -p 5432 -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] + interval: 5s + timeout: 3s + retries: 5 + +volumes: + postgres_data: + \ No newline at end of file diff --git a/compose/dev/node/Dockerfile b/compose/dev/node/Dockerfile new file mode 100644 index 0000000..bff1b3c --- /dev/null +++ b/compose/dev/node/Dockerfile @@ -0,0 +1,15 @@ +FROM node:22-bullseye + +WORKDIR /app + +COPY package*.json ./ +RUN npm ci && npm cache clean --force + +COPY src ./src +COPY index.html . +COPY vite.config.* . +COPY tsconfig.* . + +EXPOSE 5173 + +CMD ["npm", "run", "devwatch"] \ No newline at end of file