Hi,
Sometimes i get build failed in CircleCi for first time, and if i rebuild the test it works well, i don’t know what is the problem!
Build failed message
#!/bin/bash -eo pipefail
set -x
docker-compose -f docker-compose.ci.yml up -d prod
docker-compose -f docker-compose.ci.yml exec prod curl --retry 10 --retry-delay 5 -v http://127.0.0.1:8000
+ docker-compose -f docker-compose.ci.yml up -d prod
Creating fugokiui_prod_1
+ docker-compose -f docker-compose.ci.yml exec prod curl --retry 10 --retry-delay 5 -v http://127.0.0.1:8000
* Rebuilt URL to: http://127.0.0.1:8000/
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* connect to 127.0.0.1 port 8000 failed: Connection refused
* Failed to connect to 127.0.0.1 port 8000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 127.0.0.1 port 8000: Connection refused
Exited with code 7
Any idea about this topic please?
halfer
February 9, 2018, 5:26pm
2
Yep, the problem is here:
You’re not waiting for this server long enough before you’re trying to use it. There’s a race condition between full server init and your tests, and on the random occasions the server starts up first, things will pass.
If that’s not sufficient help, readers would probably need to see your Circle config, and perhaps your docker-compose.yml
as well, to see where a wait would need to be added. However, I suggest you give it a go first.
2 Likes
I think sleep
command should fix this problem
Yes @halfer sleep
command fix this issue,
This is my config before
- run:
name: Run tests
command: |
set -x
docker-compose -f docker-compose.ci.yml up -d prod
docker-compose -f docker-compose.ci.yml exec prod curl --retry 10 --retry-delay 5 -v http://127.0.0.1:8000
Config after
- run:
name: Run tests
command: |
set -x
docker-compose -f docker-compose.ci.yml up -d prod
sleep 30
docker-compose -f docker-compose.ci.yml exec prod curl --retry 10 --retry-delay 5 -v http://127.0.0.1:8000
Thanks @halfer +1
1 Like
halfer
February 12, 2018, 3:30pm
5
Great stuff. You’ll probably find a smaller sleep is fine - usually under 10 seconds will do it, but it depends what’s in the DC config.
Yes, it depends of docker-compose config