redhat-developer / henge

This project has merged into Kompose.
https://github.com/skippbox/kompose
MIT License
14 stars 7 forks source link

Build path in docker-compose #20

Closed kadel closed 6 years ago

kadel commented 8 years ago

Currently build in docker compose file is expected to be relative path. We also need support absolute path, urls, and context with dockerfile options. see: https://docs.docker.com/compose/compose-file/

surajssd commented 8 years ago

@kadel it will be a good addition to libcompose itself

kadel commented 8 years ago

libcompose supports that

surajssd commented 8 years ago

So should we work on this or wait till we swap openshift's libcompose with upstream libcompose?

kadel commented 8 years ago

swapping to upstream libcompose won't help

kadel commented 8 years ago

from my investigation it seems that this is actually intentional and it is how openshift import has been written. look at this: https://github.com/redhat-developer/henge/blob/master/pkg/transformers/openshift/generate.go#L145,L178

surajssd commented 8 years ago

@kadel one finding openshift's libcompose code itself will expand the Build variable, so after p.Parse() if you look for p.Configs[svc_name].Build it will be changed from relative path to absolute path.

I checked with upstream libcompose, it worked with both absolute path and relative path.

surajssd commented 8 years ago

Using absolute path for build in docker-compose file

``` $ cat docker-compose.yml version: "2" services: mariadb: image: centos/mariadb ports: - "3306" environment: MYSQL_ROOT_PASSWORD: etherpad MYSQL_DATABASE: etherpad MYSQL_PASSWORD: etherpad MYSQL_USER: etherpad etherpad: build: "/home/vagrant/compose-lib/etherpad/myphp" ports: - "80:9001" depends_on: - mariadb environment: DB_HOST: mariadb DB_DBID: etherpad DB_PASS: etherpad DB_USER: etherpad $ ~/work/src/github.com/docker/libcompose/libcompose up WARN[0000] Note: This is an experimental alternate implementation of the Compose CLI (https://github.com/docker/compose) INFO[0000] [0/2] [mariadb]: Starting INFO[0000] Recreating mariadb INFO[0001] [1/2] [mariadb]: Started INFO[0001] [1/2] [etherpad]: Starting WARN[0001] Error while reading .dockerignore (/home/vagrant/compose-lib/etherpad/myphp/.dockerignore) : open /home/vagrant/compose-lib/etherpad/myphp/.dockerignore: no such file or directory INFO[0001] Building etherpad_etherpad... Sending build context to Docker daemon 79.36 kB Step 1 : FROM somefoo Pulling repository docker.io/library/somefoo Error: image library/somefoo not foundERRO[0006] Failed Starting etherpad : Status: Error: image library/somefoo not found, Code: 1 ERRO[0006] Failed to start: etherpad : Status: Error: image library/somefoo not found, Code: 1 Status: Error: image library/somefoo not found, Code: 1 ```

Using relative path in docker compose file

``` $ cat docker-compose.yml version: "2" services: mariadb: image: centos/mariadb ports: - "3306" environment: MYSQL_ROOT_PASSWORD: etherpad MYSQL_DATABASE: etherpad MYSQL_PASSWORD: etherpad MYSQL_USER: etherpad etherpad: build: "./myphp" ports: - "80:9001" depends_on: - mariadb environment: DB_HOST: mariadb DB_DBID: etherpad DB_PASS: etherpad DB_USER: etherpad $ ~/work/src/github.com/docker/libcompose/libcompose up WARN[0000] Note: This is an experimental alternate implementation of the Compose CLI (https://github.com/docker/compose) INFO[0000] [0/2] [mariadb]: Starting INFO[0000] Recreating mariadb INFO[0001] [1/2] [mariadb]: Started INFO[0001] [1/2] [etherpad]: Starting WARN[0001] Error while reading .dockerignore (myphp/.dockerignore) : open myphp/.dockerignore: no such file or directory INFO[0001] Building etherpad_etherpad... Sending build context to Docker daemon 79.36 kB Step 1 : FROM somefoo Pulling repository docker.io/library/somefoo Error: image library/somefoo not foundERRO[0005] Failed Starting etherpad : Status: Error: image library/somefoo not found, Code: 1 ERRO[0005] Failed to start: etherpad : Status: Error: image library/somefoo not found, Code: 1 Status: Error: image library/somefoo not found, Code: 1 ```
surajssd commented 8 years ago

Reported issue in origin https://github.com/openshift/origin/issues/9815

surajssd commented 8 years ago

Doing deeper research on libcompose's way of handling the parsed config is quite different, so libcompose stores path to build directory as is given by user. And build information is stored in object of type Build.

(dlv) b /home/vagrant/work/src/github.com/docker/libcompose/project/project.go:178
(dlv) c
(dlv) p serviceConfigs["etherpad"]
*github.com/docker/libcompose/config.ServiceConfig {
    Build: github.com/docker/libcompose/yaml.Build {
        Context: "./myphp",
        Dockerfile: "",
        Args: map[string]string [],},
    CapAdd: []string len: 0, cap: 0, [],
    CapDrop: []string len: 0, cap: 0, [],
    CPUSet: "",
[SNIP]

While openshift's libcompose will only store absolute path to build path.

(dlv) b /home/vagrant/work/src/github.com/redhat-developer/henge/pkg/transformers/openshift/generate.go:63
(dlv) c
(dlv) p p.Configs["etherpad"]
*github.com/redhat-developer/henge/vendor/github.com/openshift/origin/third_party/github.com/docker/libcompose/project.ServiceConfig {
    Build: "/home/vagrant/compose-lib/etherpad/myphp",
    CapAdd: []string len: 0, cap: 0, [],
[SNIP]