diff --git a/.dockerignore b/.dockerignore index f1e12e7..72d8320 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,21 +1,81 @@ -# repo and project folders -.devcontainer -.docs +# Version control .git -.github .gitignore -.gitmodules -.idea -.vscode - -# docker -Dockerfile -.dockerignore -docker-compose.yaml - -# python related -.pyright_cache -.pytest_cache +.gitattributes + +# Development containers +.devcontainer/ +.vscode/ + +# Documentation +docs/ +*.txt + +# Python cache and temporary files +__pycache__/ *.pyc *.pyo *.pyd +.Python +.pytest_cache/ +.coverage +.coverage.* +.cache +.mypy_cache/ +.ruff_cache/ +.dmypy.json +dmypy.json + +# Virtual environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Build artifacts +build/ +dist/ +*.egg-info/ +.eggs/ + +# IDE files +.idea/ +.vscode/ +*.swp +*.swo +*~ + +# OS files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Scripts (if not needed in container) +scripts/ + +# Log files +*.log +logs/ + +# Temporary files +tmp/ +temp/ +.tmp/ +.temp/ + +# Test artifacts +.tox/ +.nox/ +htmlcov/ +.coverage +coverage.xml +*.cover +*.py,cover +.hypothesis/ diff --git a/Dockerfile b/Dockerfile index 9474b39..937f763 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,11 +7,13 @@ ARG USER=appuser ENV RUNTIME_PACKAGES=libpq-dev # These packages will be deleted from the final image, after the application is packaged -ENV BUILD_PACKAGES=gcc +ENV BUILD_PACKAGES="gcc build-essential python3-dev" RUN apt-get update \ - && apt-get install -y ${BUILD_PACKAGES} ${RUNTIME_PACKAGES} \ - && apt-get clean && rm -rf /var/lib/apt/lists/* + && apt-get install -y --no-install-recommends ${BUILD_PACKAGES} ${RUNTIME_PACKAGES} \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && rm -rf /tmp/* /var/tmp/* RUN mkdir -p /opt/app/${PROJECT_NAME} @@ -32,15 +34,20 @@ RUN pip install --upgrade pip \ && pip install --user uv==${UV_VERSION} WORKDIR /opt/app/${PROJECT_NAME} -COPY --chown=${USER}:${USER} . . +# Only copy files needed to install dependencies so it can be cached +# (changes to source files won't invalidate cache at this point) +COPY --chown=${USER}:${USER} pyproject.toml uv.lock ./ RUN uv sync --frozen --no-cache --no-install-project --no-default-groups +# Then copy the rest of the application +COPY --chown=${USER}:${USER} . . # ---- # Devcontainer adds extra tools for development FROM base AS devcontainer +ARG USER=appuser USER root # Add any other tool usefull during development to the following list, this won't be included @@ -80,6 +87,8 @@ RUN uv build --wheel # Deployment stage to run in cloud environments. This must be the last stage, which is used to run the application by default FROM base AS deployment +ARG PROJECT_NAME=python-template + # root is needed to remove build dependencies USER root RUN apt-get purge -y ${BUILD_PACKAGES} \