我有一个正在运行npm install
的docker文件。当我将此提交到gcloud builds submit --tag <tag>
时,出现以下错误:
....
npm ERR! path git
npm ERR! code ENOENT
npm ERR! errno ENOENT
npm ERR! syscall spawn git
npm ERR! enoent Error while executing:
npm ERR! enoent undefined ls-remote -h -t ssh://[email protected]/web3-js/WebSocket-Node.git
npm ERR! enoent
npm ERR! enoent
npm ERR! enoent spawn git ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
根据上面的错误消息,以及对“未定义的ls-remote -h -t ssh://[email protected]”进行谷歌搜索的结果,看来问题在于git路径未定义。
是否有解决方法?
您混合了两件事:
tag
tag
git tag
是您放入存储库中的值,以便在特定时间点获取代码。 git ls-remote
命令是正确的选择。但是,标签为空,ls-remote
将ssh://
git url作为标签名称。因此,在存储库URL中说undefined
。
Cloud Build tag
,如果您的容器在gcr docker hub中的名称。通常是gcr.io //
为了解决您的问题,您有2个解决方案:
tag
命令。使用docker build
命名您的容器,并使用环境变量tag
在您的Dockerfile中使用以指定git标签-e GIT_TAG=xxx
使用Cloud Build配置文件,并在cloudbuild.yaml
中使用与环境变量相同的逻辑。要将Dockerfile
传递到Cloud Build,请使用GIT_TAG
。您可以使用必须以下划线开头的自己的替代变量,也可以使用预定义的substitution variables变量。在这两种情况下,您都必须在运行Cloud Build命令时指定它]命令:TAG_NAME
或gcloud builds submit --substitutions=TAG_NAME="test"
gcloud builds submit --substitutions=_MY_TAG_NAME="test"
文件
cloudbuild.yaml
您可以看到
- name: 'gcr.io/cloud-builders/docker' args: ['build', '-t', 'gcr.io/$PROJECT_ID/my-image', '.', '-e', 'GIT_TAG=$_MY_TAG_NAME'] # my-image is pushed to Container Registry images: - 'gcr.io/$PROJECT_ID/my-image'
命令行和Cloud Build定义完全相同。
通过您可以在本地(或在Cloud Shell上)使用docker build进行测试的方法,以便进行更快的测试和迭代,然后将其打包在docker build
文件中。