Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix image build path error #946

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/transformer/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,13 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
return nil, err
}

// Build the container!
// Build the image!
err = transformer.BuildDockerImage(service, name, composeFileDir)
if err != nil {
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)
if err != nil {
return nil, errors.Wrapf(err, "Unable to push Docker image for service %v", name)
Expand Down
13 changes: 6 additions & 7 deletions pkg/transformer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,15 @@ func GetComposeFileDir(inputFiles []string) (string, error) {

//BuildDockerImage builds docker image
func BuildDockerImage(service kobject.ServiceConfig, name string, relativePath string) error {

// First, let's figure out the relative path of the Dockerfile!
// else, we error out.
if _, err := os.Stat(service.Build); err != nil {
// 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)
}
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)
}

// 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
if service.Image != "" {
imageName = service.Image
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FOO=BAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM busybox:1.26.2

RUN touch /test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM busybox:1.26.2

RUN touch /test
4 changes: 4 additions & 0 deletions script/test_in_openshift/tests/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
convert::kompose_up $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