forked from LaconicNetwork/kompose
Add support for build-args with --build local (#1256)
At the moment build-args can be specified in the compose configuration, but they're used only when creating a build-config and not for local builds.
This commit is contained in:
parent
d105a77e07
commit
ca75c31df8
@ -24,6 +24,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
dockerlib "github.com/fsouza/go-dockerclient"
|
||||
"github.com/kubernetes/kompose/pkg/kobject"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
@ -268,6 +269,17 @@ func BuildDockerImage(service kobject.ServiceConfig, name string) error {
|
||||
imageName = service.Image
|
||||
}
|
||||
|
||||
buildargs := []dockerlib.BuildArg{}
|
||||
for envName, envValue := range service.BuildArgs {
|
||||
var value string
|
||||
if envValue == nil {
|
||||
value = os.Getenv(envName)
|
||||
} else {
|
||||
value = *envValue
|
||||
}
|
||||
buildargs = append(buildargs, dockerlib.BuildArg{Name: envName, Value: value})
|
||||
}
|
||||
|
||||
// Connect to the Docker client
|
||||
client, err := docker.Client()
|
||||
if err != nil {
|
||||
@ -277,7 +289,7 @@ func BuildDockerImage(service kobject.ServiceConfig, name string) error {
|
||||
// Use the build struct function to build the image
|
||||
// Build the image!
|
||||
build := docker.Build{Client: *client}
|
||||
err = build.BuildImage(imagePath, imageName, service.Dockerfile)
|
||||
err = build.BuildImage(imagePath, imageName, service.Dockerfile, buildargs)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -38,7 +38,7 @@ BuildImage builds a Docker image via the Docker API. Takes the source directory
|
||||
and image name and then builds the appropriate image. Tarball is utilized
|
||||
in order to make building easier.
|
||||
*/
|
||||
func (c *Build) BuildImage(source string, image string, dockerfile string) error {
|
||||
func (c *Build) BuildImage(source string, image string, dockerfile string, buildargs []dockerlib.BuildArg) error {
|
||||
|
||||
log.Infof("Building image '%s' from directory '%s'", image, path.Base(source))
|
||||
|
||||
@ -68,6 +68,7 @@ func (c *Build) BuildImage(source string, image string, dockerfile string) error
|
||||
InputStream: tarballSource,
|
||||
OutputStream: outputBuffer,
|
||||
Dockerfile: dockerfile,
|
||||
BuildArgs: buildargs,
|
||||
}
|
||||
|
||||
// Build it!
|
||||
|
||||
Loading…
Reference in New Issue
Block a user