@@ -77,6 +77,10 @@ func (ref *Instance) BuildImage(options imagebuilder.DockerfileBuildOptions) err
7777 }
7878 }
7979
80+ if options .BuildContext == "" {
81+ options .BuildContext = "."
82+ }
83+
8084 var contextDir string
8185 if strings .HasPrefix (options .BuildContext , "http://" ) ||
8286 strings .HasPrefix (options .BuildContext , "https://" ) {
@@ -86,20 +90,16 @@ func (ref *Instance) BuildImage(options imagebuilder.DockerfileBuildOptions) err
8690 } else {
8791 if exists := fsutil .DirExists (options .BuildContext ); exists {
8892 contextDir = options .BuildContext
93+ //Dockerfile path is expected to be relative to build context
94+ fullDockerfileName := filepath .Join (contextDir , options .Dockerfile )
95+ if ! fsutil .Exists (fullDockerfileName ) || ! fsutil .IsRegularFile (fullDockerfileName ) {
96+ return fmt .Errorf ("invalid dockerfile reference (%s) - %s" , options .Dockerfile , fullDockerfileName )
97+ }
8998 } else {
9099 return imagebuilder .ErrInvalidContextDir
91100 }
92101 }
93102
94- fullDockerfileName := options .Dockerfile
95- if ! fsutil .Exists (fullDockerfileName ) || ! fsutil .IsRegularFile (fullDockerfileName ) {
96- //a slightly hacky behavior using the build context directory if the dockerfile flag doesn't include a usable path
97- fullDockerfileName = filepath .Join (contextDir , fullDockerfileName )
98- if ! fsutil .Exists (fullDockerfileName ) || ! fsutil .IsRegularFile (fullDockerfileName ) {
99- return fmt .Errorf ("invalid dockerfile reference - %s" , fullDockerfileName )
100- }
101- }
102-
103103 buildOptions := images.BuildOptions {
104104 BuildOptions : buildahDefine.BuildOptions {
105105 Output : options .ImagePath ,
@@ -110,15 +110,18 @@ func (ref *Instance) BuildImage(options imagebuilder.DockerfileBuildOptions) err
110110 RemoveIntermediateCtrs : true ,
111111 PullPolicy : buildahDefine .PullIfMissing ,
112112 OutputFormat : buildahDefine .Dockerv2ImageManifest , //buildah.OCIv1ImageManifest
113- CommonBuildOpts : & buildahDefine.CommonBuildOptions {
114- AddHost : strings .Split (options .ExtraHosts , "," ),
113+ CommonBuildOpts : & buildahDefine.CommonBuildOptions {
114+ // AddHost: strings.Split(options.ExtraHosts, ","),
115115 },
116-
117- //ConfigureNetwork: tbd <- options.NetworkMode
116+ ConfigureNetwork : buildahDefine .NetworkDefault , //tbd <- options.NetworkMode
118117 //CacheFrom: tbd <- options.CacheFrom
119118 //CacheTo: tbd <- options.CacheFrom
120119 },
121- ContainerFiles : []string {fullDockerfileName },
120+ ContainerFiles : []string {options .Dockerfile },
121+ }
122+
123+ if options .ExtraHosts != "" {
124+ buildOptions .CommonBuildOpts .AddHost = strings .Split (options .ExtraHosts , "," )
122125 }
123126
124127 if len (options .Platforms ) > 0 {
@@ -149,8 +152,11 @@ func (ref *Instance) BuildImage(options imagebuilder.DockerfileBuildOptions) err
149152 }
150153 }
151154
152- for _ , nv := range options .BuildArgs {
153- buildOptions .Args [nv .Name ] = nv .Value
155+ if len (options .BuildArgs ) > 0 {
156+ buildOptions .Args = map [string ]string {}
157+ for _ , nv := range options .BuildArgs {
158+ buildOptions .Args [nv .Name ] = nv .Value
159+ }
154160 }
155161
156162 if options .OutputStream != nil {
0 commit comments