3

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.

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

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.

As a small part of one such a Makefile, here is a target that calls docker build and docker push.

build/myapp/deployer: ...

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

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

How do I run these Makefiles in Cloud Build?

Joshua Fox
  • 18,704
  • 23
  • 87
  • 147

1 Answers1

3

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>

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.

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • Docker-in-docker makes things complicated. For example, docker/kubectl do not come preconfigured with the suitable service user. Further, they run into problems accessing the filesystem. – Joshua Fox Nov 30 '19 at 16:24
  • guillaume blaquiere: Perhaps this is the better question: How can we use parameters calculated within the Cloud Build process: https://stackoverflow.com/questions/59118037/h – Joshua Fox Nov 30 '19 at 16:27