deploy(docker): optimize size

This commit is contained in:
MingxuanGame
2025-08-10 11:03:20 +00:00
parent 2c872785f6
commit 30725422f4
5 changed files with 52 additions and 25 deletions

4
.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
.venv/
.ruff_cache/
.vscode/
replays/

View File

@@ -1,17 +1,13 @@
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS builder
WORKDIR /app WORKDIR /app
RUN apt-get update && apt-get install -y \ RUN apt-get update \
gcc \ && apt-get install -y gcc pkg-config default-libmysqlclient-dev \
pkg-config \ && rm -rf /var/lib/apt/lists/* \
default-libmysqlclient-dev \ && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
curl \
netcat-openbsd \
&& rm -rf /var/lib/apt/lists/*
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y ENV PATH="/root/.cargo/bin:${PATH}" \
ENV PATH="/root/.cargo/bin:${PATH}" PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 UV_PROJECT_ENVIRONMENT=/app/.venv
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONDONTWRITEBYTECODE=1
@@ -21,11 +17,25 @@ COPY pyproject.toml uv.lock ./
COPY packages/ ./packages/ COPY packages/ ./packages/
RUN uv sync --frozen --no-dev RUN uv sync --frozen --no-dev
RUN uv pip install rosu-pp-py RUN uv pip install rosu-pp-py
COPY . . COPY . .
# ---
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
WORKDIR /app
RUN apt-get update \
&& apt-get install -y curl netcat-openbsd \
&& rm -rf /var/lib/apt/lists/*
ENV PATH="/app/.venv/bin:${PATH}" \
PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
COPY --from=builder /app/.venv /app/.venv
COPY --from=builder /app /app
COPY docker-entrypoint.sh /app/docker-entrypoint.sh COPY docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh RUN chmod +x /app/docker-entrypoint.sh

View File

@@ -1,18 +1,13 @@
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS builder
WORKDIR /app WORKDIR /app
RUN apt-get update && apt-get install -y \ RUN apt-get update \
gcc \ && apt-get install -y gcc pkg-config default-libmysqlclient-dev git \
pkg-config \ && rm -rf /var/lib/apt/lists/* \
default-libmysqlclient-dev \ && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
curl \
netcat-openbsd \
git \
&& rm -rf /var/lib/apt/lists/*
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y ENV PATH="/root/.cargo/bin:${PATH}" \
ENV PATH="/root/.cargo/bin:${PATH}" PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 UV_PROJECT_ENVIRONMENT=/app/.venv
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONDONTWRITEBYTECODE=1
@@ -22,11 +17,25 @@ COPY pyproject.toml uv.lock ./
COPY packages/ ./packages/ COPY packages/ ./packages/
RUN uv sync --frozen --no-dev RUN uv sync --frozen --no-dev
RUN uv pip install git+https://github.com/ppy-sb/rosu-pp-py.git RUN uv pip install git+https://github.com/ppy-sb/rosu-pp-py.git
COPY . . COPY . .
# ---
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
WORKDIR /app
RUN apt-get update \
&& apt-get install -y curl netcat-openbsd \
&& rm -rf /var/lib/apt/lists/*
ENV PATH="/app/.venv/bin:${PATH}" \
PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
COPY --from=builder /app/.venv /app/.venv
COPY --from=builder /app /app
COPY docker-entrypoint.sh /app/docker-entrypoint.sh COPY docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh RUN chmod +x /app/docker-entrypoint.sh

View File

@@ -2,6 +2,8 @@ version: '3.8'
services: services:
app: app:
# or use
# image: mingxuangame/osu-lazer-api-osurx:latest
build: build:
context: . context: .
dockerfile: Dockerfile-osurx dockerfile: Dockerfile-osurx

View File

@@ -2,6 +2,8 @@ version: '3.8'
services: services:
app: app:
# or use
# image: mingxuangame/osu-lazer-api:latest
build: build:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile