Using docker-compose with CI - how to deal with exit codes and daemonized linked containers?

后端 未结 9 1239
故里飘歌
故里飘歌 2020-12-07 11:45

Right now our Jenkins agents generate a docker-compose.yml for each of our Rails projects and then run docker-compose up. The docker-compose.yml has a main \"web\" container

9条回答
  •  眼角桃花
    2020-12-07 12:11

    --exit-code-from SERVICE and --abort-on-container-exit don't work in scenarios where you need to run all containers to completion, but fail if one of them exited early. An example might be if running 2 test suits in concurrently in different containers.

    With @spenthil's suggestion, you can wrap docker-compose in a script that will fail if any containers do.

    #!/bin/bash
    set -e
    
    # Wrap docker-compose and return a non-zero exit code if any containers failed.
    
    docker-compose "$@"
    
    exit $(docker-compose -f docker-compose.ci.build.yml ps -q | tr -d '[:space:]' |
      xargs docker inspect -f '{{ .State.ExitCode }}' | grep -v 0 | wc -l | tr -d '[:space:]')
    

    Then on your CI server simply change docker-compose up to ./docker-compose.sh up.

提交回复
热议问题