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
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

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
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

View File

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

View File

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