Google Cloud Run 作业在不运行包含的脚本的情况下在 2 秒内成功。

huangapple go评论80阅读模式
英文:

Google Cloud Run job succeeding in 2 seconds without included script running

问题

我有一个包含需要运行的脚本的Google Cloud Run作业。该脚本正在将数据加载到Google Bigquery中。我有一个Dockerfile,其中定义了我需要的所有先决条件(从GitHub存储库加载自定义Python库,安装Python库等)。

当我构建容器时,脚本按预期运行,我在BQ中看到了结果。

但是,当我在Cloud Run中运行作业时,它并没有按预期运行。

我尝试手动运行作业以及调度Cloud Scheduler Cron作业。

我期望脚本执行,然后在BQ中看到数据。

但是,我注意到作业只运行了大约2秒,成功运行,并且BQ在运行后没有显示任何更改。此外,日志仅告诉我容器以状态0退出,并且没有提供任何信息,包括stdout转储。

我在这里漏掉了什么?

更新:问题已解决

但是我的答案可能不是最佳实践,而且我可能仍然漏掉了一些东西。将很乐意接受任何帮助我和更广泛的Stack Overflow社区更多了解的答案。

谢谢!

英文:

I have Google Cloud Run job that contains a script I need ran. The script is loading data into Google Bigquery. I have a Dockerfile that defines all pre-requisites I need (loading a custom python library from a github Repo, installing python libraries, etc).

When I build the container the script runs as expected and I see results in BQ.

But when I run the job in Cloud Run it doesn't run as expected.

I tried manually running the job as well as scheduling a Cloud Scheduler Cron job.

I expected it the script to execute and then see data in BQ.

However I notice that the job is running in 2 seconds or so and succeeding and BQ shows no changes after the run. Also, the logs only tell me that the container exited with status 0 and gives no information, including stdout dumps.

What am I missing here?

UPDATE: ISSUE RESOLVED

However my answer may not be the best practice and I may still be missing something here. Will be happy to accept any answers helping me and the greater Stack Overflow community understand more here.

Thanks!

答案1

得分: 0

原来是我对 Docker 运行时(引擎?我不确定这里用什么词)对构建好的容器的处理方式理解有误。

我以为每次运行 Docker 镜像时,都会执行 Dockerfile 中列出的所有命令。

因此(假设这里使用了 Ubuntu 基础镜像作为示例):

...
所有设置了很棒的镜像内容都在这里
...

RUN python3 my_awesome_script.py

这意味着每次运行容器时都会执行 my_awesome_script.py

我错了

事实证明,在本地运行 docker container run my_awesome_image 时,会运行镜像,就好像 Dockerfile 中的所有步骤都已完成一样。

因此,一个没有运行 Flask 应用或其他服务的 Dockerfile 只会简单地退出。

这是我在本地和在 Google 云平台上注意到的情况。该作业将在 20 秒内以“成功”状态完成。

运行 docker container run -ti my_awesome_image 将使我进入镜像本身的 TTY 界面,然后我可以运行 python3 my_awesome_script.py 以获得我想要的结果。

在 Google Cloud Run 作业界面上经过一些试验和错误后,我找到了“容器参数”部分,并成功执行了 python3 my_awesome_script.py

这解决了我的问题。

英文:

Turns out it was my lack of understanding of what the docker runtime (engine? IDK the right word here) does with built containers.

I thought that a Docker image would run through all the commands listed in the Dockerfile every time.

Thus (Assuming an Ubuntu base image for this example),

...
All awesome image set up stuff here
...

RUN python3 my_awesome_script.py

Would mean that every time the container was ran it would end up running my_awesome_script.py.

I WAS WRONG

Turns out docker container run my_awesome_image (in local) will run the image as it was after all the steps in the Dockerfile are completed.

Therefore a Dockerfile with no Flask app or other service running will simply exit.

This is what I noticed locally and in GCP as well. The job would simply finish in 20 seconds with a 'success'.

Running docker container run -ti my_awesome_image will get me to a TTY in the image itself and then I can issue python3 my_awesome_script.py for the results I want.

After some trial and error in the Google Cloud Run Jobs interface I found the "Container Arguments" section and was able issue python3 my_awesome_script.py.

This resolved my issue.

huangapple
  • 本文由 发表于 2023年6月19日 06:23:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76502746.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定