我正在使用cloud build构建docker映像 从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
我所有的代码都在src->我->后端
云构建步骤.yaml文件的内容为:
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文件:
FROM scratch
COPY bin/backend /me/backend
ENTRYPOINT ["/me/backend"]
给我这个错误:
can not find a package golang/x/sys/unix in any of ...
通过示例指导自己{@ 3}:
------ 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
我所有的代码都在src->我->后端
云构建步骤.yaml文件的内容为:
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文件:
FROM scratch
COPY bin/backend /backend
ENTRYPOINT ["backend"]
给我这个错误: “在以下任何位置都找不到打包我/后端的软件包”和“ 并有很多错误,它无法找到我的包裹 documentation
因此,有人知道配置出了什么问题吗? :(
答案 0 :(得分:0)
对于同样遇到麻烦的用户,最大的问题是依赖 args:['安装','我/后端'] “安装”是阻止我完成构建的瓶颈,由于某种原因,“安装”不能获取所有依赖关系,因此您需要首先获取所有依赖关系: 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 #my code
--backend
.
.
--deploy
cloudbuild.yaml
Dockerfile
我也将所有代码从“ src / me”移动到了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
您应该在命令行中(以我的本地存储库为例):
cd src/me/deploy
gcloud builds submit .