From b6e1d39132102f334ccef8ac0335776f9a8c9187 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Thu, 28 May 2026 09:22:33 +0545 Subject: [PATCH] feat(src/djinit/templates/project): add Dockerfile and dockerignore templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce Dockerfile and dockerignore templates to scaffold Docker‑ready Django projects, providing conditional system‑level dependencies for databases and optional Tailwind support, and a comprehensive ignore list for generated projects. - New Features - Dockerfile template with conditional apt packages for MySQL or PostgreSQL, and optional Tailwind installation. - dockerignore template covering Python bytecode, virtual environments, OS artifacts, Django static/media files, and common VCS files. - Enhancements - Expand project scaffolding to include ready‑to‑use container configuration files. --- src/djinit/templates/project/Dockerfile-tpl | 44 +++++++++++++++++++ src/djinit/templates/project/dockerignore-tpl | 26 +++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/djinit/templates/project/Dockerfile-tpl create mode 100644 src/djinit/templates/project/dockerignore-tpl diff --git a/src/djinit/templates/project/Dockerfile-tpl b/src/djinit/templates/project/Dockerfile-tpl new file mode 100644 index 0000000..d61ebe4 --- /dev/null +++ b/src/djinit/templates/project/Dockerfile-tpl @@ -0,0 +1,44 @@ +FROM python:3.13-slim + +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 +ENV PIP_NO_CACHE_DIR=1 +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 + +WORKDIR /app + +# @IF database_type == 'mysql' +RUN apt-get update && apt-get install -y --no-install-recommends \ + default-libmysqlclient-dev \ + build-essential \ + && rm -rf /var/lib/apt/lists/* +# @ELSE +RUN apt-get update && apt-get install -y --no-install-recommends \ + libpq-dev \ + && rm -rf /var/lib/apt/lists/* +# @ENDIF + +# @IF use_tailwind +RUN apt-get update && apt-get install -y --no-install-recommends \ + curl \ + && rm -rf /var/lib/apt/lists/* +ENV NODE_VERSION=20 +RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - \ + && apt-get install -y nodejs \ + && rm -rf /var/lib/apt/lists/* +# @ENDIF + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# @IF use_tailwind +RUN python manage.py tailwind install +# @ENDIF + +COPY . . + +RUN python manage.py collectstatic --noinput || true + +EXPOSE 8000 + +CMD ["gunicorn", "[[ module_name ]].wsgi:application", "--bind", "0.0.0.0:8000"] \ No newline at end of file diff --git a/src/djinit/templates/project/dockerignore-tpl b/src/djinit/templates/project/dockerignore-tpl new file mode 100644 index 0000000..505d698 --- /dev/null +++ b/src/djinit/templates/project/dockerignore-tpl @@ -0,0 +1,26 @@ +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +*.so +.venv +venv +ENV +.env +.git +.gitignore +*.md +README* +LICENSE +.coverage +htmlcov +.pytest_cache +.mypy_cache +.ruff_cache +.DS_Store +node_modules +*.log +db.sqlite3 +media +staticfiles \ No newline at end of file