Reputation: 323
I have a docker file, which is running npm install
. When i submit this to gcloud builds submit --tag <tag>
, i get the following error:
....
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
From the error message above, and the results in googling for "undefined ls-remote -h -t ssh://[email protected]", it appears that the issue is that the git path is undefined.
Is there a workaround for this?
EDIT:
# reference: https://www.docker.com/blog/keep-nodejs-rockin-in-docker/
# Operating System
FROM node:10.16.3-slim
# create app directory
WORKDIR /usr/src/app
COPY package-lock.json ./
COPY package.json ./
RUN npm install --no-optional
# for production: RUN npm ci
COPY . .
#EXPOSE 8080
# Environment variables
ENV mode help
CMD ["sh", "-c", "node src/app.js ${mode}"]
I now think this is because i used the -slim
version of the nodejs docker image (going by the recommendation in the docker blog post). I hadn't realized these images also include other programs like git, etc. that are often needed for nodejs.
Upvotes: 0
Views: 1412
Reputation: 75715
There are 2 things to not mix:
tag
tag
The git tag
is a value that you put in your repository to get the code at a certain point of time. The git ls-remote
command is the right one for this. However the tag is empty and the ls-remote
takes the ssh://
git url as the tag name.
The Cloud Build tag
if the name of your container in the gcr docker hub. it's usually gcr.io/<project_id>/<name that you want>
For solving your issue, you have 2 solutions:
docker build
command. Use the tag
to name your container, and use an environment variable -e GIT_TAG=xxx
to use in your Dockerfile to specify the git tagcloudbuild.yaml
and use the same logic with environment variable in your Dockerfile
. For passing your GIT_TAG
to the Cloud Build, use substitution variables. You can use your own substitution variable which must start by underscore, or use the predefined TAG_NAME
variable. In both case, you have to specify it when you run your Cloud Build commandCommand: gcloud builds submit --substitutions=TAG_NAME="test"
or gcloud builds submit --substitutions=_MY_TAG_NAME="test"
cloudbuild.yaml
file
- 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'
You can see that the docker build
command line and the Cloud Build definition are exactly the same.
By the way you can test your build with docker build locally (or on Cloud Shell) for quicker tests and iteration and then package it in cloudbuild.yaml
file.
UPDATE
With your additional details, you don't have git installed in your base image.
Add this line before your npm install
RUN apt-get update && apt-get install -y git
Upvotes: 3