Fix docker local build (#1212)

This commit is contained in:
Hang Yan 2019-12-27 10:26:42 +08:00 committed by GitHub
parent 1f0a097836
commit dd28e9220b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 19 deletions

View File

@ -1024,14 +1024,8 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
log.Infof("Build key detected. Attempting to build image '%s'", service.Image)
// Get the directory where the compose file is
composeFileDir, err := transformer.GetComposeFileDir(opt.InputFiles)
if err != nil {
return nil, err
}
// Build the image!
err = transformer.BuildDockerImage(service, name, composeFileDir)
err := transformer.BuildDockerImage(service, name)
if err != nil {
return nil, errors.Wrapf(err, "Unable to build Docker image for service %v", name)
}

View File

@ -313,14 +313,8 @@ func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
return nil, fmt.Errorf("image key required within build parameters in order to build and push service '%s'", name)
}
// Get the directory where the compose file is
composeFileDir, err := transformer.GetComposeFileDir(opt.InputFiles)
if err != nil {
return nil, err
}
// Build the container!
err = transformer.BuildDockerImage(service, name, composeFileDir)
err := transformer.BuildDockerImage(service, name)
if err != nil {
log.Fatalf("Unable to build Docker container for service %v: %v", name, err)
}

View File

@ -222,12 +222,21 @@ func GetComposeFileDir(inputFiles []string) (string, error) {
}
//BuildDockerImage builds docker image
func BuildDockerImage(service kobject.ServiceConfig, name string, relativePath string) error {
// Get the appropriate image source and name
imagePath := path.Join(relativePath, path.Base(service.Build))
if !path.IsAbs(service.Build) {
imagePath = path.Join(relativePath, service.Build)
func BuildDockerImage(service kobject.ServiceConfig, name string) error {
wd, err := os.Getwd()
if err != nil {
return err
}
log.Debug("Build image working dir is: ", wd)
// Get the appropriate image source and name
imagePath := path.Join(wd, path.Base(service.Build))
if !path.IsAbs(service.Build) {
imagePath = path.Join(wd, service.Build)
}
log.Debugf("Build image context is: %s", imagePath)
if _, err := os.Stat(imagePath); err != nil {
return errors.Wrapf(err, "%s is not a valid path for building image %s. Check if this dir exists.", service.Build, name)
}

View File

@ -70,6 +70,16 @@ function convert::run_cmd() {
}
readonly -f convert::run_cmd
function convert::expect_cmd_success() {
local cmd=$1
convert::start_test "convert::expect_cmd_success: Running: '${cmd}'"
convert::run_cmd $cmd
exit_status=$?
if [ $exit_status -ne 0 ]; then FAIL_MSGS=$FAIL_MSGS"exit status: $exit_status\n"; return $exit_status; fi
}
# run the command and match the output to the existing file
# if error then save error string in FAIL_MSGS
# if success save pass string in SUCCESS_MSGS

View File

@ -537,6 +537,14 @@ cd $CURRENT_DIR
#### Test docker build feature
cmd="kompose convert -f $KOMPOSE_ROOT/script/test/fixtures/buildconfig/docker-compose-dockerfile.yml --stdout -j --build=local"
convert::expect_cmd_success "$cmd"
cmd="kompose convert --provider openshift -f $KOMPOSE_ROOT/script/test/fixtures/buildconfig/docker-compose-dockerfile.yml --stdout -j --build=local"
convert::expect_cmd_success "$cmd"
# Test the presence of build args in buildconfig
# Replacing variables with current branch and uri
# Test BuildConfig