我为mongodb测试构建了一个docker镜像。您可以从zhaoyi0113/mongo-uat
找到。从此映像启动docker容器时,它将创建一些mongodb实例,这将需要几分钟才能启动。现在我想通过无人机CI在这个容器中运行我的集成测试用例。下面是我的.drone.yml文件:
pipeline:
build:
image: node:latest
commands:
- npm install
- npm test
- npm run eslint
integration:
image: zhaoyi0113/mongo-uat
commands:
- npm install
- npm run integration
此管道中有两个步骤,第一步是在nodejs项目中运行单元测试。第二个integration
用于在mongodb docker镜像中运行集成测试用例。
当我运行drone exec
时,会收到错误failed to connect to mongo instance
。我认为,因为mongodb实例需要几分钟才能启动。启动mongodb实例后,应运行命令npm install
和npm run integration
。如何延迟构建命令?
EDIT1
图片zhaoyi0113/mongo-uat
有mongodb环境。它将创建一些mongodb实例。我可以运行此命令docker run -d zhaoyi0113/mongo-uat
来启动此容器,之后我可以附加到此容器以查看mongodb实例。我不确定无人机如何发射泊坞容器。
答案 0 :(得分:4)
集成测试的推荐方法是将服务容器放在Yaml的服务部分[1] [2]
因此,为了启动Mongo服务容器,我将创建下面的Yaml文件。 Mongo服务将从默认端口127.0.0.1开始,并可从管道容器访问。
pipeline:
test:
image: node
commands:
- npm install
- npm run test
integration:
image: node
commands:
- npm run integration
services:
mongo:
image: mongo:3.0
这是测试MySQL,Postgres,Mongo等服务的推荐方法。
[1] http://readme.drone.io/usage/getting-started/#services
[2] http://readme.drone.io/usage/services-guide/
答案 1 :(得分:0)
作为Brads答案的简短附录:尽管mongo服务将在无人机主机上的127.0.0.1上运行-无法在节点应用内内通过此IP访问该服务。要访问该服务,请引用其服务名称(此处为mongo)。