Reputation: 43
While building my application on Travis I am trying to run the tests within a Docker container. The container starts and the tests are run, and when I log the container output I can see they have passed. It is my understanding I can use grep for this as seen below. So this is my travis script:
script:
docker-compose up -d
docker logs dockertestapp_app_1
docker logs 2>&1 dockertestapp_app_1 | grep -q 'npm info ok'
I just want to grep the output of the container logs to see whether or not the tests pass but it always fails. Am I missing something simple?
Thank you in advance!
Upvotes: 0
Views: 856
Reputation: 683
In order to avoid a sleep of 60 seconds you described in your comment, start your tests manually doing something like this:
docker exec -it dockertestapp_app_1 bash -c 'tests.py > /proc/1/fd/1'
Note I'm executing a test file (in this example, tests.py
) and setting output to /proc/1/fd/1
. This way you can normally grep the expression that means your tests passed as you are currently doing.
TIP: you may not need to output to /proc/1/fd/1
for docker logs as your test script may return a non-zero exit code to indicate that tests failed. This way you don't even need the grep line in your script.
Upvotes: 1