Fix image build path error

This commit is contained in:
Hang Yan 2018-02-24 15:40:00 +08:00
parent 170acd9e1a
commit e119b30ebd
7 changed files with 43 additions and 9 deletions

View File

@ -660,13 +660,13 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
return nil, err return nil, err
} }
// Build the container! // Build the image!
err = transformer.BuildDockerImage(service, name, composeFileDir) err = transformer.BuildDockerImage(service, name, composeFileDir)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "Unable to build Docker image for service %v", name) return nil, errors.Wrapf(err, "Unable to build Docker image for service %v", name)
} }
// Push the built container to the repo! // Push the built image to the repo!
err = transformer.PushDockerImage(service, name) err = transformer.PushDockerImage(service, name)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "Unable to push Docker image for service %v", name) return nil, errors.Wrapf(err, "Unable to push Docker image for service %v", name)

View File

@ -209,16 +209,15 @@ func GetComposeFileDir(inputFiles []string) (string, error) {
//BuildDockerImage builds docker image //BuildDockerImage builds docker image
func BuildDockerImage(service kobject.ServiceConfig, name string, relativePath string) error { func BuildDockerImage(service kobject.ServiceConfig, name string, relativePath string) error {
// Get the appropriate image source and name
// First, let's figure out the relative path of the Dockerfile! imagePath := path.Join(relativePath, path.Base(service.Build))
// else, we error out. if !path.IsAbs(service.Build) {
if _, err := os.Stat(service.Build); err != nil { imagePath = path.Join(relativePath, service.Build)
}
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) return errors.Wrapf(err, "%s is not a valid path for building image %s. Check if this dir exists.", service.Build, name)
} }
// Get the appropriate image source and name
// use path.Base to get the last element of the relative build path
imagePath := path.Join(relativePath, path.Base(service.Build))
imageName := name imageName := name
if service.Image != "" { if service.Image != "" {
imageName = service.Image imageName = service.Image

View File

@ -0,0 +1,24 @@
version: '3'
services:
backend-server:
image: "172.30.1.1:5000/myproject/test-image"
build:
context: ../server
dockerfile: Dockerfile
env_file:
- ../docker_env.list
ports:
- 5000:4000
front-end:
image: "172.30.1.1:5000/myproject/test-image"
build:
context: ../web
dockerfile: Dockerfile
env_file:
- ../docker_env.list
ports:
- 8080:8080
depends_on:
- backend-server

View File

@ -0,0 +1,3 @@
FROM busybox:1.26.2
RUN touch /test

View File

@ -0,0 +1,3 @@
FROM busybox:1.26.2
RUN touch /test

View File

@ -24,3 +24,7 @@ convert::print_msg "Running tests for build+push"
docker_compose_file="${KOMPOSE_ROOT}/script/test_in_openshift/compose-files/buildconfig/docker-compose-build-image.yml" docker_compose_file="${KOMPOSE_ROOT}/script/test_in_openshift/compose-files/buildconfig/docker-compose-build-image.yml"
convert::kompose_up $docker_compose_file convert::kompose_up $docker_compose_file
convert::kompose_down $docker_compose_file convert::kompose_down $docker_compose_file
docker_compose_file="${KOMPOSE_ROOT}/script/test_in_openshift/compose-files/buildconfig-relative-dirs/docker/docker-compose-build-image.yml"
convert::kompose_up $docker_compose_file
convert::kompose_down $docker_compose_file