Storage bucket calling problem in cloud run, flask app with docker

34 Views Asked by At

I am deploying a ML model and flask app into google cloud run. I added my ml model to a storage bucket(Since I have a large ML model) and then call it inside my Flask app.

ML model stored bucket Calling method

def download_blob(bucket_name, source_blob_name, destination_file_name):
    """Downloads a blob from the bucket."""
    storage_client = storage.Client()
    try:
        storage_client = storage.Client()
        bucket = storage_client.bucket(bucket_name)
        blob = bucket.blob(source_blob_name)
        blob.download_to_filename(destination_file_name)

    except Exception as e:
        print(f"Error downloading blob {source_blob_name}: {e}")

But the problem is, when docker image is building, ML model saving directory is not there. Because of that when i copy the app directory to the image it doesn't have the ML model directory.

Dockerfile

FROM python:3.8
WORKDIR /app
COPY . /app
RUN python -m pip install --upgrade pip
RUN pip install -r requirements.txt
EXPOSE 8080
CMD ["gunicorn", "-b", "0.0.0.0:8080", "app:app"]

When the backend is running it gives below error.

OSError: No file or directory found at /tmpml/model.h5

Also when i test it, it gives 503 error

please, can someone give me a solution for this?

0

There are 0 best solutions below