Skip to content

Commit ca19def

Browse files
committed
feat: add chown (linux only)
### What does this PR do? * Adds chown to the advanced settings page for build * Only applicable to Linux (see: osbuild/bootc-image-builder#576) ### Screenshot / video of UI <!-- If this PR is changing UI, please include screenshots or screencasts showing the difference --> ### What issues does this PR fix or reference? <!-- Include any related issues from Podman Desktop repository (or from another issue tracker). --> Closes #472 ### How to test this PR? <!-- Please explain steps to reproduce --> 1. Be on Linux 2. Build an image 3. See that it is chown (ex. ls -l /outputdir) Signed-off-by: Charlie Drage <[email protected]>
1 parent 5de5222 commit ca19def

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

packages/backend/src/build-disk-image.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,28 @@ test('test build config json passed in', async () => {
431431
expect(options.HostConfig.Binds[2]).toEqual(build.buildConfigFilePath + ':/config.json:ro');
432432
}
433433
});
434+
435+
test('test chown works when passed into createBuilderImageOptions', async () => {
436+
const name = 'test123-bootc-image-builder';
437+
const build = {
438+
image: 'test-image',
439+
tag: 'latest',
440+
type: ['raw'],
441+
arch: 'amd64',
442+
folder: '/tmp/foo/bar/qemutest4',
443+
chown: '1000:1000',
444+
} as BootcBuildInfo;
445+
446+
const options = createBuilderImageOptions(name, build);
447+
448+
expect(options).toBeDefined();
449+
expect(options.HostConfig).toBeDefined();
450+
expect(options.HostConfig?.Binds).toBeDefined();
451+
if (options.HostConfig?.Binds) {
452+
expect(options.HostConfig.Binds.length).toEqual(2);
453+
expect(options.HostConfig.Binds[0]).toEqual(build.folder + ':/output/');
454+
expect(options.HostConfig.Binds[1]).toEqual('/var/lib/containers/storage:/var/lib/containers/storage');
455+
}
456+
expect(options.Cmd).toContain('--chown');
457+
expect(options.Cmd).toContain(build.chown);
458+
});

packages/backend/src/build-disk-image.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ export function createBuilderImageOptions(
456456
}
457457
}
458458

459+
// If there is the chown in build, add the --chown flag to the command with the value in chown
460+
if (build.chown) {
461+
cmd.push('--chown', build.chown);
462+
}
463+
459464
return options;
460465
}
461466

packages/frontend/src/Build.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,4 +728,7 @@ test('collapse and uncollapse of advanced options', async () => {
728728
// expect build config to be shown
729729
const buildConfig2 = screen.queryByRole('label', { name: 'Build config' });
730730
expect(buildConfig2).toBeDefined();
731+
// Expect chown to be shown
732+
const chown = screen.queryByRole('label', { name: 'Change file owner and group' });
733+
expect(chown).toBeDefined();
731734
});

packages/frontend/src/Build.svelte

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ let availableArchitectures: string[] = [];
3434
// Build options
3535
let buildFolder: string;
3636
let buildConfigFile: string;
37+
let buildChown: string;
3738
let buildType: BuildType[] = [];
3839
let buildArch: string | undefined;
3940
let buildFilesystem: string = ''; // Default filesystem auto-selected / empty
@@ -193,6 +194,7 @@ async function buildBootcImage() {
193194
type: buildType,
194195
arch: buildArch,
195196
filesystem: buildFilesystem,
197+
chown: buildChown,
196198
awsAmiName: awsAmiName,
197199
awsBucket: awsBucket,
198200
awsRegion: awsRegion,
@@ -690,6 +692,25 @@ export function goToHomePage(): void {
690692
</p>
691693
</div>
692694

695+
<!-- chown, this option is only available for Linux users -->
696+
{#if isLinux}
697+
<div class="mb-2">
698+
<label for="chown" class="block mb-2 font-semibold">Change file owner and group</label>
699+
<div class="flex flex-row space-x-3">
700+
<Input
701+
name="chown"
702+
id="chown"
703+
bind:value={buildChown}
704+
placeholder="GID and UID parameters (ex. 1000:1000)"
705+
class="w-full"
706+
aria-label="chown-select" />
707+
</div>
708+
<p class="text-sm text-[var(--pd-content-text)] pt-2">
709+
This option allows you to change the owner and group of the files in the output directory.
710+
</p>
711+
</div>
712+
{/if}
713+
693714
<!-- AWS -->
694715
<div>
695716
<span class="font-semibold block">Upload image to AWS</span>

packages/shared/src/models/bootc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface BootcBuildInfo {
2626
engineId: string;
2727
type: BuildType[];
2828
folder: string;
29+
chown?: string;
2930
buildConfigFilePath?: string;
3031
filesystem?: string;
3132
arch?: string;

0 commit comments

Comments
 (0)