gsutil cp in dockerfile does not copy file

Viewed 519

I am trying to deploy my FastAPI app on Cloud Run, and in the Dockerfile I'd like to copy a file on my GCS Bucket and read it in the API. It somehow does not copy the file.

This is the copy lines in my Dockerfile:

FROM google/cloud-sdk AS gcloud
RUN mkdir ./models
RUN gsutil cp gs://rim-models/model_1.pkl ./models/model_1.pkl

And when I created an image with gcloud builds submit --tag gcr.io/project-id/api-name --timeout=3600, it shows that the file was copied:

Copying gs://rim-models/model_1.pkl ...
- [1 files][399.8 KiB/399.8 KiB]
Operation completed over 1 objects/399.8 KiB.

However, I got this error in the API:

FileNotFoundError: [Errno 2] No such file or directory: 'models/model_1.pkl'

When I run the command gsutil cp gs://rim-models/model_1.pkl ./models/model_1.pkl locally, it does copy the file model_1.pkl to my local directory models. So why did it not work when I deployed the app to Cloud Run?

EDIT: After changing all models paths to either all relative or all absolute, the error remains.

1 Answers

Your container creation contains mistakes or inconsistency in the directory definition.

RUN mkdir /models
RUN gsutil cp gs://rim-models/model_1.pkl ./models/model_1.pkl

First line, you create the absolute path /models, in the seconds, you use the relative path ./models

You can either use the full path, or the relative, but there is lack of consistency.

In your API error, the mention is models/model_1.pkl, obviously a relative path. I don't know the full path where your API look the data, but you have to fix all this small unaligned directory definition

Related