1

我正在使用cloud build来构建一个 docker 映像,从github提供的示例中指导自己:

- - - 垃圾桶

------包装

------src

     --cloud.google.com
     --contrib.go.opencensus.io
     --github.com
     --go.opencensus.io
     --golang.org
     --google.golang.org
     --me
        --backend

------cloudbuild.yaml

------Dockerfile

我所有的代码都在 src -> me -> backend

云构建步骤.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']

码头工人文件:

FROM scratch

COPY bin/backend /me/backend

ENTRYPOINT ["/me/backend"]

给我这个错误:

can not find a package golang/x/sys/unix in any of ...

我

从文档中提供的示例中指导自己 :

- - - 垃圾桶

------包装

------src

     --cloud.google.com
     --contrib.go.opencensus.io
     --github.com
     --go.opencensus.io
     --golang.org
     --google.golang.org
     --me
        --backend
          cloudbuild.yaml
          Dockerfile

我所有的代码都在 src -> me -> backend

云构建步骤.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']

码头工人文件:

FROM scratch

COPY bin/backend /backend

ENTRYPOINT ["backend"]

给我这个错误:“在任何.and中都找不到包我/后端”和一堆相同的错误,它无法找到我的包 我2 我3

所以有人知道配置有什么问题吗?:(

4

1 回答 1

1

对于有同样问题的用户,最大的问题是 go 依赖 args: ['install', 'me/backend'] "install" 是阻止我完成构建的瓶颈,由于某种原因,"install" 无法获取所有依赖项,您需要首先使用以下命令获取所有依赖项:args:['get','-d','me/backend/...'],显然您为您想要的存储库更改“me/backend”建造。

我的本地存储库设置如何:

- - -垃圾桶

------包装

------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”中的所有代码移至谷歌云存储库

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 .
于 2019-01-27T17:29:54.690 回答