build(api): implement multi-stage Dockerfile
- Use multi-stage build to reduce final image size - Move build dependencies to builder stage - Copy only necessary files to final stage - Use UV for faster Python package installation - Clean up duplicate operations
This commit is contained in:
parent
51e71a4d52
commit
820bca6308
1 changed files with 13 additions and 12 deletions
|
|
@ -1,8 +1,16 @@
|
||||||
FROM python:3.12-alpine
|
FROM python:3.12-alpine AS builder
|
||||||
LABEL maintainer="Rajesh Rajendran<rjshrjndrn@gmail.com>"
|
LABEL maintainer="Rajesh Rajendran<rjshrjndrn@gmail.com>"
|
||||||
LABEL maintainer="KRAIEM Taha Yassine<tahayk2@gmail.com>"
|
LABEL maintainer="KRAIEM Taha Yassine<tahayk2@gmail.com>"
|
||||||
|
|
||||||
RUN apk add --no-cache build-base=~1.2 tini=~0.19
|
RUN apk add --no-cache build-base
|
||||||
|
WORKDIR /work
|
||||||
|
COPY requirements.txt ./requirements.txt
|
||||||
|
RUN pip install --no-cache-dir --upgrade uv && \
|
||||||
|
export UV_SYSTEM_PYTHON=true && \
|
||||||
|
uv pip install --no-cache-dir --upgrade pip setuptools wheel && \
|
||||||
|
uv pip install --no-cache-dir --upgrade -r requirements.txt
|
||||||
|
|
||||||
|
FROM python:3.12-alpine
|
||||||
ARG GIT_SHA
|
ARG GIT_SHA
|
||||||
ARG envarg
|
ARG envarg
|
||||||
# Add Tini
|
# Add Tini
|
||||||
|
|
@ -13,18 +21,11 @@ ENV SOURCE_MAP_VERSION=0.7.4 \
|
||||||
PRIVATE_ENDPOINTS=false \
|
PRIVATE_ENDPOINTS=false \
|
||||||
ENTERPRISE_BUILD=${envarg} \
|
ENTERPRISE_BUILD=${envarg} \
|
||||||
GIT_SHA=$GIT_SHA
|
GIT_SHA=$GIT_SHA
|
||||||
|
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
|
||||||
|
COPY --from=builder /usr/local/bin /usr/local/bin
|
||||||
|
RUN apk add --no-cache tini
|
||||||
WORKDIR /work
|
WORKDIR /work
|
||||||
COPY requirements.txt ./requirements.txt
|
|
||||||
RUN pip install --no-cache-dir --upgrade uv && \
|
|
||||||
uv pip install --no-cache-dir --upgrade pip setuptools wheel --system && \
|
|
||||||
uv pip install --no-cache-dir --upgrade -r requirements.txt --system
|
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN mv env.default .env && \
|
|
||||||
adduser -u 1001 openreplay -D
|
|
||||||
USER 1001
|
|
||||||
|
|
||||||
ENTRYPOINT ["/sbin/tini", "--"]
|
ENTRYPOINT ["/sbin/tini", "--"]
|
||||||
CMD ["./entrypoint.sh"]
|
CMD ["./entrypoint.sh"]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue