使用Google Cloud Build,如何运行执行docker和kubectrl命令的Makefile? [英] With Google Cloud Build, how do I run a Makefile that executes docker and kubectrl commands?

查看:56
本文介绍了使用Google Cloud Build,如何运行执行docker和kubectrl命令的Makefile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了一个项目,该项目由许多运行许多 docker 命令的 Makefile 构建.我想在Cloud Build上构建它.

I received a project that is built with a number of Makefiles which run a number of docker commands. I want to build it on Cloud Build.

我知道Cloud Build可本地处理Docker,但必须与现有的Makefile结构一起使用.

I know that Cloud Build handles Docker natively, but must work with the existing Makefile-structure.

我尝试了 make 自定义构建步骤,但是由于缺少 docker kubectl ,Cloud Build失败.所以我可以将它们添加到 make Custom Build步骤的 Dockerfile 中,但这似乎是错误的,因为然后 make 运行Docker-在Docker中,这会引起问题-例如,缺少 gcloud kubectl 权限和上下文.

I tried the make Custom Build step, but Cloud Build failed on lack of docker and kubectl. So I could add these to the Dockerfile of the make Custom Build step, but it seems like that is wrong, because then make runs Docker-in-Docker and this causes problems -- for example, gcloud and kubectl permissions and context are missing.

作为此类Makefile的一小部分,这是一个调用 docker buildz和 docker push`"的目标.

As a small part of one such a Makefile, here is a target that calls docker buildz anddocker push`.

build/myapp/deployer: ...

    docker build \
        --build-arg REGISTRY="$(REGISTRY)/myapp" \
        --tag "$(APP_DEPLOYER_IMAGE)" \
        -f deployer/Dockerfile \
        .

    docker push "$(APP_DEPLOYER_IMAGE)"
    @touch "$@"

如何在Cloud Build中运行这些Makefile?

How do I run these Makefiles in Cloud Build?

推荐答案

要回答您的评论:如何在docker容器中运行docker?",您必须像奔跑者一样看到自定义云构建器.您可以在Cloud Build中像这样使用它

To answer to your comment: "How to run docker inside a docker container?", you have to see your custom cloud builder like an runner. You can use it like this in Cloud Build

- steps:
  - name: gcr.io/your-project/your-custom-builder
    entrypoint: "bash"
    args: 
      - "-c"
      - |
        Makefile
        <All the script lines that you want which use binaries installed in your custom builder>

在此处,自定义Cloud Builder运行命令,但结果存储在Cloud Build工作区中,而不是在自定义Cloud Builder容器中.

Here the custom Cloud Builder run the command but the result is stored in your Cloud Build workspace, not in the custom Cloud Builder container.

这篇关于使用Google Cloud Build,如何运行执行docker和kubectrl命令的Makefile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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