2016-08-18 128 views
1

我有一个Makefile文件,看起来像这样:运行搬运工集成测试容器而开发的容器运行

dev: 
    docker-compose up -d --build 

test: 
    DOCKER_ENV="-test" docker-compose up -d --build 
    // run some integration tests on the containers then 
    // shut them down (and let ephemeral database disappear) 
    DOCKER_ENV="-test" docker-compose down -v 

我的搬运工,撰写看起来是这样的:

services: 
    foo: 
    container_name: foo${DOCKER_ENV} 
    image: foo:latest 
    bar: 
    container_name: bar${DOCKER_ENV} 
    image: bar:latest 

当我尝试运行make dev然后make test后者导致用新名称(“-test”)重建dev容器,而不是创建一整套单独的容器 - 这正是我想要的。

如何让开发环境保持运行并定期启动测试环境? (我们将在某个时候做这个CI,但我希望开发人员能够在本地运行所有测试。)

回答

2

从测试使用泊坞窗,撰写项目名称设置为独立的开发,如:

dev: 
    docker-compose up -d --build 

test: 
    export DOCKER_PROJ=`basename \`pwd\``"-test" 
    docker-compose -p ${DOCKER_PROJ} up -d --build 
    // run some integration tests on the containers then 
    // shut them down (and let ephemeral database disappear) 
    docker-compose -p ${DOCKER_PROJ} down -v 

(我的Makefile的语法是有点生疏,我敢肯定,有简洁的方式来做到这一点。)

+2

您也可以设置,而不是使用'-p'了'COMPOSE_PROJECT_NAME'环境变量。 – dnephin