Skip to content

Commit

Permalink
Fix cloud backend dockerfile build (#415)
Browse files Browse the repository at this point in the history
- Install rust dependencies
- Use multi-stage build
  • Loading branch information
DMalone87 authored Nov 4, 2024
1 parent b49b4b3 commit 5490468
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions backend/Dockerfile.cloud
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

0 comments on commit 5490468

Please sign in to comment.