如何在本地机器上使用带有sdk的云构建来构建docker映像而不会死于尝试 [英] How to build a docker image using cloud build with sdk, in local machine without dying trying it
问题描述
我正在使用
通过示例指导自己,请参见
那么有人知道配置有什么问题吗?:(
同样的麻烦,最大的问题是依赖
args:['install','me / backend']
安装是阻止我完成构建的瓶颈,出于某种原因,安装不会获取所有依赖项,您需要首先使用以下命令获取所有依赖项:
args:['get','-d','me / backend / ...'],显然,您更改了 me / backend作为您要构建的存储库。
我的本地存储库设置如何:
- --- 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#我的代码
--backend
。
。
--deploy
cloudbuild.yaml
Dockerfile
我将我所有位于 src / me的代码移至 Google云存储库
cloudbuild.yaml:
步骤:
-名称:'gcr.io/cloud-builders/gcloud-slim'
args:['源','存储库','克隆','[存储库名称]','src / me','-project = [项目名称]'] #change [存储库名称]和[项目名称]分别代表您的存储库名称和项目名称
-名称:'gcr.io/cloud-builders/go'
args:['get','-d','me / backend /。 ..']
-名称:'gcr.io/cloud-builders/go'
args:['install','me / backend']
env:['GOPATH =。 ']
-名称:'gcr.io/cloud-builders/docker'
args:['build','--tag = gcr.io / [项目名称] / me / backend', '。']#用您的项目名称
images更改[项目名称]:['gcr.io/ [项目名称] / me / backend']#用您的项目名称
更改[项目名称]工件:
对象:
位置:'gs:// [您的存储桶名称] / backend /'#为您的[更改您的存储桶名称]存储桶名称
路径:['./bin/backend']
Dockerfile:
FROM alpine
COPY bin / backend / backend
RUN apk update& apk添加ca证书&& rm -rf / var / cache / apk / *
CMD [ / backend]
RUN chmod 755 / backend
在命令行中,您应该(以我的本地存储库为例):
cd src /我/部署
gcloud构建提交。
I'm using cloud build to build a docker image Guiding myself from examples provide at github:
------bin
------pkg
------src
--cloud.google.com
--contrib.go.opencensus.io
--github.com
--go.opencensus.io
--golang.org
--google.golang.org
--me
--backend
------cloudbuild.yaml
------Dockerfile
Where all my code is in src -> me -> backend
Cloud build steps .yaml file content is:
steps:
- name: 'gcr.io/cloud-builders/go'
args: ['install', 'me/backend']
env: ['GOPATH=.']
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '--tag=gcr.io/superpack-213022/me/backend', '.']
images: ['gcr.io/superpack-213022/me/backend']
Docker File:
FROM scratch
COPY bin/backend /me/backend
ENTRYPOINT ["/me/backend"]
Gives me this error:
can not find a package golang/x/sys/unix in any of ...
Guiding myself from examples provide at documentation:
------bin
------pkg
------src
--cloud.google.com
--contrib.go.opencensus.io
--github.com
--go.opencensus.io
--golang.org
--google.golang.org
--me
--backend
cloudbuild.yaml
Dockerfile
Where all my code is in src -> me -> backend
Cloud build steps .yaml file content is:
steps:
- name: 'gcr.io/cloud-builders/go'
args: ['install', '.']
env: ['GOPATH=backend']
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '--tag=gcr.io/superpack-213022/backend', '.']
images: ['gcr.io/superpack-213022/backend']
Docker File:
FROM scratch
COPY bin/backend /backend
ENTRYPOINT ["backend"]
give me this error: "can not find package me/backend in any of . and" and a buch of error with the same, it is not able to find my package
So anybody knows what is wrong with the configuration? :(
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 .
这篇关于如何在本地机器上使用带有sdk的云构建来构建docker映像而不会死于尝试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!