如果另一个服务状态是0(成功),Docker-compose运行服务

我对Docker和Docker组合非常新。

我想用docker撰写来testing我的项目,如果testing好的话发布它。 如果testing失败,则不应该发布应用程序。

这是我的docker-compose.yml

version: '3' services: mongodb: image: mongo test: build: context: . dockerfile: Dockerfile.tests links: - mongodb publish: build: context: . dockerfile: Dockerfile.publish ?? # I want to say here that publish step is dependent to test. 

之后,在我的testAndPublish.sh文件中,我想说:

  docker-compose up if [ $? = 0 ]; then # If all the services succeed .... else .... fi 

所以如果testing或发布步骤失败,我不会推它。

如何在docker-compose中构build像stream程一样的步骤? 谢谢。

我想你正在试图用docker-compose来做所有的事情,这是错误的。

当谈到CI(Fe Travis或CircleCI)时,我总是把我的工作stream程如下:

  • 假设您有一个web节点和database节点
  • install步骤travis.ymlcircle.yml ,我总是把东西像docker-compose run web npm install和其他
  • test步骤中,我会把docker-compose run web npm test或类似的东西,像docker-compose run web my-test-script.sh ,这样你就会知道testing将在声明的docker环境中运行,如果他们失败此步骤失败,并且CI中的整个testing步骤失败
  • deploy步骤中,我将运行一些deploy.sh脚本,它将从Dockerfile( web使用的那个)构build映像,并将其推送到Docker Hub。

通过这种方式,您的CItesting例程仍然依赖于特定的Docker环境,但是部署推送(不需要Docker)与应用程序分开存放,这使得它更方便。