Skip to content

Commit

Permalink
Add slug to contracts from requirement labels
Browse files Browse the repository at this point in the history
This ensures that the supervisor accepts contracts generated when using
the label. See
https://github.com/balena-os/balena-supervisor/blob/master/src/lib/contracts.ts#L194-L206
for the validation object.

Change-type: patch
  • Loading branch information
pipex committed Mar 3, 2025
1 parent 6fcfba1 commit c43606b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/parse/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ export function parse(c: Composition): ImageDescriptor[] {
}

function createContractFromLabels(
serviceName: string,
labels?: Dict<string>,
): ContractObject | null {
const requires = Object.entries(labels ?? {}).flatMap(([key, value]) => {
Expand All @@ -626,6 +627,7 @@ function createContractFromLabels(

return {
type: 'sw.container',
slug: `contract-for-${serviceName}`,
requires,
};
}
Expand All @@ -634,7 +636,7 @@ function createImageDescriptor(
serviceName: string,
service: Service,
): ImageDescriptor {
const contract = createContractFromLabels(service.labels);
const contract = createContractFromLabels(serviceName, service.labels);
if (service.image && !service.build) {
return {
serviceName,
Expand Down
3 changes: 3 additions & 0 deletions test/multibuild/contracts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ describe('Container contracts', () => {
.to.have.property('contract')
.that.deep.equals({
type: 'sw.container',
slug: 'contract-for-one',
requires: [
{
type: 'hw.device-type',
Expand All @@ -156,6 +157,7 @@ describe('Container contracts', () => {
.to.have.property('contract')
.that.deep.equals({
type: 'sw.container',
slug: 'contract-for-two',
requires: [
{
type: 'sw.supervisor',
Expand Down Expand Up @@ -207,6 +209,7 @@ describe('Container contracts', () => {
.to.have.property('contract')
.that.deep.equals({
type: 'sw.container',
slug: 'contract-for-other',
requires: [
{
type: 'hw.device-type',
Expand Down

0 comments on commit c43606b

Please sign in to comment.