How to build and push Go image using Google Ko?Could you tell me the steps for cloudbuild.yaml to create the image and push go image using Google ko?

Viewed 21

I need to build go project using google Ko after checking out from git and then push the image to private artifactory which takes credentials. How to define the steps for the above in cloudbuild.yaml? Steps where it takes Source path and also where it takes private repository path. How to give the credentials of artifactory through script?

1 Answers

Error you are getting is due the failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "bash"

By default, the ko command uses a secure and lean base image from the Distroless collection of images (the gcr.io/distroless/static:nonroot image), which doesn’t contain a shell or other executables in order to reduce the attack surface of the container.

You can first create the Ko docker image and we will use this docker image as the base iamge to Cloudbuild. We will push and save the Ko docker image to GCR

Github : https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/ko

There is cloudbuild.yaml to build image on cloudbuild or you also run docker build -t locally to build docker

Once docker image is built and pushed to the GCR we can write the cloudbuild.yaml to build the application

Try this Cloudbuild.yaml for example

steps:
  - name: gcr.io/$PROJECT_ID/ko
    entrypoint: /bin/sh
    env:
      - 'KO_DOCKER_REPO=gcr.io/$PROJECT_ID'
    args:
      - -c
      - |
        echo $(/ko publish --preserve-import-paths ./cmd/ko) > ./ko_container.txt || exit 1
Related