在Google Cloud Build上构建Dockerfile不会打印测试日志

时间:2018-08-23 01:04:18

标签: docker google-cloud-build

我有一个简单的 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"]

我在 Google Cloud Build 中运行它并获取以下日志:

...
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
...

在步骤6/6npm run test上,我看不到本地计算机上的日志:

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

如何使这些日志显示在构建日志中?

1 个答案:

答案 0 :(得分:1)

这是因为您正在构建不运行它的映像:)。运行容器时,您会看到日志打印出来,例如

docker run -it my-image