How do I structure a repo with Cloud Run needing higher level code?

2024/11/20 15:23:37

I have added code to a repo to build a Cloud Run service. The structure is like this: enter image description here

I want to run b.py in cr.

Is there any way I can deploy cr without just copying b.py into the cr directory? (I don't want to do it since here are lots of other folders and files that b.py represents). The problem is due to the Dockerfile being unable to see folders above. Also how would eg api.py import from b.py?

TIA you lovely people.

Answer

You have to build your container with the correct parameters, and therefore, not to use the gcloud run deploy --source=. .... to build your container with default parameters

With docker, the Dockerfile by default is in the PATH/Dokerfile. But you can override that default behavior with the -f parameter to indicate the Dockerfile location.

For example, you can do that

cd topdocker build -f ./a/cr/Dockerfile .

Like that, you provide to the docker build runtime the current path (here top, and the current path is represented but the dot at the end .).

And you also specify the full path of the Dockerfile inside this current path.

So that, you have to update your Dockerfile, because the COPY . . will no longer copy the cr path, but the whole top directory.


EDIT 1

To validate my answer, I exactly do what you ask in your comment. I used gcloud build summit but:

  • I ran the command from the top directory
  • I created a cloudbuild.yaml file
steps:- name: 'gcr.io/cloud-builders/docker'entrypoint: 'bash'args:- -c- |docker build -f ./a/cr/Dockerfile -t <YOUR TAG> .docker push <YOUR TAG>

you can't perform a gcloud builds submit --tag <YOUR TAG> from the top directory if you haven't a Dockerfile in the root dir.

https://en.xdnf.cn/q/118403.html

Related Q&A

Unable to build kivy image loaded .py file into exe using auto-py-to-exe

I have a simple kivy file in which i want to cover the entire canvas with an image bgi.jpg MainWidget: <MainWidget>:canvas.before:Rectangle:size:self.sizesource:bgi.jpgand the .py file code i…

Pandas Panel is deprecated,

This code snippet is from one of my script which works fine in current panda version (0.23) but Panel is deprecated and will be removed in a future version.panel = pd.Panel(dict(df1=dataframe1,df2=data…

Python - Why is this data being written to file incorrectly?

Only the first result is being written to a csv, with one letter of the url per row. This is instead of all urls being written, one per row.What am I not doing right in the last section of this code t…

How does Python interpreter look for types? [duplicate]

This question already has answers here:How does Python interpreter work in dynamic typing?(3 answers)Closed 10 months ago.If I write something like:>>> a = float()how does Python interpreter …

title() method in python writing functions when word like arent

using functiondef make_cap(sentence):return sentence.title()tryining outmake_cap("hello world") Hello World# it workd but when I have world like "arent" and isnt". how to write…

Creating a C++ Qt Gui for a Python logic

I was presented with a Python logic for which I need to create a GUI. I want to use Qt for that purpose and ideally I would like to program it in C++, without using the Qt Creator.What are recommended …

Pythons BaseHTTPServer returns junky responses

I use Pythons BaseHTTPServer and implement the following very simple BaseHTTPRequestHandler:class WorkerHandler(BaseHTTPRequestHandler):def do_GET(self):self.wfile.write({"status" : "rea…

Why is matplotlib failing on import matplotlib.pyplot as plt

I installed matplotlib using conda:conda install matplotlibThe following code failed:#!/usr/bin/env python import matplotlib import matplotlib.pyplot as pltWith this error message:"ImportError: N…

Setting cell color of matplotlib table and save as a figure?

Im following this code a link! to save a table as the image, and I have some feature like check value in a cell then set color for a cell, but I added some code stylemap, it doesnt workimport pandas a…

Errno 111 Connection refused - Python Mininet API hosts client/server no connection?

I am new to Mininet and I am trying to find a way to use a script in python to execute a few tests using Mininet. More precisely I want to build topology and send a few xmlrpc request from one host t…