-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (42 loc) · 1.74 KB
/
Copy pathDockerfile
File metadata and controls
51 lines (42 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# ---- Stage 0: Build MozJPEG from source ----
FROM debian:bookworm-slim AS mozjpeg-builder
RUN apt-get update && apt-get install -y --no-install-recommends \
cmake nasm build-essential curl ca-certificates \
&& rm -rf /var/lib/apt/lists/*
ARG MOZJPEG_VERSION=4.1.5
RUN curl -L https://github.com/mozilla/mozjpeg/archive/refs/tags/v${MOZJPEG_VERSION}.tar.gz \
| tar xz \
&& cd mozjpeg-${MOZJPEG_VERSION} \
&& mkdir build && cd build \
&& cmake -DCMAKE_INSTALL_PREFIX=/opt/mozjpeg \
-DENABLE_SHARED=OFF \
-DENABLE_STATIC=ON \
-DPNG_SUPPORTED=OFF \
.. \
&& make -j$(nproc) \
&& make install
# ---- Stage 1: Production image ----
FROM python:3.12-slim
LABEL org.opencontainers.image.source="https://github.com/amitray007/pare"
LABEL org.opencontainers.image.description="Serverless image compression API"
LABEL org.opencontainers.image.licenses="MIT"
# Copy MozJPEG binaries (jpegtran always needed; cjpeg for JPEG_ENCODER=cjpeg fallback)
COPY --from=mozjpeg-builder /opt/mozjpeg/bin/cjpeg /usr/local/bin/cjpeg
COPY --from=mozjpeg-builder /opt/mozjpeg/bin/jpegtran /usr/local/bin/jpegtran
# Install system compression tools + codec libraries
RUN apt-get update && apt-get install -y --no-install-recommends \
pngquant \
gifsicle \
libheif1 \
libde265-0 \
libaom3 \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application
COPY . /app
WORKDIR /app
# Cloud Run sets $PORT; Uvicorn workers configurable
CMD ["sh", "-c", \
"uvicorn main:app --host 0.0.0.0 --port ${PORT:-8080} --workers ${WORKERS:-1} --timeout-graceful-shutdown ${GRACEFUL_SHUTDOWN_TIMEOUT:-30}"]