-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix cloud backend dockerfile build (#415)
- Install rust dependencies - Use multi-stage build
- Loading branch information
Showing
1 changed file
with
39 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,53 @@ | ||
# docker build command: | ||
# docker build -t police-data-trust-backend-dev -f backend/Dockerfile.cloud . | ||
FROM python:3-slim-bookworm | ||
# Stage 1: Build Stage | ||
FROM python:3-slim-bookworm AS build | ||
|
||
# required for pandas | ||
RUN apt-get update -y && apt-get install gcc g++ python3-dev wget -y | ||
# Install required packages | ||
RUN apt-get update -y && apt-get install -y \ | ||
gcc \ | ||
g++ \ | ||
python3-dev \ | ||
wget \ | ||
curl \ | ||
libffi-dev \ | ||
build-essential \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app/ | ||
# Install Rust | ||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ | ||
&& . "$HOME/.cargo/env" | ||
ENV PATH="/root/.cargo/bin:${PATH}" | ||
|
||
ARG NPDI_API_PORT=5000 | ||
WORKDIR /app/ | ||
|
||
COPY requirements/prod.txt . | ||
|
||
SHELL ["/bin/bash", "-o", "pipefail", "-c"] | ||
RUN arch=$(arch) && \ | ||
file=pandas-2.2.2-cp312-cp312-manylinux_2_17_${arch}.manylinux2014_${arch}.whl && \ | ||
url="https://pypi.debian.net/pandas/${file}" && \ | ||
wget ${url} && \ | ||
sed -i "s/pandas==2.2.2/${file}/" prod.txt | ||
RUN pip install --no-cache-dir -r prod.txt | ||
file=pandas-2.2.2-cp312-cp312-manylinux_2_17_${arch}.manylinux2014_${arch}.whl && \ | ||
url="https://pypi.debian.net/pandas/${file}" && \ | ||
wget ${url} && \ | ||
sed -i "s/pandas==2.2.2/${file}/" prod.txt | ||
|
||
RUN pip install --no-cache-dir --user -r prod.txt | ||
|
||
COPY . . | ||
|
||
# Stage 2: Production Image | ||
FROM python:3-slim-bookworm | ||
|
||
WORKDIR /app/ | ||
|
||
ARG NPDI_API_PORT=5000 | ||
|
||
# Copy installed packages from the build stage | ||
COPY --from=build /root/.local /root/.local | ||
|
||
# Update PATH to include pip-installed packages | ||
ENV PATH=/root/.local/bin:${PATH} | ||
|
||
COPY . . | ||
|
||
EXPOSE $NPDI_API_PORT | ||
ENV NPDI_API_PORT=$NPDI_API_PORT | ||
|
||
ENTRYPOINT [ "./run_cloud.sh" ] | ||
# ENV FLASK_ENV=${FLASK_ENV:-development} | ||
# CMD flask run --host=0.0.0.0 |