Skip to content

Commit

Permalink
Create image contracts when creating release
Browse files Browse the repository at this point in the history
This will use the contracts created from the composition (if any)
to set the `contract` property in the release images.

This requires passing a list of ImageDescriptors returned by
compose.parse when calling release `create`.

Change-type: minor
  • Loading branch information
pipex committed Feb 28, 2025
1 parent ea2e5f8 commit 2862b6b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/release/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import type { PinejsClientCore } from 'pinejs-client-core';
import * as models from './models';
import type { Dict } from './types';

import type { Composition } from '../../lib/parse';
import type { Composition, ImageDescriptor } from '../../lib/parse';
import { parse } from '../../lib/parse';

Check failure on line 7 in lib/release/api.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (v20.18.3)

'parse' is declared but its value is never read.

Check failure on line 7 in lib/release/api.ts

View workflow job for this annotation

GitHub Actions / Flowzone / Test npm (v22.14.0)

'parse' is declared but its value is never read.

const MAX_CONCURRENT_REQUESTS = 5;

Expand Down Expand Up @@ -69,6 +70,12 @@ export interface Request {

/** 'balena.yml' contract contents */
contract?: models.JsonType;

/**
* List of image descriptors returned
* by compose.parse
*/
imgDescriptors?: ImageDescriptor[];
}

export interface Response {
Expand Down Expand Up @@ -104,6 +111,7 @@ export async function create(req: Request) {

const res = { release, serviceImages: {} } as Response;

const imgDescriptors = req.imgDescriptors ?? [];
// Create services and associated image, labels and env vars
await pMap(
Object.entries(req.composition.services),
Expand All @@ -113,6 +121,10 @@ export async function create(req: Request) {
service_name: serviceName,
});

const imgDescriptor = imgDescriptors.find(
(d) => d.serviceName === serviceName,
);

// Create images and attach labels and env vars
const img = await createImage(
api,
Expand All @@ -123,6 +135,8 @@ export async function create(req: Request) {
is_a_build_of__service: service.id,
status: 'running',
start_timestamp: new Date(),
...(imgDescriptor &&
imgDescriptor.contract && { contract: imgDescriptor.contract }),
},
);

Expand Down

0 comments on commit 2862b6b

Please sign in to comment.