1
votes

I use CircleCI to build a go binary that I want to run in a pod installed by Helm charts. I want to move the binary from CircleCI to the remote cluster so it's available when the pod starts. I know it's possible with volumes, like ConfigMap or Secrets but I'm not sure what the best way to do this.

I once made it work with a private docker registry and a kubernetes Secrets for the credentials of the registry but I don't like this option. I don't want to have to build and push a new docker image on every binary change.

version: 2.1
jobs:
  build_and_deploy:
    docker:
      - image: circleci/golang:1.12.7
    steps:
      - checkout
      - run: go get -v -t -d ./...
      - run: go build cmd/main.go
      - run: ...
      - run: helm install

workflows:
  version: 2
  build:
    jobs:
      - build_and_deploy:

The expected result should be a new binary available on the cluster every time the job runs.

2
Since only go binary is changing - only that layer will be downloaded - and not other layers of the container - I think a container image is a clean option!Vishal Biyani
creating a container image is the common way to do this.Markus Dresch
The idiomatic way is to put the binary in your docker image that helm installs.Flimzy
"I don't want to have to build and push a new docker image on every binary change." -- Why not? That is precisely what helm is designed for.Flimzy
@Flimzy because it brings the complexity of a private docker registry.mathieux51

2 Answers

1
votes

According to the best practices - the binary file should be applied during your build image execution - as mentioned by community above and best developer practices:

Don’t create images from running containers – In other terms, don’t use “docker commit” to create an image. This method to create an image is not reproducible and should be completely avoided. Always use a Dockerfile or any other S2I (source-to-image) approach that is totally reproducible, and you can track changes to the Dockerfile if you store it in a source control repository (git).

However, from another point of view you can consider:

1. init contianers to build your image directly on the cluster

2. kaniko with with external location of your build context (gcs bucket git repository)

3. helm pre-install hook in order to use the above mentioned solutions

4. finally other solutions like cloud build or cloud build locally

Please refer also to "Switching from CircleCI to Google Cloud Build". As described in the article above you can use keel to automatically update your deployments when the image in the docker repository is updated.

Please let me know if it helps.

0
votes

Your CI/CD should simply build a Docker container with that binary. Then you should push it to the private repository. Cluster should download the binary.