【发布时间】:2021-05-27 22:14:18
【问题描述】:
我有一个 gitlab.ci 有这个工作:
build_image:
stage: build
tags:
- BUILD
script:
# recuperation de la derniere image
- docker pull ${CI_REGISTRY_IMAGE}:${TAG} || true
# build ap artir de la derniere image taggé
- docker build --cache-from ${CI_REGISTRY_IMAGE}:${TAG}
--rm
--pull
--tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
-f cicd/Dockerfile
.
- docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
only:
- master
- develop
test_api_image:
image: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
stage: testbuild
variables:
#on force la connexion au service local
MONGODB_URL: mongodb://mongo:27017/BDD
script:
- npm run cicdtest
tags:
- TEST
only:
- master
- develop
首先,在构建作业中,我们使用 Dockerfile 构建镜像并将其推送到 nexus。
在下一项工作中,gitlab 运行程序拉取此图像,并使用“npm run cicdtest”启动 mocha 测试 我们发现了这个错误。
$ npm run cicdtest
> api@0.1.0 cicdtest /builds/data/api
> mocha test/api/**/tests.js --file test/helper --reporter list --exit
sh: mocha: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
在我的桌面上,我在本地提取相同的图像进行测试,然后运行并进入容器。当我执行“npm run cicdtest”时我没有问题。
有什么想法吗?
有关信息,这是我的 Dockerfile:
FROM centos:latest
RUN mkdir -p /var/www/myapp
WORKDIR /var/www/myapp
RUN yum update -y \
&& yum install -y gcc gcc-c++ make \
&& curl -sL https://rpm.nodesource.com/setup_14.x | bash - \
&& yum install -y nodejs
COPY ["package.json", "package-lock.json*", "./"]
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "node" , "./src/app.js"]
我的 package.json 包含:
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"crypto-js": "^4.0.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"mongoose": "^5.10.13",
"mustache": "^4.2.0",
"nodemailer": "^6.6.0",
"nodemon": "^2.0.6",
"restify": "^8.5.1",
"web-push": "^3.4.4"
},
"devDependencies": {
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"eslint": "^7.26.0",
"eslint-plugin-chai-expect": "^2.2.0",
"husky": "^6.0.0",
"mocha": "^8.3.0",
"supertest": "^6.1.3"
}
【问题讨论】:
标签: docker npm gitlab continuous-integration dockerfile