Search code examples
dockergoogle-cloud-rungoogle-cloud-buildstreamlitpython-poetry

Streamlit with Poetry running in Docker locally but not on Cloud Run


I encountered that I was able to run the Dockerfile below on my local device without any issues, but on Cloud Run it fails with the following error in the logs:

enter image description here

The Dockerfile looks like this:

FROM debian:stable-slim

WORKDIR /root
RUN apt-get update && apt-get upgrade -y && apt-get install -y curl python3 python3-dev python3-venv build-essential \
  libgmp3-dev && curl -sSL https://install.python-poetry.org | python3 -
ADD poetry.lock .
ADD pyproject.toml .
ADD main.py .
ENV PATH "/root/.local/bin:$PATH"
RUN poetry install -vvv
ENV STREAMLIT_SERVER_PORT 8080
RUN poetry run echo $PATH
RUN poetry run which python
RUN poetry run which streamlit
CMD ["poetry", "run", "streamlit", "run", "main.py"]

I was expecting Docker to ensure the same execution environment locally and on Cloud Run.

In addition the echo $PATH / which python / which streamlit commands return similar things locally and on Cloud Build.

Locally I get:

Step 10/13 : RUN poetry run echo $PATH
 ---> Running in 1e00651356b2
/root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Removing intermediate container 1e00651356b2
 ---> bd9b9acd4152
Step 11/13 : RUN poetry run which python
 ---> Running in 58b5348154a1
/root/.cache/pypoetry/virtualenvs/eso-website-lKa0R1gD-py3.9/bin/python
Removing intermediate container 58b5348154a1
 ---> d3a8588626f0
Step 12/13 : RUN poetry run which streamlit
 ---> Running in 72ea21408e0c
/root/.cache/pypoetry/virtualenvs/eso-website-lKa0R1gD-py3.9/bin/streamlit
Removing intermediate container 72ea21408e0c
 ---> 3f7fa5ded8ec
Step 13/13 : CMD ["poetry", "run", "streamlit", "run", "main.py"]
 ---> Running in ea06f67b0930
Removing intermediate container ea06f67b0930
 ---> ae2349318933
Successfully built ae2349318933
Successfully tagged esoapp:latest

In Cloud Build I see:
Step #0: INFO[0026] RUN poetry run echo $PATH                    
Step #0: INFO[0026] Taking snapshot of full filesystem...        
Step #0: INFO[0034] cmd: /bin/sh                                 
Step #0: INFO[0034] args: [-c poetry run echo $PATH]             
Step #0: INFO[0034] Running: [/bin/sh -c poetry run echo $PATH]  
Step #0: /root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Step #0: INFO[0035] Taking snapshot of full filesystem...        
Step #0: INFO[0036] No files were changed, appending empty layer to config. No layer added to image. 
Step #0: INFO[0036] RUN poetry run which python                  
Step #0: INFO[0036] cmd: /bin/sh                                 
Step #0: INFO[0036] args: [-c poetry run which python]           
Step #0: INFO[0036] Running: [/bin/sh -c poetry run which python] 
Step #0: INFO[0036] Pushing layer gcr.io/personal-313102/eso-app/cache:88561d733a1fd5ca03e6481ff992723526198d61ba0abe93ab912eaa155da06a to cache now 
Step #0: INFO[0036] Pushing image to gcr.io/personal-313102/eso-app/cache:88561d733a1fd5ca03e6481ff992723526198d61ba0abe93ab912eaa155da06a 
Step #0: /root/.cache/pypoetry/virtualenvs/eso-website-lKa0R1gD-py3.9/bin/python
Step #0: INFO[0037] Taking snapshot of full filesystem...        
Step #0: INFO[0038] No files were changed, appending empty layer to config. No layer added to image. 
Step #0: INFO[0038] RUN poetry run which streamlit               
Step #0: INFO[0038] cmd: /bin/sh                                 
Step #0: INFO[0038] args: [-c poetry run which streamlit]        
Step #0: INFO[0038] Running: [/bin/sh -c poetry run which streamlit] 
Step #0: INFO[0038] Pushing layer gcr.io/personal-313102/eso-app/cache:498bfad933dca72234af0985b0ed384effed32958351e5727a4cbc56a2670d13 to cache now 
Step #0: INFO[0038] Pushing image to gcr.io/personal-313102/eso-app/cache:498bfad933dca72234af0985b0ed384effed32958351e5727a4cbc56a2670d13 
Step #0: INFO[0038] Pushed gcr.io/personal-313102/eso-app/cache@sha256:32f47b0699c392a7be4e8243545975348475956e35fd51347348168a07a714db 
Step #0: /root/.cache/pypoetry/virtualenvs/eso-website-lKa0R1gD-py3.9/bin/streamlit
Step #0: INFO[0038] Taking snapshot of full filesystem...        
Step #0: INFO[0040] No files were changed, appending empty layer to config. No layer added to image. 
Step #0: INFO[0040] CMD ["poetry", "run", "streamlit", "run", "main.py"] 
Step #0: INFO[0040] No files changed in this command, skipping snapshotting. 
Step #0: INFO[0040] Pushing layer gcr.io/personal-313102/eso-app/cache:7a16d1344c60a8740190534cfa44fed333547d60231720fcea3820ebd42ecf87 to cache now 
Step #0: INFO[0040] Pushing image to gcr.io/personal-313102/eso-app/cache:7a16d1344c60a8740190534cfa44fed333547d60231720fcea3820ebd42ecf87 
Step #0: INFO[0040] Pushed gcr.io/personal-313102/eso-app/cache@sha256:c4e57c77bd9dccfbbe3aca001bdf3fc26bccca20ed2879fc143a91ccdbee895a 
Step #0: INFO[0041] Pushed gcr.io/personal-313102/eso-app/cache@sha256:4198599d679af55fda0cf5cc8407bac0eb0ddb110e1e503a06663df9947523a6 
Step #0: INFO[0041] Pushing image to gcr.io/personal-313102/eso-app:0a1bd22ce692a52f231221778abea5561ac736e7 
Step #0: INFO[0043] Pushed gcr.io/personal-313102/eso-app@sha256:72473a2099329f7a4fb2a5933c7d3c749906840b27967752d06c24ca3f71acc5 
Finished Step #0
Starting Step #1

Any ideas on why the streamlit binary cannot be found in Cloud Run?


Solution

  • Digging further into this myself, I discovered that the home directory was confused in Cloud Run.

    This is apparently a known issue -> https://cloud.google.com/run/docs/issues#home

    It was solved by changing the CMD command in the Dockerfile to CMD HOME=/root poetry run streamlit run main.py