0
votes

I'm using docker in docker in my gitlab ci to run my test env and run tests in it.

In order to wait until all tests are finished I use docker wait.

tests:
    image: docker:19-git
    stage: tests
    script:
      - docker-compose -f docker-compose/my_test_env.yml up -d #setting up env
      - docker-compose -f docker-compose/tests.yml up -d #running tests
      - docker wait docker-compose-services_tests_1

I need to fail job if there are some problems with tests, but (docker wait docker-compose-services_tests_1) prints container exit code and returning this exit code is considered as success operation, so job is considered as passed. docker wait doesn't have option not to print exit code.

So I need some sh (not bash) script to run docker wait and exit with non 0 exit code if container returns non 0 exit code (to fail the job).

What is the correct way to do this?

1

1 Answers

0
votes

You have two options here

  1. Removing the -d in the second command docker-compose -f docker-compose/tests.yml up, doing this you do not need to use the third step

  2. if you really want to run the compose dettached, just add a script that captures the output of docker-compose log and according to the result, take an action, exit 0 or 1