@@ -13,22 +13,60 @@ import { paths } from '../../lib/paths';
1313import { Task } from '../../lib/tasks' ;
1414
1515export 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+
32+ let _containerTool = containerTool ;
33+
34+ // Check if useDocker is set to true and set the container tool to docker
35+ if ( useDocker ) {
36+ Task . log (
37+ `The ${ chalk . white ( '--use-docker' ) } flag is deprecated, use ${ chalk . white (
38+ '--container-tool' ,
39+ ) } instead`,
40+ ) ;
41+ Task . log (
42+ `Setting ${ chalk . white ( '--container-tool' ) } to docker as ${ chalk . white (
43+ '--use-docker' ) } was specified`,
44+ ) ;
45+ _containerTool = 'docker' ;
46+ }
47+
48+ // Validate containerTool value
49+ const allowedTools = [ 'docker' , 'podman' , 'buildah' ] ;
50+ if ( ! allowedTools . includes ( _containerTool ) ) {
51+ Task . error (
52+ `Invalid value for --container-tool: ${ _containerTool } . Allowed values are: ${ allowedTools . join ( ', ' ) } ` ,
53+ ) ;
54+ return ;
55+ }
56+
57+ // Determine the build command and version check command
58+ const buildCommand = _containerTool === 'buildah' ? 'bud' : 'build' ;
59+ const containerToolCmd = _containerTool ;
60+
2561 // check if the container tool is available, skip if just exporting the plugins to a directory
2662 if ( ! exportTo ) {
63+ let toolAvailable = false ;
2764 try {
28- await Task . forCommand ( `${ containerTool } --version` ) ;
65+ await Task . forCommand ( `${ containerToolCmd } --version` ) ;
66+ toolAvailable = true ;
2967 } catch ( e ) {
3068 Task . error (
31- `Unable to find ${ containerTool } command: ${ e } \nMake sure that ${ containerTool } is installed and available in your PATH.` ,
69+ `Unable to find ${ containerToolCmd } command: ${ e } \nMake sure that ${ containerToolCmd } is installed and available in your PATH.` ,
3270 ) ;
3371 return ;
3472 }
@@ -202,16 +240,14 @@ export async function command(opts: OptionValues): Promise<void> {
202240 flags . push ( `--platform ${ platform } ` ) ;
203241 }
204242 // run the command to generate the image
205- Task . log ( `Creating image using ${ containerTool } ` ) ;
206- await Task . forCommand (
207- `echo "from scratch
243+ Task . log ( `Creating image using ${ containerToolCmd } ` ) ;
244+ const containerInput = `from scratch
208245COPY . .
209- " | ${ containerTool } build \
210- ${ flags . join ( ' ' ) } \
211- -t '${ tag } ' -f - .
212- ` ,
213- { cwd : tmpDir } ,
214- ) ;
246+ ` ;
247+ const buildCmd =
248+ `echo "${ containerInput } " | ${ containerToolCmd } ${ buildCommand } ${ flags . join ( ' ' ) } -t '${ tag } ' -f - .` ;
249+
250+ await Task . forCommand ( buildCmd , { cwd : tmpDir } ) ;
215251 Task . log ( `Successfully built image ${ tag } with following plugins:` ) ;
216252 for ( const plugin of pluginRegistryMetadata ) {
217253 Task . log ( ` ${ chalk . white ( Object . keys ( plugin ) [ 0 ] ) } ` ) ;
0 commit comments