django_docker_config= """
# define an alias for the specific python version used in this file.
FROM docker.io/python:3.12.8-slim-bookworm AS python

# Python build stage
FROM python AS python-build-stage

ARG BUILD_ENVIRONMENT=local

# Install apt packages
RUN apt-get update && apt-get install --no-install-recommends -y \\
  # dependencies for building Python packages
  build-essential \\
  # psycopg dependencies
  libpq-dev \\
  # netcat for entrypoint script
  netcat

# Copy the requirements file
COPY ./src/django_requirements.txt /app/django_requirements.txt

# Install Python dependencies
RUN pip install -r /app/django_requirements.txt

# Create Python Dependency and Sub-Dependency Wheels.
RUN pip wheel --wheel-dir /usr/src/app/wheels  \\
  -r /app/django_requirements.txt

# Python 'run' stage
FROM python AS python-run-stage

ARG BUILD_ENVIRONMENT=local
ARG APP_HOME=/app

# Copy the wheels and install them
COPY --from=python-build-stage /usr/src/app/wheels /wheels
RUN pip install --no-index --find-links=/wheels -r /app/django_requirements.txt

# Set the working directory
WORKDIR ${APP_HOME}

# Copy the application code
COPY . ${APP_HOME}

# Set the entrypoint
COPY ./compose/local/django/entrypoint /entrypoint
RUN sed -i 's/\\r$//g' /entrypoint
RUN chmod +x /entrypoint

COPY ./compose/local/django/start /start
RUN sed -i 's/\\r$//g' /start
RUN chmod +x /start

COPY ./compose/local/django/celery/worker/start /start-celeryworker
RUN sed -i 's/\\r$//g' /start-celeryworker
RUN chmod +x /start-celeryworker

COPY ./compose/local/django/celery/beat/start /start-celerybeat
RUN sed -i 's/\\r$//g' /start-celerybeat
RUN chmod +x /start-celerybeat

WORKDIR /app

ENTRYPOINT ["/entrypoint"]

# Default command
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
"""

postgres_docker_config= """
FROM postgres:16
COPY ./compose/local/postgres/maintenance /usr/local/bin/maintenance
RUN chmod +x /usr/local/bin/maintenance
    """

local_yml_docker_config= """
    version: '3'

    services:
    django:
        build:
        context: .
        dockerfile: ./compose/local/django/Dockerfile
        image: local_django
        container_name: django
        depends_on:
        - postgres
        - redis
        volumes:
        - .:/app:z
        env_file:
        - ./.envs/.local/.django
        - ./.envs/.local/.postgres
        ports:
        - "8000:8000"
        command: /start

    postgres:
        build:
        context: .
        dockerfile: ./compose/local/postgres/Dockerfile
        image: local_postgres
        container_name: postgres
        volumes:
        - local_postgres_data:/var/lib/postgresql/data
        - local_postgres_data_backups:/backups
        env_file:
        - ./.envs/.local/.postgres

    redis:
        image: redis:6
        container_name: redis

    celeryworker:
        build:
        context: .
        dockerfile: ./compose/local/django/Dockerfile
        image: local_celeryworker
        container_name: celeryworker
        depends_on:
        - redis
        - postgres
        volumes:
        - .:/app:z
        env_file:
        - ./.envs/.local/.django
        - ./.envs/.local/.postgres
        command: /start-celeryworker

    celerybeat:
        build:
        context: .
        dockerfile: ./compose/local/django/Dockerfile
        image: local_celerybeat
        container_name: celerybeat
        depends_on:
        - redis
        - postgres
        volumes:
        - .:/app:z
        env_file:
        - ./.envs/.local/.django
        - ./.envs/.local/.postgres
        command: /start-celerybeat

    flower:
        build:
        context: .
        dockerfile: ./compose/local/django/Dockerfile
        image: local_flower
        container_name: flower
        ports:
        - "5555:5555"
        env_file:
        - ./.envs/.local/.django
        command: celery flower

    mailpit:
        image: axllent/mailpit:latest
        container_name: mailpit
        ports:
        - "8025:8025"
        - "1025:1025"

    volumes:
    local_postgres_data: {}
    local_postgres_data_backups: {}
    """

production_yml_docker_config= """
    version: '3'

    services:
    django:
        build:
        context: .
        dockerfile: ./compose/production/django/Dockerfile
        image: production_django
        depends_on:
        - postgres
        - redis
        env_file:
        - ./.envs/.production/.django
        - ./.envs/.production/.postgres
        command: /start

    postgres:
        build:
        context: .
        dockerfile: ./compose/production/postgres/Dockerfile
        image: production_postgres
        volumes:
        - production_postgres_data:/var/lib/postgresql/data
        - production_postgres_data_backups:/backups
        env_file:
        - ./.envs/.production/.postgres

    redis:
        image: redis:6

    celeryworker:
        build:
        context: .
        dockerfile: ./compose/production/django/Dockerfile
        image: production_celeryworker
        depends_on:
        - redis
        - postgres
        env_file:
        - ./.envs/.production/.django
        - ./.envs/.production/.postgres
        command: /start-celeryworker

    celerybeat:
        build:
        context: .
        dockerfile: ./compose/production/django/Dockerfile
        image: production_celerybeat
        depends_on:
        - redis
        - postgres
        env_file:
        - ./.envs/.production/.django
        - ./.envs/.production/.postgres
        command: /start-celerybeat

    traefik:
        build:
        context: .
        dockerfile: ./compose/production/traefik/Dockerfile
        image: production_traefik
        depends_on:
        - django
        volumes:
        - production_traefik:/etc/traefik/acme:z
        ports:
        - "0.0.0.0:80:80"
        - "0.0.0.0:443:443"

    volumes:
    production_postgres_data: {}
    production_postgres_data_backups: {}
    production_traefik: {}
    """