Services not accessible

Raised https://github.com/drone/drone/issues/2362 earlier which describes the problem.

drone exec is not consistent with the following drone.yml

pipeline:
  ping:
    image: postgres
    commands:
      - sleep 10
      - psql -U postgres -d test -h database -c "SELECT * FROM pg_catalog.pg_tables;"

services:
  database:
    image: postgres
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_DB=test

Sometimes succeeds but most of the time it fails with the following error

[ping:L15:10s] psql: could not translate host name "database" to address: Name or service not known

To trigger a success I need to change the service name from ‘database’ to something else and then it succeeds for the next run or for a couple of runs then it goes back to the above error. Very annoying.

The yaml file works as-is for me, without modification

It’s more consistent in Ubuntu … 0 failures after a few executions :S

I’m running:
drone 0.8.3
docker version 17.12.0-ce, build c97c6d6
macos 10.12.6

If you kill the CLI while it is running, it may not have time to cleanup the drone_default network, which could impact subsequent executions.

hmm… docker network ls returns (amongst others)

1fc1ec378ea5        drone_default                      bridge              local
0dfda9901367        drone_default                      bridge              local
b64590d836e2        drone_default                      bridge              local
10eb13a4f2dc        drone_default                      bridge              local
63bfe0c48e3d        drone_default                      bridge              local

Yes, you need to remove those. That happens if the CLI gets killed and is unable to cleanup after itself. This has been discussed in prior threads [1][2]

[1] Multiple drone_default networks created with services
[2] Service hostname is intermittently being resolved to wrong IPs

yeah, worked after I removed the networks manually. Do you think the same can happen on the actual drone server? Because I’ve noticed inconsistent behaviour there as well.

No, the server creates a unique network name per-pipeline execution.

docker network prune comes handy when you do exec frequently.

Thanks for the tip laszlocph. Still find it strange that the drone cli allows you to be in that erroneous state without providing any warnings.

In the most recent version I see that if you have multiple drone networks, the CLI warns you about them and you can clean them up.