forked from LaconicNetwork/kompose
Merge pull request #946 from hangyan/fix-build-path
Fix image build path error
This commit is contained in:
commit
47a8bfc0ea
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
@ -0,0 +1 @@
|
||||
FOO=BAR
|
||||
@ -0,0 +1,3 @@
|
||||
FROM busybox:1.26.2
|
||||
|
||||
RUN touch /test
|
||||
@ -0,0 +1,3 @@
|
||||
FROM busybox:1.26.2
|
||||
|
||||
RUN touch /test
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user