diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eb291ef --- /dev/null +++ b/.dockerignore @@ -0,0 +1,18 @@ +# Ignore text files +*.txt +*.md +LICENSE + +# UV/Python virtual env files +.venv/ +.python-version + +# Git +.git/ +.gitignore +.gitea/ +.pre-commit-config.yaml + +# Docker build files +Dockerfile +.dockerignore diff --git a/Dockerfile b/Dockerfile index 2417c9b..c310c2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,32 @@ -FROM --platform=$BUILDPLATFORM python:3.13-alpine -COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ +### Build stage ### +FROM python:3.13-alpine AS build +COPY --from=ghcr.io/astral-sh/uv:0.8.21 /uv /uvx /bin/ +ENV UV_PROJECT_ENVIRONMENT=/app/.venv -# Install curl for healthcheck -RUN apk add --no-cache curl - -# Set working directory WORKDIR /app - -# Install dependencies RUN --mount=type=cache,target=/root/.cache/uv \ --mount=type=bind,source=uv.lock,target=uv.lock \ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ - uv sync --locked --no-install-project + uv sync --frozen --no-dev --no-install-workspace -# Copy the project into the image -ADD . /app +### Runtime stage ### +FROM python:3.13-alpine AS runtime +ENV PATH="/app/.venv/bin:$PATH" -# Sync the project -RUN --mount=type=cache,target=/root/.cache/uv \ - uv sync --locked +# Install curl for healthchecks +RUN apk add --no-cache curl +WORKDIR /app -# Add mount point for data volume -ENV BASE_DIR=/data -VOLUME /data +# Copy the virtual environment from build stage +COPY --from=build /app/.venv /app/.venv + +# Copy all top-level Python files +COPY . /app + +# Optional mount for data +#ENV BASE_DIR=/data +#VOLUME /data EXPOSE 5000 - -ENTRYPOINT ["uv", "run"] -CMD ["main.py"] \ No newline at end of file +ENTRYPOINT ["python3", "main.py"]