br4chu / docker-compose-maven-plugin

Maven plugin that talks to docker-compose command-line interface
Apache License 2.0
12 stars 4 forks source link

Compose fails with "No such file or directory" for imported compose files in multi module project #6

Closed michael-schnell closed 4 years ago

michael-schnell commented 4 years ago

The plugin fails in a multi module project if Docker Compose imports are used in the main compose file:

ERROR] Failed to execute goal io.brachu:docker-compose-maven-plugin:0.7.0:up (default) on project X: Docker-compose cluster failed to start: Non-zero (1) exit code returned from 'docker-compose -f - -p ijrdwemi ps -q'.
[ERROR] Output is:
[ERROR] .FileNotFoundError: [Errno 2] No such file or directory: '/home/<user>/git/<root-prj>/src/main/compose/mariadb.yml'

It seems that the current directory is not set to the module that is currently being executed.

Project structure

myproject/pom.xml  (Parent POM)
myproject/mymodule/pom.xml  (Module POM with "docker-compose-maven-plugin")
myproject/mymodule/docker-compose.yml
myproject/mymodule/src/main/compose/mariadb.yml

The "docker-compose.yml" has a relative import to another Docker Compose YAML file:

mariadb.jtenman.org:
  extends:
    file: src/main/compose/mariadb.yml
    service: mariadb.jtenman.org

When you execute the build in the directory "myproject/mymodule", the plugin works fine. Executing the build in the parent directory "myproject" fails with above error.

I guess this is because the current directory is "myproject". The <file>${project.basedir}/docker-compose.yml</file> configuration picks up the main "docker-compose.yml" file, but then Docker Compose cannot resolve the relative file "src/main/compose/mariadb.yml" because it is started in the parent directory.

The solution would be, to set the current directory for executing Docker Compose to the current directory of the Maven project that is currently build (which could be a module). Then it should work.

mjagus commented 4 years ago

Thank you for the report. Since version 0.8.0 of this plugin you can now provide "workDir" parameter to any of this plugin's goals. Value of this parameter will be used as the working directory for docker-compose process so this should cover your use-case. Default value is Maven's "${project.basedir}".

Feel free to reopen or create a new issue if you have further problems with this feature.

michael-schnell commented 4 years ago

Yes, it works.

I used version 0.7.0 and with 0.8.0 it is fixed.

Tnx.