balena-supervisor/docker-compose.test.yml
Kyle Harding 33b29cfa22
Run test supervisor under a different service name
The docker compose V2 spec no longer accepts `network_mode: bridge`,
which means we can no longer override the network configuration of
the `balena-supervisor` service for tests.

For this reason we now create a separate service to run the built
supervisor `balena-supervisor-sut` and run API tests against this
service instead of the default `balena-supervisor`.

Change-type: patch
2023-05-03 09:33:22 -04:00

116 lines
3.0 KiB
YAML

version: '2.3'
services:
balena-supervisor-sut:
build:
context: ./
dockerfile: Dockerfile.template
args:
ARCH: ${ARCH:-amd64}
command: ['/wait-for-it.sh', '--', '/usr/src/app/entry.sh']
stop_grace_period: 3s
# Use bridge networking for the tests
environment:
DOCKER_HOST: tcp://docker:2375
DBUS_SYSTEM_BUS_ADDRESS: unix:path=/run/dbus/system_bus_socket
# Required to skip device mounting in test env
TEST: 1
depends_on:
- docker
- dbus
- dbus-services
volumes:
- dbus:/run/dbus
- ./test/data/root:/mnt/root
- ./test/data/root/mnt/boot:/mnt/boot
- ./test/lib/wait-for-it.sh:/wait-for-it.sh
tmpfs:
- /data # sqlite3 database
dbus:
image: balenablocks/dbus
stop_grace_period: 3s
environment:
DBUS_CONFIG: session.conf
DBUS_ADDRESS: unix:path=/run/dbus/system_bus_socket
volumes:
- dbus:/run/dbus
# Fake system service to listen for supervisor
# requests
dbus-services:
build: ./test/lib/dbus
stop_grace_period: 3s
depends_on:
- dbus
volumes:
- dbus:/run/dbus
environment:
DBUS_SYSTEM_BUS_ADDRESS: unix:path=/run/dbus/system_bus_socket
docker:
image: docker:dind
stop_grace_period: 3s
privileged: true
environment:
DOCKER_TLS_CERTDIR: ''
command: --tls=false # --debug
sut:
# Build the supervisor code for development and testing
build:
context: ./
dockerfile: Dockerfile.template
target: test
args:
# Change this if testing in another architecture
ARCH: ${ARCH:-amd64}
command:
[
'./test/lib/wait-for-it.sh',
'--supervisor',
'--',
'npm',
'run',
'test:integration',
]
depends_on:
- balena-supervisor-sut
- docker
- dbus
- dbus-services
stop_grace_period: 3s
volumes:
- dbus:/run/dbus
# Set required supervisor configuration variables here
environment:
DOCKER_HOST: tcp://docker:2375
DBUS_SYSTEM_BUS_ADDRESS: unix:path=/run/dbus/system_bus_socket
BALENA_SUPERVISOR_ADDRESS: http://balena-supervisor-sut:48484
# Required by migrations
CONFIG_MOUNT_POINT: /mnt/boot/config.json
# Required to set mountpoints normally set in entry.sh
ROOT_MOUNTPOINT: /mnt/root
BOOT_MOUNTPOINT: /mnt/boot
HOST_OS_VERSION_PATH: /mnt/boot/os-release
STATE_MOUNTPOINT: /mnt/state
DATA_MOUNTPOINT: /mnt/data
DATABASE_PATH: /data/database.sqlite
# Set required mounts as tmpfs or volumes here
# if specific files need to be backed up between tests,
# make sure to add them to the `testfs` configuration under
# .mochapodrc.yml
tmpfs:
- /data
- /mnt/root
- /mnt/boot
- /mnt/state
- /mnt/data
volumes:
dbus:
driver_opts:
# Use tmpfs to avoid files remaining between runs
type: tmpfs
device: tmpfs