I\'m using cloud build to build a docker image Guiding myself from examples provide at github:
------bin
------pkg
------src
--cloud
For users with the same trouble, the big problem is go dependecies args: ['install', 'me/backend'] "install" was the bottleneck that stoped me to acomplish the build, for some reason, "install" does not fetch all dependencies, you need to fetch all dependencies first with this: args: ['get','-d','me/backend/...'], obviusly you change "me/backend" for your repositorie you want to build.
How is my local repositorie setup:
-----bin
------pkg
------src
--cloud.google.com #dependency
--contrib.go.opencensus.io #dependency
--github.com #dependency
--go.opencensus.io #dependency
--golang.org #dependency
--google.golang.org #dependency
--me #my code
--backend
.
.
--deploy
cloudbuild.yaml
Dockerfile
Also I moved all my code at "src/me" to google cloud repositories
cloudbuild.yaml:
steps:
- name: 'gcr.io/cloud-builders/gcloud-slim'
args: ['source','repos','clone', '[repositorie name]','src/me','--project=[project name]'] #change [repositorie name] and [project name] for your repositorie name and project name respectively
- name: 'gcr.io/cloud-builders/go'
args: ['get','-d','me/backend/...']
- name: 'gcr.io/cloud-builders/go'
args: ['install', 'me/backend']
env: ['GOPATH=.']
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '--tag=gcr.io/[project name]/me/backend', '.'] #change [project name] with your project name
images: ['gcr.io/[project name]/me/backend'] #change [project name] with your project name
artifacts:
objects:
location: 'gs://[your bucket name]/backend/' #change [your bucket name] for your bucket name
paths: ['./bin/backend']
Dockerfile:
FROM alpine
COPY bin/backend /backend
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
CMD ["/backend"]
RUN chmod 755 /backend
In command line you should(taking my local repositorie example):
cd src/me/deploy
gcloud builds submit .