From 5f5b30108e5b4ea43b443dc2af7ec2fabaa0c3ab Mon Sep 17 00:00:00 2001 From: jkuijperm Date: Tue, 29 Sep 2026 17:32:21 +0200 Subject: [PATCH] Build: imagen autocontenida, .dockerignore y limpieza de requirements - Dockerfile copia el proyecto Django, no la raiz del repo, para que manage.py y wsgi.py queden donde gunicorn los espera - collectstatic en tiempo de construccion y CMD en la imagen - .dockerignore: evita que .env, .git y artefactos locales entren en la imagen - requirements.txt sin BOM --- .dockerignore | 27 ++++++++++++++++++++++++++ .gitignore | 3 +++ Dockerfile | 31 ++++++++++++++++++++++++++++++ expenses_manager/requirements.txt | Bin 734 -> 345 bytes 4 files changed, 61 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..81e3045 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,27 @@ +# Secrets — these must never end up in an image layer. +.env +db.env +*.env +!.env.example + +# Version control and IDE noise. +.git +.gitignore +.vscode +.idea + +# Local artifacts that would otherwise be copied in by COPY. +__pycache__/ +*.py[cod] +*.bak +venv/ +.venv/ +db.sqlite3 +staticfiles/ +.pytest_cache/ +.coverage +htmlcov/ + +# Documentation and planning, not needed at runtime. +*.md +LICENSE \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1329a83..896191d 100644 --- a/.gitignore +++ b/.gitignore @@ -129,6 +129,7 @@ venv/ ENV/ env.bak/ venv.bak/ +db.env # Spyder project settings .spyderproject @@ -161,3 +162,5 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +staticfiles/ +*.bak \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..08fd0cb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM python:3.11-slim + +# Fail fast and log straight to stdout, so `docker-compose logs` is useful. +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +WORKDIR /app + +# Dependencies first: this layer is cached and only rebuilt when +# requirements.txt changes, not on every code change. +COPY expenses_manager/requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the Django project itself, not the repository root, so that /app is +# the directory holding manage.py. The previous version copied the repo root +# into /app/expenses_manager, which left manage.py and wsgi.py one level +# deeper than the gunicorn command expected. +COPY expenses_manager/ . + +# Collect static files at build time so the running container never needs to +# write to its own filesystem. SECRET_KEY is required by settings.py when +# DEBUG is False, but collectstatic never uses it, so a throwaway value is +# enough — the real one comes from the environment at runtime. +RUN SECRET_KEY=build-time-placeholder \ + DEBUG=False \ + ALLOWED_HOSTS=localhost \ + python manage.py collectstatic --noinput + +EXPOSE 8000 + +CMD ["gunicorn", "expenses_manager.wsgi:application", "--bind", "0.0.0.0:8000"] \ No newline at end of file diff --git a/expenses_manager/requirements.txt b/expenses_manager/requirements.txt index 02e24241c87e385801389cbcf345d28f81440da9..28af1ba28fc49c52f9500bbd499956870cce60a6 100644 GIT binary patch literal 345 zcmX|-O;*Gp5QO*KCH;Ve_-4_rJb*XwVZtzI(nMfJ@$`24x1);U>n?nasf07)2*!X` zOWtzvyGPV8!OZ#=ijM*D4h(11!;7bw5gk}CTE#1+B^N@p4g`=y(>X=#1rU$HSntUI0^In zc36Kmouru&_mXK?a|?8n@yt^7Z99CaTu*}or&``OIUC`&e(>5);e%h)l!@mvOFFdA Y)i?eltGUvs-YzL|0Gs`2qyPW_ literal 734 zcmZ8fQBs326x?rTJPJ&qwvHe6%L8}=2V0D23kVUdhgWxB2%wY6kjZZL?c2xCcYz)b z6*`o7!Y$VtDKf4UD_r6Ndo(z5cPMb;7H38DihDaT2EG@=@hir)sRS*l+~I|2O}sID zLp(Q5sN(QWw6ba)PtwRC*6gI37&X0C)C#QBJO`bYRrYu_C*ntrlp^EET8`^%@1?(8 zpgr%^b349O58Ao)+A^;hPw+?|HLG=_+F$lPZyi%B$?<#{{bsmXD4vOxM7`lcly9sz zqlx(%up>|D$9|TK!@r!x3)9R-|6)J0zZwY+{Hk`1Vag&*MKkO1#>p$uj^{8}Ia8J! zQ}cX(B1e4*$rjE%dv7frhX=m?94qy_Q}vKW@HbD#JjNQ!)GpYpeJ{@71W( P@DzP%f*F}H75V=KU?Xd?