Drone provides a services section in the Yaml file used for defining service containers. The below configuration composes database and cache containers.
Drone uses pod-style networking. Service containers share the same network as your build and plugin containers, and are therefore available at 127.0.0.1
pipeline: build: image: golang commands: - go build - go test +services: + database: + image: mysql + + cache: + image: redis
Service containers generally expose environment variables to customize service startup such as default usernames, passwords and ports. Please see the official image documentation to learn more.
services: database: image: mysql + environment: + - MYSQL_DATABASE=test + - MYSQL_ALLOW_EMPTY_PASSWORD=yes cache: image: redis
Service containers require time to initialize and begin accept connections. If you are unable to connect to a service you may need to wait a few seconds or implement a backoff.
pipeline: test: image: golang commands: + - sleep 15 - go get - go test services: database: image: mysql
Service containers can also be included in the pipeline section of the Yaml using the
detach parameter. This should be used when explicit control over startup order is required.
pipeline: build: image: golang commands: - go get - go build database: image: redis + detach: true test: image: golang commands: - go test