Dockerfile-摩卡中意外的令牌错误

时间:2019-10-21 03:21:40

标签: javascript docker docker-compose mocha dockerfile

下面是存储为图像标签somehub/someapp-specs的dockerfile:

FROM ubuntu:trusty

MAINTAINER Developer team <developerteam@abc.com>

# Prevent dpkg source
ENV TERM=xterm-256color

# Set mirrors to ca
RUN sed -i "s/http:\/\/archive./http:\/\/ca.archive./g" /etc/apt/sources.list

# Install node.js
RUN apt-get update && \
    apt-get install curl -y && \
    curl -sL http://deb.nodesource.com/setup_4.x | sudo -E bash - && \
    apt-get install -y nodejs

COPY . /app
WORKDIR /app

# Install application dependencies
RUN npm install -g mocha && \
    npm install

# Set mocha test runner as entrypoint
ENTRYPOINT ["mocha"]

在docker-compose的以下摘要中的test服务中使用:

test:
  image: somehub/someapp-specs
  links:
    - nginx
  environment:
    URL: http://nginx:8080/todos
    JUNIT_REPORT_PATH: /reports/acceptance.xml
    JUNIT_REPORT_STACK: 1
  command: --reporter mocha-jenkins-reporter

错误启动了mocha容器:

$ docker-compose up test
release_dbc_1 is up-to-date
Starting release_webroot_1 ... done
Creating release_app_1     ... done
Creating release_nginx_1   ... done
Creating release_test_1    ... done
Attaching to release_test_1
test_1     | /usr/lib/node_modules/mocha/bin/mocha:13
test_1     | const {deprecate, warn} = require('../lib/utils');
test_1     |       ^
test_1     | 
test_1     | SyntaxError: Unexpected token {
test_1     |     at exports.runInThisContext (vm.js:53:16)
test_1     |     at Module._compile (module.js:373:25)
test_1     |     at Object.Module._extensions..js (module.js:416:10)
test_1     |     at Module.load (module.js:343:32)
test_1     |     at Function.Module._load (module.js:300:12)
test_1     |     at Function.Module.runMain (module.js:441:10)
test_1     |     at startup (node.js:140:18)
test_1     |     at node.js:1043:3
release_test_1 exited with code 1

Dockerfile中的

COPY . /app指令正在复制具有以下版本的package.json:

{
  "name": "someappspecs",
  "version": "0.1.0",
  "description": "someapp acceptance tests",
  "main": "app.js",
  "scripts": {
    "test": "mocha"
  },
  "author": "xyz",
  "license": "ISC",
  "dependencies": {
    "bluebird": "^3.7.0",
    "chai": "^4.2.0",
    "chai-as-promised": "^7.1.1",
    "mocha": "^6.2.1",
    "mocha-jenkins-reporter": "^0.4.2",
    "superagent": "^5.1.0",
    "superagent-promise": "^1.1.0"
  }
}

mocha用于在release_app_1容器上运行验收测试

如何解决此意外的令牌错误?看起来与其他容器服务无关。

1 个答案:

答案 0 :(得分:2)

那是因为Mocha需要节点> 6.0,而您的节点是4.x

  

从v6.0.0开始,Mocha需要Node.js v6.0.0或更高版本。

尝试通过使用“节点映像”升级节点:

FROM node:10.16

或者您可以像这样更新当前的dockerfile:

RUN apt-get update && \
    apt-get install curl -y && \
    curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
    apt-get install -y nodejs