refactor(environment): update virtualenv path to /opt/venv in Docker setup

- Adjusted `docker-compose.dev.yml` to reflect the new venv location.
- Modified entrypoint script and Dockerfile to reference `/opt/venv` for isolated dependencies.
- Improved bind mount setup to prevent venv overwrites during development.
This commit is contained in:
2026-01-04 00:58:24 +01:00
parent d0fc7f37ff
commit ca5f5e3383
3 changed files with 18 additions and 17 deletions

View File

@@ -7,7 +7,10 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=/app \
UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_NO_CACHE=1
UV_NO_CACHE=1 \
UV_PROJECT_ENVIRONMENT=/opt/venv \
VIRTUAL_ENV=/opt/venv \
PATH="/opt/venv/bin:$PATH"
# Install system dependencies and uv
RUN apt-get update && \
@@ -20,7 +23,7 @@ RUN apt-get update && \
# Copy dependency files
COPY pyproject.toml uv.lock ./
# Install dependencies using uv (development mode with dev dependencies)
# Install dependencies using uv into /opt/venv (outside /app to survive bind mounts)
RUN uv sync --extra dev --frozen
# Copy application code
@@ -45,7 +48,10 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=/app \
UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_NO_CACHE=1
UV_NO_CACHE=1 \
UV_PROJECT_ENVIRONMENT=/opt/venv \
VIRTUAL_ENV=/opt/venv \
PATH="/opt/venv/bin:$PATH"
# Install system dependencies and uv
RUN apt-get update && \
@@ -58,7 +64,7 @@ RUN apt-get update && \
# Copy dependency files
COPY pyproject.toml uv.lock ./
# Install only production dependencies using uv (no dev dependencies)
# Install only production dependencies using uv into /opt/venv
RUN uv sync --frozen --no-dev
# Copy application code
@@ -67,7 +73,7 @@ COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
# Set ownership to non-root user
RUN chown -R appuser:appuser /app
RUN chown -R appuser:appuser /app /opt/venv
# Switch to non-root user
USER appuser
@@ -77,4 +83,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["uv", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]