A TypeScript wrapper around compose-go that parses and validates Docker Compose files for balena applications.
This project provides a Node.js library that uses a Go binary (built from compose-go) to parse Docker Compose files and normalize them for use with balena. It handles:
- Parsing standard Docker Compose files
- Validating balena-specific constraints
- Converting compose configurations to balena-compatible formats
- Transforming compositions into image descriptors for building/pulling
- Node.js 20+
- Go 1.24+ (for local builds)
npm i @balena/compose-parser
The project consists of two main components:
- Go Binary (
lib/main.go): A wrapper around compose-go that outputs structured JSON - TypeScript Library (
lib/): Node.js library that calls the Go binary and processes results
# Build everything
npm run build
# Build Go binary only
npm run build:gonpm run testRuns TypeScript unit tests that test the library functions directly. This does not cover the entirety of the functionality, as due to CI constraints, tests using the Go binary are performed in Docker.
npm run test:compose
# Or the following if running build:go first:
npm run test:integrationThe integration tests validate the functionality of the compose-go wrapper for parsing input compose files. npm run test:compose is for running the tests in Docker, but the tests can be run directly if a built Go binary is available as generated from npm run build:go.
# Check for linting issues
npm run lint
# Fix auto-fixable linting issues
npm run lint-fiximport { parse, defaultComposition, toImageDescriptors } from '@balena/compose-parser';
// Parse a compose file
const composition = await parse('docker-compose.yml');
// Parse multiple compose files (later files override earlier ones)
const composition = await parse([
'docker-compose.yml',
'docker-compose.override.yml'
]);
// Convert composition to image descriptors for building/pulling
const imageDescriptors = toImageDescriptors(composition);The toImageDescriptors() function converts a composition into descriptors that can be used for image operations:
const descriptors = toImageDescriptors(composition);
// Returns array of:
// {
// serviceName: string,
// image: string | BuildConfig,
// contract?: ContractObject // if service has contract requirement labels
// }Supports validation of contract requirement labels:
io.balena.features.requires.sw.supervisor: Semver range for Supervisor versionio.balena.features.requires.hw.device-type: Device type slugio.balena.features.requires.arch.sw: Architecture (aarch64,amd64,armv7hf, etc.)io.balena.features.requires.sw.l4t: L4T version range