Services
Crow provides a services: section in the pipeline config file for “service” containers.
These are static daemon services like databases or APIs which are then used/consumed by other containers within the pipeline.
To illustrate possible use cases, the below examples uses a “database” and a “cache” service.
Hostnames
Section titled “Hostnames”Services are accessed via DNS using their assigned hostnames.
In the example below, the MySQL service is assigned the hostname database and is subsequently available at database:3306.
steps: - name: build image: golang commands: - go build - go test
services: - name: database image: mysql
- name: cache image: redisPorts and Protocol
Section titled “Ports and Protocol”Defining ports and their protocol is supported:
services: - name: database image: mysql ports: - 3306
- name: wireguard image: wg ports: - 51820/udpConfiguration
Section titled “Configuration”Service containers allow exposing environment variables to customize their startup.
services: - name: database image: mysql environment: - MYSQL_DATABASE=test - MYSQL_ALLOW_EMPTY_PASSWORD=yes
- name: cache image: redisService containers like databases benefit greatly from tmpfs mounts, which store data in RAM instead of on disk. This can significantly speed up test pipelines.
services: - name: database image: postgres:18 tmpfs: - /var/lib/postgresql environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres
- name: cache image: mysql:9 tmpfs: - /var/lib/mysql environment: MYSQL_DATABASE: test MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'See the tmpfs section in the workflow syntax for more details on size limits and mount options.
Detachment
Section titled “Detachment”Services always start at the beginning of a workflow, asynchronously to any other step.
With the detach option, the execution order can be controlled in a more granular way.
This setting allows using normal steps as implicit “service” steps which honor the specified execution order.
These steps will also terminate at the end of the workflow.
steps: - name: build image: golang commands: - go build - go test
- name: database image: redis detach: true
- name: test image: golang commands: - go testInitialization
Section titled “Initialization”Service containers require time to initialize and begin accepting connections.
If the service is not yet available when the first step tries to connect and using detach is not an option, adding a short sleep command can help:
steps: - name: test image: golang commands: - sleep 15 - go get - go test
services: - name: database image: mysqlFull example
Section titled “Full example”services: - name: database image: mysql environment: - MYSQL_DATABASE=test - MYSQL_ROOT_PASSWORD=examplesteps: - name: get-version image: ubuntu commands: - ( apt update && apt dist-upgrade -y && apt install -y mysql-client 2>&1 )> /dev/null - sleep 20s # need to wait for mysql-server init - echo 'SHOW VARIABLES LIKE "version"' | mysql -u root -h database test -p example