Cloud-builders: Docker build step missing workspace resources

Created on 3 Mar 2018  路  5Comments  路  Source: GoogleCloudPlatform/cloud-builders

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?

Most helpful comment

The problem is your .dockerignore contains node_modules. You could either remove it, or install the dependencies in the Dockerfile.

All 5 comments

Hey @artjomzab ,

I tried to reproduce, but it worked on my side.

A few questions:

  1. Does the node_modules directory exist before the first step? Can you check by adding a first step debian ls?
    You may want to add a file . gcloudignore with node_modules. If your local machine OS is different from the worker, it may be an issue.
  2. Could you give me a buildId of a failing build?

Best,
Philippe

@Philmod

  1. node_modules does not exist before first step
  2. b965402b-e307-4fde-8601-278c16a65a84

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DazWilkin picture DazWilkin  路  3Comments

jredl-va picture jredl-va  路  3Comments

drgomesp picture drgomesp  路  8Comments

ewhauser picture ewhauser  路  4Comments

ptemmer picture ptemmer  路  5Comments