2016-12-07 75 views
3

我试图从通过gitlab-ci-multirunner运行的码头图像中访问mongorestore/mongodump命令。如何访问码头图像中的mongorestore/mongodump

我.gitlab-ci.yml看起来是这样的:

image: node:7.2.0 

cache: 
    key: "$CI_BUILD_REF_NAME" 
    paths: 
    - node_modules/ 

services: 
    - mongo 

variables: 
    DOCKER_ENV: 'true' 
    NODE_ENV: 'test' 

all_tests: 
    script: 
    - npm install 
    - npm install tsd -g 
    - tsd install --save 
    - node_modules/typescript/bin/tsc -p . 
    - node node_modules/mocha/bin/_mocha --recursive tests --timeout 15000 

在我的测试我mongodump/mongorestore。我得到的错误是:

Create Transaction Tests

Connected to MongoDB: mongodb://mongo:27017/test-db { Error: Command failed: mongorestore --port 27017 --drop /builds/project/repo/project/tests/testData/db/mongo/dump

/bin/sh: 1: mongorestore: not found

我甚至尝试运行与脚本中的部分 “泊坞窗运行” 一mongorestore命令:

- docker run --rm --link mongodb:mongo -v /root:/backup mongo bash -c ‘mongorestore /backup --host $MONGO_PORT_27017_TCP_ADDR’ 

我得到这个错误:

/bin/bash: line 61: docker: command not found

我必须提到,我在gitlab提供的共享docker runner上运行此映像。

有关如何从我的测试中访问“mongorestore”命令的任何建议?

+0

我可以问你是否想在节点码头集装箱中运行mongodump和mongorestore,因为这是它们在生产环境中的运行方式?还是只是为了测试,设置测试数据? –

+0

仅用于测试和设置数据。 –

+1

如果你在生产中不需要它们,那么也许你不应该让它们在你的容器中进行测试。值得研究[使用单独的容器来播种数据](http://stackoverflow.com/a/33397913),或者看看您是否可以使用标准mongo调用删除/创建测试数据。 –

回答

2

不是最优雅的解决方案,但您始终可以在节点顶部创建自己的映像:安装了mongo的7.2.0,从而允许容器执行mongodump/restore。这样的图像Dockerfile应该看起来像 - FROM node:7.2.0 RUN apt-get update -y && \ apt-get install -y mongodb

然后,您可以拉这个图像,而不是正常的节点图像,并有mongo cli在您的处置。

+0

谢谢你的回答。如果有其他人感兴趣,为了能够使用相同的跑步者,我使用了Gitlab注册表:https://about.gitlab.com/2016/05/23/gitlab-container-registry/。 –