Skip to content

feat(configuration): support disabling quadlet default dependencies #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@
"command": "podlet.compose",
"title": "Podlet: compose"
}
]
],
"configuration": {
"title": "Podman Quadlet",
"properties": {
"quadlet.generate.DefaultDependencies": {
"type": "boolean",
"default": true,
"description": "Add Quadlet’s default network dependencies to the unit (default is true)."
}
}
}
},
"devDependencies": {
"@podman-desktop/api": "^1.18.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
window,
cli as cliApi,
commands as commandsApi,
configuration as configurationApi,
} from '@podman-desktop/api';
import { MainService } from './services/main-service';

Expand All @@ -28,6 +29,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<void
cliApi: cliApi,
commandsApi: commandsApi,
containers: containerEngine,
configurationApi: configurationApi,
});
return main.init();
}
Expand Down
39 changes: 39 additions & 0 deletions packages/backend/src/services/configuration-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**********************************************************************
* Copyright (C) 2025 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/
import type { Disposable, configuration as configurationApi, Configuration } from '@podman-desktop/api';
import type { AsyncInit } from '../utils/async-init';

interface Dependencies {
configurationApi: typeof configurationApi;
}

export class ConfigurationService implements Disposable, AsyncInit {
#configuration: Configuration;

constructor(protected dependencies: Dependencies) {
this.#configuration = this.dependencies.configurationApi.getConfiguration('quadlet');

Check failure on line 29 in packages/backend/src/services/configuration-service.ts

View workflow job for this annotation

GitHub Actions / unit tests / ubuntu-24.04

src/services/main-service.spec.ts > ensure init register all APIs

TypeError: Cannot read properties of undefined (reading 'getConfiguration') ❯ new ConfigurationService src/services/configuration-service.ts:29:62 ❯ MainService.init src/services/main-service.ts:112:27 ❯ src/services/main-service.spec.ts:108:3

Check failure on line 29 in packages/backend/src/services/configuration-service.ts

View workflow job for this annotation

GitHub Actions / unit tests / macos-15

src/services/main-service.spec.ts > ensure init register all APIs

TypeError: Cannot read properties of undefined (reading 'getConfiguration') ❯ new ConfigurationService src/services/configuration-service.ts:29:62 ❯ MainService.init src/services/main-service.ts:112:27 ❯ src/services/main-service.spec.ts:108:3

Check failure on line 29 in packages/backend/src/services/configuration-service.ts

View workflow job for this annotation

GitHub Actions / unit tests / ubuntu-24.04

src/services/main-service.spec.ts > ensure init register all APIs

TypeError: Cannot read properties of undefined (reading 'getConfiguration') ❯ new ConfigurationService src/services/configuration-service.ts:29:62 ❯ MainService.init src/services/main-service.ts:112:27 ❯ src/services/main-service.spec.ts:108:3
}

async init(): Promise<void> {}

getQuadletDefaultDependencies(): boolean {
return this.#configuration.get<boolean>('generate.DefaultDependencies') ?? true;
}

dispose(): void {}
}
11 changes: 11 additions & 0 deletions packages/backend/src/services/main-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
extensions,
process as processApi,
commands as commandsApi,
configuration as configurationApi,
provider,
window,
cli as cliApi,
Expand Down Expand Up @@ -44,6 +45,7 @@ import { DialogService } from './dialog-service';
import { DialogApiImpl } from '../apis/dialog-api-impl';
import { DialogApi } from '/@shared/src/apis/dialog-api';
import { PodletJsService } from './podlet-js-service';
import { ConfigurationService } from './configuration-service';

interface Dependencies {
extensionContext: ExtensionContext;
Expand All @@ -55,6 +57,7 @@ interface Dependencies {
cliApi: typeof cliApi;
commandsApi: typeof commandsApi;
containers: typeof containerEngine;
configurationApi: typeof configurationApi;
}

export class MainService implements Disposable, AsyncInit {
Expand Down Expand Up @@ -105,6 +108,13 @@ export class MainService implements Disposable, AsyncInit {
await routing.init();
this.#disposables.push(routing);

// The configuration
const configuration = new ConfigurationService({
configurationApi: this.dependencies.configurationApi,
});
await configuration.init();
this.#disposables.push(configuration);

// The provider service register subscribers events for provider updates
const providers = new ProviderService({
providers: this.dependencies.providers,
Expand Down Expand Up @@ -175,6 +185,7 @@ export class MainService implements Disposable, AsyncInit {
containers: containers,
images: images,
telemetry: this.#telemetry,
configuration: configuration,
});

/**
Expand Down
15 changes: 15 additions & 0 deletions packages/backend/src/services/podlet-js-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
import { ContainerGenerator, Compose, ImageGenerator } from 'podlet-js';
import { readFile } from 'node:fs/promises';
import { TelemetryEvents } from '../utils/telemetry-events';
import type { ConfigurationService } from './configuration-service';
import type { QuadletSection } from 'podlet-js/dist/models/quadlet-section';

interface Dependencies {
containers: ContainerService;
images: ImageService;
telemetry: TelemetryLogger;
configuration: ConfigurationService;
}

export class PodletJsService {
Expand All @@ -47,9 +50,20 @@
return new ContainerGenerator({
container,
image,
quadlet: this.buildQuadletSection(),
}).generate();
}

protected buildQuadletSection(): undefined | QuadletSection {
const defaultDependencies = this.dependencies.configuration.getQuadletDefaultDependencies();

Check failure on line 58 in packages/backend/src/services/podlet-js-service.ts

View workflow job for this annotation

GitHub Actions / unit tests / ubuntu-24.04

src/services/podlet-js-service.spec.ts > image quadlets > should use the container and image service to inspect resources

TypeError: Cannot read properties of undefined (reading 'getQuadletDefaultDependencies') ❯ PodletJsService.buildQuadletSection src/services/podlet-js-service.ts:58:65 ❯ PodletJsService.generateImage src/services/podlet-js-service.ts:78:21 ❯ PodletJsService.generate src/services/podlet-js-service.ts:99:18 ❯ src/services/podlet-js-service.spec.ts:173:20

Check failure on line 58 in packages/backend/src/services/podlet-js-service.ts

View workflow job for this annotation

GitHub Actions / unit tests / ubuntu-24.04

src/services/podlet-js-service.spec.ts > container quadlets > generate container should send telemetry event

TypeError: Cannot read properties of undefined (reading 'getQuadletDefaultDependencies') ❯ PodletJsService.buildQuadletSection src/services/podlet-js-service.ts:58:65 ❯ PodletJsService.generateContainer src/services/podlet-js-service.ts:53:21 ❯ PodletJsService.generate src/services/podlet-js-service.ts:97:18 ❯ src/services/podlet-js-service.spec.ts:131:5

Check failure on line 58 in packages/backend/src/services/podlet-js-service.ts

View workflow job for this annotation

GitHub Actions / unit tests / ubuntu-24.04

src/services/podlet-js-service.spec.ts > container quadlets > should use the container and image service to inspect resources

TypeError: Cannot read properties of undefined (reading 'getQuadletDefaultDependencies') ❯ PodletJsService.buildQuadletSection src/services/podlet-js-service.ts:58:65 ❯ PodletJsService.generateContainer src/services/podlet-js-service.ts:53:21 ❯ PodletJsService.generate src/services/podlet-js-service.ts:97:18 ❯ src/services/podlet-js-service.spec.ts:98:20

Check failure on line 58 in packages/backend/src/services/podlet-js-service.ts

View workflow job for this annotation

GitHub Actions / unit tests / macos-15

src/services/podlet-js-service.spec.ts > image quadlets > should use the container and image service to inspect resources

TypeError: Cannot read properties of undefined (reading 'getQuadletDefaultDependencies') ❯ PodletJsService.buildQuadletSection src/services/podlet-js-service.ts:58:65 ❯ PodletJsService.generateImage src/services/podlet-js-service.ts:78:21 ❯ PodletJsService.generate src/services/podlet-js-service.ts:99:18 ❯ src/services/podlet-js-service.spec.ts:173:20

Check failure on line 58 in packages/backend/src/services/podlet-js-service.ts

View workflow job for this annotation

GitHub Actions / unit tests / macos-15

src/services/podlet-js-service.spec.ts > container quadlets > generate container should send telemetry event

TypeError: Cannot read properties of undefined (reading 'getQuadletDefaultDependencies') ❯ PodletJsService.buildQuadletSection src/services/podlet-js-service.ts:58:65 ❯ PodletJsService.generateContainer src/services/podlet-js-service.ts:53:21 ❯ PodletJsService.generate src/services/podlet-js-service.ts:97:18 ❯ src/services/podlet-js-service.spec.ts:131:5

Check failure on line 58 in packages/backend/src/services/podlet-js-service.ts

View workflow job for this annotation

GitHub Actions / unit tests / macos-15

src/services/podlet-js-service.spec.ts > container quadlets > should use the container and image service to inspect resources

TypeError: Cannot read properties of undefined (reading 'getQuadletDefaultDependencies') ❯ PodletJsService.buildQuadletSection src/services/podlet-js-service.ts:58:65 ❯ PodletJsService.generateContainer src/services/podlet-js-service.ts:53:21 ❯ PodletJsService.generate src/services/podlet-js-service.ts:97:18 ❯ src/services/podlet-js-service.spec.ts:98:20

Check failure on line 58 in packages/backend/src/services/podlet-js-service.ts

View workflow job for this annotation

GitHub Actions / unit tests / ubuntu-24.04

src/services/podlet-js-service.spec.ts > image quadlets > should use the container and image service to inspect resources

TypeError: Cannot read properties of undefined (reading 'getQuadletDefaultDependencies') ❯ PodletJsService.buildQuadletSection src/services/podlet-js-service.ts:58:65 ❯ PodletJsService.generateImage src/services/podlet-js-service.ts:78:21 ❯ PodletJsService.generate src/services/podlet-js-service.ts:99:18 ❯ src/services/podlet-js-service.spec.ts:173:20

Check failure on line 58 in packages/backend/src/services/podlet-js-service.ts

View workflow job for this annotation

GitHub Actions / unit tests / ubuntu-24.04

src/services/podlet-js-service.spec.ts > container quadlets > generate container should send telemetry event

TypeError: Cannot read properties of undefined (reading 'getQuadletDefaultDependencies') ❯ PodletJsService.buildQuadletSection src/services/podlet-js-service.ts:58:65 ❯ PodletJsService.generateContainer src/services/podlet-js-service.ts:53:21 ❯ PodletJsService.generate src/services/podlet-js-service.ts:97:18 ❯ src/services/podlet-js-service.spec.ts:131:5

Check failure on line 58 in packages/backend/src/services/podlet-js-service.ts

View workflow job for this annotation

GitHub Actions / unit tests / ubuntu-24.04

src/services/podlet-js-service.spec.ts > container quadlets > should use the container and image service to inspect resources

TypeError: Cannot read properties of undefined (reading 'getQuadletDefaultDependencies') ❯ PodletJsService.buildQuadletSection src/services/podlet-js-service.ts:58:65 ❯ PodletJsService.generateContainer src/services/podlet-js-service.ts:53:21 ❯ PodletJsService.generate src/services/podlet-js-service.ts:97:18 ❯ src/services/podlet-js-service.spec.ts:98:20
if (!defaultDependencies) {
return {
DefaultDependencies: defaultDependencies,
};
}
return undefined;
}

/**
* Using the `podlet-js` package, generate a stringify {@link ImageQuadlet}
* @param engineId
Expand All @@ -61,6 +75,7 @@

return new ImageGenerator({
image: image,
quadlet: this.buildQuadletSection(),
}).generate();
}

Expand Down
7 changes: 7 additions & 0 deletions packages/podlet-js/src/containers/container-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ import { ReadOnly } from './builders/read-only';
import { Mount } from './builders/mount';
import { Generator } from '../utils/generator';
import { Restart } from './builders/restart';
import type { QuadletSection } from '../models/quadlet-section';

interface Dependencies {
container: ContainerInspectInfo;
image: ImageInspectInfo;
quadlet?: QuadletSection;
}

export class ContainerGenerator extends Generator<Dependencies> {
Expand Down Expand Up @@ -63,6 +65,11 @@ export class ContainerGenerator extends Generator<Dependencies> {
} as ContainerQuadlet,
);

// user may specify a quadlet section
if (this.dependencies.quadlet) {
containerQuadlet.Quadlet = this.dependencies.quadlet;
}

return stringify(this.format(containerQuadlet));
}
}
7 changes: 7 additions & 0 deletions packages/podlet-js/src/images/image-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import { Generator } from '../utils/generator';
import type { ImageInspectInfo } from '@podman-desktop/api';
import { stringify } from 'js-ini';
import type { ImageQuadlet } from '../models/image-quadlet';
import type { QuadletSection } from '../models/quadlet-section';

interface Dependencies {
image: ImageInspectInfo;
quadlet?: QuadletSection;
}

export class ImageGenerator extends Generator<Dependencies> {
Expand All @@ -36,6 +38,11 @@ export class ImageGenerator extends Generator<Dependencies> {
},
};

// user may specify a quadlet section
if (this.dependencies.quadlet) {
image.Quadlet = this.dependencies.quadlet;
}

return stringify(this.format(image));
}
}
2 changes: 2 additions & 0 deletions packages/podlet-js/src/models/container-quadlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/
import type { ServiceQuadlet } from './service-quadlet';
import type { QuadletSection } from './quadlet-section';

/**
* Learn more about Container Quadlet https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html#container-units-container
*/
export interface ContainerQuadlet {
Service?: ServiceQuadlet;
Quadlet?: QuadletSection;
Container: {
/**
* Add these capabilities, in addition to the default Podman capability set, to the container.
Expand Down
2 changes: 2 additions & 0 deletions packages/podlet-js/src/models/image-quadlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/
import type { ServiceQuadlet } from './service-quadlet';
import type { QuadletSection } from './quadlet-section';

/**
* Learn more about Image Quadlet https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html#image-units-image
*/
export interface ImageQuadlet {
Service?: ServiceQuadlet;
Quadlet?: QuadletSection;
Image: {
/**
* All tagged images in the repository are pulled.
Expand Down
28 changes: 28 additions & 0 deletions packages/podlet-js/src/models/quadlet-section.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**********************************************************************
* Copyright (C) 2025 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

/**
* Learn more about Quadlet Section https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html#quadlet-section-quadlet
*/
export interface QuadletSection {
/**
* Add Quadlet’s default network dependencies to the unit.
* @default true
*/
DefaultDependencies: boolean;
}
Loading