feat: Shrink docker file
This commit is contained in:
18
.dockerignore
Normal file
18
.dockerignore
Normal file
@@ -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
|
||||||
41
Dockerfile
41
Dockerfile
@@ -1,31 +1,32 @@
|
|||||||
FROM --platform=$BUILDPLATFORM python:3.13-alpine
|
### Build stage ###
|
||||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
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
|
WORKDIR /app
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||||
--mount=type=bind,source=uv.lock,target=uv.lock \
|
--mount=type=bind,source=uv.lock,target=uv.lock \
|
||||||
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
|
--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
|
### Runtime stage ###
|
||||||
ADD . /app
|
FROM python:3.13-alpine AS runtime
|
||||||
|
ENV PATH="/app/.venv/bin:$PATH"
|
||||||
|
|
||||||
# Sync the project
|
# Install curl for healthchecks
|
||||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
RUN apk add --no-cache curl
|
||||||
uv sync --locked
|
WORKDIR /app
|
||||||
|
|
||||||
# Add mount point for data volume
|
# Copy the virtual environment from build stage
|
||||||
ENV BASE_DIR=/data
|
COPY --from=build /app/.venv /app/.venv
|
||||||
VOLUME /data
|
|
||||||
|
# Copy all top-level Python files
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
# Optional mount for data
|
||||||
|
#ENV BASE_DIR=/data
|
||||||
|
#VOLUME /data
|
||||||
|
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
|
|
||||||
|
ENTRYPOINT ["python3", "main.py"]
|
||||||
ENTRYPOINT ["uv", "run"]
|
|
||||||
CMD ["main.py"]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user