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

Commit 8d5e11d

Browse files
committed
feature(cli): extend container tool to buildah
Signed-off-by: Marcel Hild <hild@b4mad.net>
1 parent 9ba1c90 commit 8d5e11d

File tree

2 files changed

+63
-20
lines changed

2 files changed

+63
-20
lines changed

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 "buildah".',
185+
'buildah',
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: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,63 @@ 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+
containerTool = 'docker',
22+
platform,
23+
} = opts;
1824
if (!exportTo && !tag) {
1925
Task.error(
2026
`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`,
2127
);
2228
return;
2329
}
24-
const containerTool = useDocker ? 'docker' : 'podman';
30+
31+
// Validate containerTool value
32+
const allowedTools = ['docker', 'podman', 'buildah'];
33+
if (!allowedTools.includes(containerTool)) {
34+
Task.error(
35+
`Invalid value for --container-tool: ${containerTool}. Allowed values are: ${allowedTools.join(', ')}`,
36+
);
37+
return;
38+
}
39+
40+
// Determine the build command and version check command
41+
let buildCommand = containerTool === 'buildah' ? 'bud' : 'build';
42+
let containerToolCmd = containerTool;
43+
2544
// check if the container tool is available, skip if just exporting the plugins to a directory
2645
if (!exportTo) {
46+
let toolAvailable = false;
2747
try {
28-
await Task.forCommand(`${containerTool} --version`);
48+
await Task.forCommand(`${containerToolCmd} --version`);
49+
toolAvailable = true;
2950
} catch (e) {
30-
Task.error(
31-
`Unable to find ${containerTool} command: ${e}\nMake sure that ${containerTool} is installed and available in your PATH.`,
32-
);
33-
return;
51+
// Fallback: try docker if not already docker
52+
if (containerToolCmd !== 'docker') {
53+
try {
54+
await Task.forCommand(`docker --version`);
55+
Task.log(
56+
`Warning: Unable to find ${containerToolCmd} command. Falling back to docker.`,
57+
);
58+
containerToolCmd = 'docker';
59+
buildCommand = 'build';
60+
toolAvailable = true;
61+
} catch (dockerErr) {
62+
Task.error(
63+
`Unable to find ${containerToolCmd} command: ${e}\nTried falling back to docker, but docker is also not available: ${dockerErr}\nMake sure that a supported container tool is installed and available in your PATH.`,
64+
);
65+
return;
66+
}
67+
} else {
68+
Task.error(
69+
`Unable to find docker command: ${e}\nMake sure that docker is installed and available in your PATH.`,
70+
);
71+
return;
72+
}
3473
}
3574
}
3675
const workspacePackage = (await fs.readJson(
@@ -202,16 +241,16 @@ export async function command(opts: OptionValues): Promise<void> {
202241
flags.push(`--platform ${platform}`);
203242
}
204243
// run the command to generate the image
205-
Task.log(`Creating image using ${containerTool}`);
206-
await Task.forCommand(
207-
`echo "from scratch
244+
Task.log(`Creating image using ${containerToolCmd}`);
245+
const buildahInput = `from scratch
208246
COPY . .
209-
" | ${containerTool} build \
210-
${flags.join(' ')} \
211-
-t '${tag}' -f - .
212-
`,
213-
{ cwd: tmpDir },
214-
);
247+
`;
248+
const buildCmd =
249+
containerToolCmd === 'buildah'
250+
? `echo "${buildahInput}" | buildah bud ${flags.join(' ')} -t '${tag}' -f - .`
251+
: `echo "${buildahInput}" | ${containerToolCmd} build ${flags.join(' ')} -t '${tag}' -f - .`;
252+
253+
await Task.forCommand(buildCmd, { cwd: tmpDir });
215254
Task.log(`Successfully built image ${tag} with following plugins:`);
216255
for (const plugin of pluginRegistryMetadata) {
217256
Task.log(` ${chalk.white(Object.keys(plugin)[0])}`);

0 commit comments

Comments
 (0)