Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit cd7aa9e

Browse files
authored
feat(cli): extend container tool to buildah (#2667)
feature(cli): extend container tool to buildah Signed-off-by: Marcel Hild <hild@b4mad.net>
1 parent 9ba1c90 commit cd7aa9e

File tree

3 files changed

+60
-17
lines changed

3 files changed

+60
-17
lines changed

.changeset/old-cooks-reply.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@janus-idp/cli": minor
3+
---
4+
5+
The janus-cli now can use buildah as a container tool.

packages/cli/src/commands/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,16 @@ export function registerScriptCommand(program: Command) {
177177
)
178178
.option(
179179
'--use-docker',
180-
'By defult, the command uses podman to build the container image. Use this flag to use docker instead.',
181-
false,
180+
'Use Docker as the container tool (deprecated, use --container-tool instead)',
181+
)
182+
.option(
183+
'--container-tool <tool>',
184+
'Container tool to use for building the image. Allowed values: "docker", "podman", "buildah". Default is "podman".',
185+
'podman',
182186
)
183187
.option(
184188
'--platform <platform>',
185-
'Platform to use when building the container image. Default is "linux/amd64". Can be set to "" to not set --platfrom flag in builder command.',
189+
'Platform to use when building the container image. Default is "linux/amd64". Can be set to "" to not set --platform flag in builder command.',
186190
'linux/amd64',
187191
)
188192
.action(

packages/cli/src/commands/package-dynamic-plugins/command.ts

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,59 @@ import { paths } from '../../lib/paths';
1313
import { Task } from '../../lib/tasks';
1414

1515
export async function command(opts: OptionValues): Promise<void> {
16-
const { exportTo, forceExport, preserveTempDir, tag, useDocker, platform } =
17-
opts;
16+
const {
17+
exportTo,
18+
forceExport,
19+
preserveTempDir,
20+
tag,
21+
useDocker,
22+
containerTool = 'podman',
23+
platform,
24+
} = opts;
1825
if (!exportTo && !tag) {
1926
Task.error(
2027
`Neither ${chalk.white('--export-to')} or ${chalk.white('--tag')} was specified, either specify ${chalk.white('--export-to')} to export plugins to a directory or ${chalk.white('--tag')} to export plugins to a container image`,
2128
);
2229
return;
2330
}
24-
const containerTool = useDocker ? 'docker' : 'podman';
31+
2532
// check if the container tool is available, skip if just exporting the plugins to a directory
33+
let containerToolCmd = containerTool;
34+
2635
if (!exportTo) {
36+
let _containerTool = containerTool;
37+
38+
// Check if useDocker is set to true and set the container tool to docker
39+
if (useDocker) {
40+
Task.log(
41+
`The ${chalk.white('--use-docker')} flag is deprecated, use ${chalk.white(
42+
'--container-tool',
43+
)} instead`,
44+
);
45+
Task.log(
46+
`Setting ${chalk.white('--container-tool')} to docker as ${chalk.white(
47+
'--use-docker',
48+
)} was specified`,
49+
);
50+
_containerTool = 'docker';
51+
}
52+
53+
// Validate containerTool value
54+
const allowedTools = ['docker', 'podman', 'buildah'];
55+
if (!allowedTools.includes(_containerTool)) {
56+
Task.error(
57+
`Invalid value for --container-tool: ${_containerTool}. Allowed values are: ${allowedTools.join(', ')}`,
58+
);
59+
return;
60+
}
61+
62+
// version check command
63+
containerToolCmd = _containerTool;
2764
try {
28-
await Task.forCommand(`${containerTool} --version`);
65+
await Task.forCommand(`${containerToolCmd} --version`);
2966
} catch (e) {
3067
Task.error(
31-
`Unable to find ${containerTool} command: ${e}\nMake sure that ${containerTool} is installed and available in your PATH.`,
68+
`Unable to find ${containerToolCmd} command: ${e}\nMake sure that ${containerToolCmd} is installed and available in your PATH.`,
3269
);
3370
return;
3471
}
@@ -202,16 +239,13 @@ export async function command(opts: OptionValues): Promise<void> {
202239
flags.push(`--platform ${platform}`);
203240
}
204241
// run the command to generate the image
205-
Task.log(`Creating image using ${containerTool}`);
206-
await Task.forCommand(
207-
`echo "from scratch
242+
Task.log(`Creating image using ${containerToolCmd}`);
243+
const containerInput = `from scratch
208244
COPY . .
209-
" | ${containerTool} build \
210-
${flags.join(' ')} \
211-
-t '${tag}' -f - .
212-
`,
213-
{ cwd: tmpDir },
214-
);
245+
`;
246+
const buildCmd = `echo "${containerInput}" | ${containerToolCmd} build ${flags.join(' ')} -t '${tag}' -f - .`;
247+
248+
await Task.forCommand(buildCmd, { cwd: tmpDir });
215249
Task.log(`Successfully built image ${tag} with following plugins:`);
216250
for (const plugin of pluginRegistryMetadata) {
217251
Task.log(` ${chalk.white(Object.keys(plugin)[0])}`);

0 commit comments

Comments
 (0)