Google Cloud build快速入门 [英] quick start in google cloud build

查看:210
本文介绍了Google Cloud build快速入门的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行了快速入门

https://cloud.google.com/cloud-build/docs/quickstart-build

以及查看构建详细信息"部分中,我在任何地方都看不到quickstart.sh文件的输出.实际运行quickstart.sh文件的日志在哪里?

and in the section "View the build details", I don't see the output of the quickstart.sh file anywhere. Where is the logs from actually running the quickstart.sh file?

在没有quickstart.sh的任何输出的情况下,我不确定如何记录docker中发生的情况,因此我可以修复在docker中构建的损坏的构建.

Without any output from quickstart.sh, I am unsure how to log what is going on in docker so I can fix broken builds that build in docker.

推荐答案

在此官方教程中,通过Cloud Build构建了一个docker容器,只有一个可执行的bash脚本显示了当前日期.

In this official tutorial, a docker container is built via Cloud Build, with only one executable bash script which is displaying the current date.

#!/bin/sh
echo "Hello, world! The time is $(date)."

这是Dockerfile:

Here is the Dockerfile :

FROM alpine
COPY quickstart.sh /
CMD ["/quickstart.sh"]

这意味着quickstart.sh不会在构建阶段执行,而只能在容器的执行步骤执行.

It means quickstart.sh is never executed during build phase but only at the execution step of container.

要查看脚本的输出,您应该运行容器(在计算机本地或通过Cloud Shell):

To see the output of script, you should run container (either locally on your computer, or via Cloud Shell) :

$ docker run gcr.io/[PROJECT-ID]/quickstart-image:latest
Hello, world! The time is Sat Jun 13 05:10:41 UTC 2020.

如果要在容器的构建阶段执行脚本,则应使用RUN命令.

If you want to execute a script during build phase of container, you should use RUN command.

例如,让我们在同一目录中创建另一个名为build.sh的可执行脚本:

For example, let's create a second executable script called build.sh in the same directory:

#!/bin/sh
echo "Hello, build at $(date)."

然后,将其添加到Dockerfile文件描述中:

Then, add it on Dockerfile file description :

FROM alpine
COPY quickstart.sh /
COPY build.sh /
RUN /build.sh
CMD ["/quickstart.sh"]

现在,我们可以构建一个新版本的容器映像:

Now, we can build a new version of container image :

gcloud builds submit --tag gcr.io/[PROJECT-ID]/quickstart-image

这次,在Cloud Build控制台的详细信息输出日志中可以看到build.sh的输出:

This time, output of build.sh could be seen in the details output log in Cloud Build console:

当然,这里仅是一个简单的示例,可为您提供快速解答.您可以检查所有其他可能的选项以编写正确且干净的Dockerfile.但这与Cloud Build并没有真正的联系.

Of course, here it's just a simple example to give you a quick answer. You may check all other possible options to write a correct and clean Dockerfile. But it's not really linked with Cloud Build.

这篇关于Google Cloud build快速入门的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆