Docker-compose run service if another service status is 0 (success)
I am pretty new to Docker and Docker compose.
I want to use docker compose to test my project and publish it if tests are ok. If tests are failed, it should not publish the app at all.
Here is my 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.
After that, in my
testAndPublish.sh file, I would like to say:
docker-compose up if [ $? = 0 ]; then # If all the services succeed .... else .... fi
So if test or publish steps are failed, I am not going to push it.
How can I build step like processes in docker-compose?
One Solution collect form web for “Docker-compose run service if another service status is 0 (success)”
I think you’re trying to do everything with
docker-compose which is the wrong way around.
When it comes to CI (f.e. Travis or CircleCI) I always make my workflow as follows:
- let’s say you have a
installstep I always put things like f.e.
docker-compose run web npm installand others
- at the
teststep I would put
docker-compose run web npm testor something similar like
docker-compose run web my-test-script.sh, that way you’ll know that the tests will run in the declared docker environment, if they fail this step fails and the whole test step in the CI fails which is desired
- at the
deploystep I would run some
deploy.shscript which will build the image from Dockerfile (the one that
webuses) and push it for example to Docker Hub.
This way your CI test routine still depends on specific Docker environment but the deploy push (which doesn’t need Docker) is kept separately from the application which makes it more convinient imho.