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

后端 未结 9 1232
故里飘歌
故里飘歌 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:15

    In case you might run more docker-compose services with same name on one docker engine, and you don't know the exact name:

    docker-compose up -d
    (exit "${$(docker-compose logs -f test-chrome)##* }")
    

    echo %? - returns exit code from test-chrome service

    Benefits:

    • wait's for exact service to exit
    • uses service name, not container name
    0 讨论(0)
  • 2020-12-07 12:17

    docker-rails allows you to specify which container's error code is returned to the main process, so you CI server can determine the result. It is a great solution for CI and development for rails with docker.

    For example

    exit_code: web
    

    in your docker-rails.yml will yield the web containers exit code as a result of the command docker-rails ci test. docker-rails.yml is just a meta wrapper around the standard docker-compose.yml that gives you the potential to inherit/reuse the same base config for different environments i.e. development vs test vs parallel_tests.

    0 讨论(0)
  • 2020-12-07 12:21

    Use docker wait to get the exit code:

    $ docker-compose -p foo up -d
    $ ret=$(docker wait foo_bar_1)
    

    foo is the "project name". In the example above, I specified it explicitly, but if you don't supply it, it's the directory name. bar is the name you give to the system under test in your docker-compose.yml.

    Note that docker logs -f does the right thing, too, exiting when the container stops. So you can put

    $ docker logs -f foo_bar_1
    

    between the docker-compose up and the docker wait so you can watch your tests run.

    0 讨论(0)
提交回复
热议问题