0

I have a simple Dockerfile:

FROM node:8

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm install --only=production

# Bundle app source
COPY . .

CMD ["npm", "run", "test"]

I run it inside Google Cloud Build and get the following logs:

...
Removing intermediate container 19ae183b28c6
 ---> 5802f218fa4e
Step 5/6 : COPY . .
 ---> a1600834b6e0
Step 6/6 : CMD npm run test
 ---> Running in bfb7be511b96
Removing intermediate container bfb7be511b96
 ---> 6e974d117670
Successfully built 6e974d117670
...

At step 6/6, npm run test, I am not seeing the logs that I would on my local machine:

npm run test:

 PASS  __tests__/order.spec.ts
 PASS  __tests__/news.spec.ts
 PASS  __tests__/product.spec.ts (5.328s)
 PASS  __tests__/review.spec.ts
 PASS  __tests__/donation.spec.ts
 PASS  __tests__/referral.spec.ts
 PASS  __tests__/nonprofit.spec.ts

Test Suites: 7 passed, 7 total
Tests:       22 passed, 22 total
Snapshots:   0 total
Time:        8.291s, estimated 9s

How can I get these logs to show up in the build logs?

theblindprophet
  • 7,767
  • 5
  • 37
  • 55
  • You're building a container image that, when run, will run `npm run test`. Cloud Build just does the build. It does not `docker run` the image. If you replace `CMD ["npm","run","test"]` with `RUN npm run test` your build will include the `npm run test` and it *should* do what you ask. Though you're then also creating a container image that does nothing when run. – DazWilkin Aug 23 '18 at 03:42

1 Answers1

1

It is because you are building the image not running it :). When you run the container you will see the logs printing out e.g

docker run -it my-image

captainchhala
  • 831
  • 1
  • 7
  • 14