0

I am trying to use Google Cloud Container Builder to automate the building of my containers using GCP Build Triggers

My code is in Go, and I have a vendor folder in my project root which contains all of my Go dependencies (I use govendor). However, this vendor folder is NOT checked in to source control.

I have a cloudbuild.yaml file where I first build my Go source into a main executable, and then build a Docker image using this executable. Container Builder ensures these build steps have access to my master branch.

The problem is that the Go compilation step fails, because the vendor folder is not checked in to source control, so none of my dependencies are available for any build step.

Is there a way to create a build step that uses govendor to install all dependencies in the vendor folder? If so, how? Or is the only option to check in my vendor directory into source control (which seems unnecessary to me)?

Ismail Khan
  • 842
  • 2
  • 8
  • 20
  • 1
    If you don't have the vendor folder checked in, what is the point of using govendor? – JimB Sep 24 '17 at 22:52
  • @JimB: My vendor.json file is checked in to ensure that dependencies are consistent in any environment. The actual source code for the dependencies is not checked in. Similar to node.js where package.json is added to Git, but the node_modules/ directory is not. Here's why I did not add the dependencies to Git: https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md – Ismail Khan Sep 25 '17 at 07:41
  • 1
    If you have the `./vendor/vendor.json` file, `govendor` can build the vendor directory for you. Are you having a problem executing govendor? (for the record, most people prefer to check in the vendor directory, as it makes builds more reliable, and protects you against a dependency breaking or becoming completely unavailable) – JimB Sep 25 '17 at 12:37
  • I don't know how to run `govendor` on Google Container Builder service, since it's not listed as one of the container-builders over here: https://github.com/GoogleCloudPlatform/cloud-builders. My understanding was the opposite, actually: that most people don't check in go dependencies. Are there special precautions I should consider before doing so? – Ismail Khan Sep 25 '17 at 13:13
  • 1
    Those are just some open source examples, you can [create your own build steps](https://cloud.google.com/container-builder/docs/concepts/custom-build-steps). The point of using './vendor` _is_ to check in the dependencies. Take almost any major project and look at the vendor tree, e.g. [Kubernetes](https://github.com/kubernetes/kubernetes/tree/master/vendor), [Terraform](https://github.com/hashicorp/terraform/tree/master/vendor), [Caddy](https://github.com/mholt/caddy/tree/master/vendor), etc. There are no precautions to take, other than what you normally would do before using external code. – JimB Sep 25 '17 at 13:33
  • 1
    None of composer's arguments against commiting dependencies apply, really. 1) VCS size: guess what, you still have to download all the dependencies. In fact, build systems often cache the local checkout (e.g. git pull instead of git clone), but not the dependencies. 2) govendor does not import the history. 3) govendor does not create submodules. Being able to just clone your project and you're ready to go is a huge boon. It avoids problem like the one you are having right now (and more). I suggest you reconsider commiting vendor. – Peter Sep 25 '17 at 14:49

1 Answers1

0

As per @JimB and @Peter's comments to my question, an easy solution is to add my vendor directory to Git so I don't have to download all my dependencies during the build steps.

Ismail Khan
  • 842
  • 2
  • 8
  • 20