@@ -38,6 +38,11 @@ type Image struct {
3838	Labels   map [string ]string 
3939}
4040
41+ type  BuildOptions  struct  {
42+ 	Context  string 
43+ 	Tag      string 
44+ }
45+ 
4146type  ImageSlice  []Image 
4247
4348var  (
@@ -437,22 +442,25 @@ func SystemMigrate(ociRuntimeRequired string) error {
437442	return  nil 
438443}
439444
440- func  BuildImage (buildContext   string ) (string , error ) {
441- 	if  ! utils .PathExists (buildContext ) {
442- 		return  "" , & utils.BuildError {BuildContext : buildContext , Err : ErrBuildContextDoesNotExist }
445+ func  BuildImage (build   BuildOptions ) (string , error ) {
446+ 	if  ! utils .PathExists (build . Context ) {
447+ 		return  "" , & utils.BuildError {BuildContext : build . Context , Err : ErrBuildContextDoesNotExist }
443448	}
444- 	if  stat , err  :=  os .Stat (buildContext ); err  !=  nil  {
449+ 	if  stat , err  :=  os .Stat (build . Context ); err  !=  nil  {
445450		return  "" , err 
446451	} else  {
447452		if  ! stat .Mode ().IsDir () {
448- 			return  "" , & utils.BuildError {BuildContext : buildContext , Err : ErrBuildContextInvalid }
453+ 			return  "" , & utils.BuildError {BuildContext : build . Context , Err : ErrBuildContextInvalid }
449454		}
450455	}
451- 	if  ! utils .PathExists (buildContext + "/Containerfile" ) &&  ! utils .PathExists (buildContext + "/Dockerfile" ) {
452- 		return  "" , & utils.BuildError {BuildContext : buildContext , Err : ErrBuildContextInvalid }
456+ 	if  ! utils .PathExists (build . Context + "/Containerfile" ) &&  ! utils .PathExists (build . Context + "/Dockerfile" ) {
457+ 		return  "" , & utils.BuildError {BuildContext : build . Context , Err : ErrBuildContextInvalid }
453458	}
454459	logLevelString  :=  LogLevel .String ()
455- 	args  :=  []string {"--log-level" , logLevelString , "build" , buildContext }
460+ 	args  :=  []string {"--log-level" , logLevelString , "build" , build .Context }
461+ 	if  build .Tag  !=  ""  {
462+ 		args  =  append (args , "--tag" , build .Tag )
463+ 	}
456464
457465	stdout  :=  new (bytes.Buffer )
458466	if  err  :=  shell .Run ("podman" , nil , stdout , nil , args ... ); err  !=  nil  {
@@ -462,14 +470,19 @@ func BuildImage(buildContext string) (string, error) {
462470	imageIdBegin  :=  strings .LastIndex (output , "\n " ) +  1 
463471	imageId  :=  output [imageIdBegin :]
464472
465- 	info , err  :=  Inspect ("image" , imageId )
466- 	if  err  !=  nil  {
467- 		return  "" , err 
468- 	}
469- 	name  :=  "localhost/"  +  info ["Labels" ].(map [string ]interface {})["name" ].(string )
470- 	args  =  []string {"--log-level" , logLevelString , "tag" , imageId , name }
471- 	if  err  :=  shell .Run ("podman" , nil , nil , nil , args ... ); err  !=  nil  {
472- 		return  "" , err 
473+ 	var  name  string 
474+ 	if  build .Tag  ==  ""  {
475+ 		info , err  :=  Inspect ("image" , imageId )
476+ 		if  err  !=  nil  {
477+ 			return  "" , err 
478+ 		}
479+ 		name  =  info ["Labels" ].(map [string ]interface {})["name" ].(string )
480+ 		args  =  []string {"--log-level" , logLevelString , "tag" , imageId , name }
481+ 		if  err  :=  shell .Run ("podman" , nil , nil , nil , args ... ); err  !=  nil  {
482+ 			return  "" , err 
483+ 		}
484+ 	} else  {
485+ 		name  =  build .Tag 
473486	}
474487
475488	return  name , nil 
0 commit comments