I have a Dockerfile, shown below:
FROM --platform=linux/amd64 prefecthq/prefect:2-python3.12
RUN apt-get update && apt-get -y install libpq-dev gcc
RUN pip install --upgrade pip
RUN pip install pipenv
ENV PREFECT_API_URL="foo"
ENV PREFECT_API_KEY="bar"
WORKDIR /app
COPY Pipfile Pipfile
COPY Pipfile.lock Pipfile.lock
RUN pipenv install --deploy --ignore-pipfile
COPY . .
CMD ["pipenv", "run", "python", "src/cdk_flow/cdk_delta_flow.py"]
This file builds and runs successfully locally, but when pushing it to Google Cloud Run (using Prefect to push it), it fails to run with the following error.
Traceback (most recent call last):
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/app/src/cdk_flow/cdk_delta_flow.py", line 7, in <module>
from src.cdk_flow.cdk_common_tasks import (
File "/app/src/cdk_flow/cdk_common_tasks.py", line 3, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
Why would the Dockerfile run locally but fail to find a module on Google Cloud Run
Running
Pipenvinside a Dockerfile doesn't play nicely with Google Cloud Run. In order to avoid a module not found error we must declareENV PIPENV_VENV_IN_PROJECT 1in our Dockerfile. More detail in this thread