Today I../Today I Learned

211021) docker-compose --exit-code-from

HJChung 2021. 10. 22. 12:20
name: ML application unittest

on:
  push:
    branches: [test]

jobs: 
  test: 
    runs-on: [self-hosted, gpu]
    steps:
      - uses: actions/checkout@v2
      - name: ML inference code Unittest
        run: docker-compose -f docker-compose-unittest.yml up

이런 github actions workflow script가 있다고 하자. 

그런데 docker-compose 을 통해 실행된 unittest가 실패해서 

FAILED (errors=1)
[container] exited with code 1

으로 실행이 종료되어도 docker-compose가 정상적으로 작동하였다면 exit-code 0을 return하고, 그 후에 container에서 이루어진 job들이 fail하여서 이 job들의 exit code를 반영하지 않는다. 

 

Hi,
this is not an issue with this plugin, but with Docker Compose itself. It returns exit-code 0 if the containers are properly started. According to your log, they was properly started so Docker Compose returned 0. Your container failed later.
I don't know your use case but in general, there are two solutions.
If the failing container is a main service (e.g. application, while other containers are just databases) then you could use an additional parameter for docker-compose up command, called --exit-code-from.
If you have more containers with equal importance, then I would suggest to define a healthcheck. It can be defined in Dockerfile or in docker-compose.yml.
The healthcheck should check if your application is running correctly.
Hope it helps.

https://github.com/avast/gradle-docker-compose-plugin/issues/149

 

이를 정상적으로 반영하고 싶다면 --exit-code-from을 사용하면 된다

--exit-code-from SERVICE   Return the exit code of the selected service
                               container. Implies --abort-on-container-exit.

 

https://docs.docker.com/compose/reference/up/

 

docker-compose up

 

docs.docker.com

https://docs.github.com/en/actions/creating-actions/setting-exit-codes-for-actions

 

Setting exit codes for actions - GitHub Docs

You can use exit codes to set the status of an action. GitHub displays statuses to indicate passing or failing actions.

docs.github.com