From 30725422f4627c39485b153d8d443cc20c2e575d Mon Sep 17 00:00:00 2001 From: MingxuanGame Date: Sun, 10 Aug 2025 11:03:20 +0000 Subject: [PATCH] deploy(docker): optimize size --- .dockerignore | 4 ++++ Dockerfile | 34 ++++++++++++++++++++++------------ Dockerfile-osurx | 35 ++++++++++++++++++++++------------- docker-compose-osurx.yml | 2 ++ docker-compose.yml | 2 ++ 5 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9a41bcf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.venv/ +.ruff_cache/ +.vscode/ +replays/ diff --git a/Dockerfile b/Dockerfile index 13e59dd..3e9823a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 -RUN apt-get update && apt-get install -y \ - gcc \ - pkg-config \ - default-libmysqlclient-dev \ - curl \ - netcat-openbsd \ - && rm -rf /var/lib/apt/lists/* +RUN apt-get update \ + && apt-get install -y gcc pkg-config default-libmysqlclient-dev \ + && rm -rf /var/lib/apt/lists/* \ + && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -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 PYTHONDONTWRITEBYTECODE=1 @@ -21,11 +17,25 @@ COPY pyproject.toml uv.lock ./ COPY packages/ ./packages/ RUN uv sync --frozen --no-dev - RUN uv pip install rosu-pp-py 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 RUN chmod +x /app/docker-entrypoint.sh diff --git a/Dockerfile-osurx b/Dockerfile-osurx index d30cd09..f64272f 100644 --- a/Dockerfile-osurx +++ b/Dockerfile-osurx @@ -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 -RUN apt-get update && apt-get install -y \ - gcc \ - pkg-config \ - default-libmysqlclient-dev \ - curl \ - netcat-openbsd \ - git \ - && rm -rf /var/lib/apt/lists/* +RUN apt-get update \ + && apt-get install -y gcc pkg-config default-libmysqlclient-dev git \ + && rm -rf /var/lib/apt/lists/* \ + && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -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 PYTHONDONTWRITEBYTECODE=1 @@ -22,11 +17,25 @@ COPY pyproject.toml uv.lock ./ COPY packages/ ./packages/ RUN uv sync --frozen --no-dev - RUN uv pip install git+https://github.com/ppy-sb/rosu-pp-py.git 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 RUN chmod +x /app/docker-entrypoint.sh diff --git a/docker-compose-osurx.yml b/docker-compose-osurx.yml index 159b7da..e2f5bbc 100644 --- a/docker-compose-osurx.yml +++ b/docker-compose-osurx.yml @@ -2,6 +2,8 @@ version: '3.8' services: app: + # or use + # image: mingxuangame/osu-lazer-api-osurx:latest build: context: . dockerfile: Dockerfile-osurx diff --git a/docker-compose.yml b/docker-compose.yml index 9a6f2cb..8e2e181 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,8 @@ version: '3.8' services: app: + # or use + # image: mingxuangame/osu-lazer-api:latest build: context: . dockerfile: Dockerfile