I try to build a node application and bundle it into a docker image:
steps:
# Bring in dependencies
- name: 'gcr.io/cloud-builders/npm'
args: ['install', '--only=production', '.']
# Build docker image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '--tag=gcr.io/$PROJECT_ID/my_app:$SHORT_SHA', '.']
images: ['gcr.io/$PROJECT_ID/my_app']
However it seems that the second build step has no access to the resources from the first step. In the docker image I try to copy the node_modules folder:
FROM node:9.5.0-alpine
# Create app directory
# WORKDIR /usr/src/app
RUN apk update && \
apk add imagemagick tar ttf-dejavu
# Bundle app source
COPY node_modules .
COPY . .
EXPOSE 8080
CMD ["npm", "start"]
And it fails with
Step #1: COPY failed: stat /var/lib/docker/tmp/docker-builder382442269/node_modules: no such file or directory
Step #1: Step 5/9 : COPY ./node_modules .
When I add a step in between like:
# Bring in dependencies
- name: 'debian'
args: ['ls']
I can see node_modules in the log. So how come that node_modules is missing when performing the build step with docker?
Hey @artjomzab ,
I tried to reproduce, but it worked on my side.
A few questions:
node_modules directory exist before the first step? Can you check by adding a first step debian ls?. gcloudignore with node_modules. If your local machine OS is different from the worker, it may be an issue.buildId of a failing build?Best,
Philippe
@Philmod
I'm still unable to reproduce the problem.
Could you create a limited set of files I could use to reproduce it?
@Philmod thanks for your help Phil. I created a hello world example to reproduce the problem: https://github.com/artjomzab/gc-node-test-app
This build (18ba38ba-5d8a-4d44-a122-658873f42fe7) is failing again:
Step #3: COPY failed: stat /var/lib/docker/tmp/docker-builder312930951/node_modules: no such file or directory
The problem is your .dockerignore contains node_modules. You could either remove it, or install the dependencies in the Dockerfile.
Most helpful comment
The problem is your
.dockerignorecontainsnode_modules. You could either remove it, or install the dependencies in the Dockerfile.