When using services in the Docker runner I’d like to inject environment variables and override command and entrypoint arguments. This is for example required when running a service like Postgres which requires POSTGRES_PASSWORD to be set.
https://hub.docker.com/_/postgres
POSTGRES_PASSWORD
This environment variable is required for you to use the PostgreSQL image. It must not be empty or undefined. This environment variable sets the superuser password for PostgreSQL. The default superuser is defined by the POSTGRES_USER
environment variable.
I’ve found that services might have the same definition as steps in the source code. I’ll try to pass the same parameters.
Name string `json:"name,omitempty"` Deps []string `json:"depends_on,omitempty"` Clone manifest.Clone `json:"clone,omitempty"` Concurrency manifest.Concurrency `json:"concurrency,omitempty"` Node map[string]string `json:"node,omitempty"` Platform manifest.Platform `json:"platform,omitempty"` Trigger manifest.Conditions `json:"conditions,omitempty"` Environment map[string]string `json:"environment,omitempty"` Services []*Step `json:"services,omitempty"` Steps []*Step `json:"steps,omitempty"` Volumes []*Volume `json:"volumes,omitempty"` PullSecrets []string `json:"image_pull_secrets,omitempty" yaml:"image_pull_secrets"` Workspace Workspace `json:"workspace,omitempty"` } // GetVersion returns the resource version. func (p *Pipeline) GetVersion() string { return p.Version } // GetKind returns the resource kind.
here is an example postgres configuration in the docs that you may find helpful
https://docs.drone.io/pipeline/docker/examples/services/postgres/
Nice, thanks!
It would be useful to include an example on the services landing page that demonstrates how to override environment variables and commands.
https://docs.drone.io/pipeline/docker/syntax/services/
On a side note: does a service inherit the root environment configuration? Is it shared between all services? e.g is it possible to:
---
kind: pipeline
type: docker
name: default
environment:
POSTGRES_PASSWORD: hello
services:
- name: postgres
image: postgres:11
This is useful if both the app and the postgres container share the POSTGRES_PASSWORD variable.
1 Like