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

docker-compose 2.1 depends_on conditions not supported #888

Closed
jordanglassman opened this issue Nov 2, 2017 · 11 comments · Fixed by #1718
Closed

docker-compose 2.1 depends_on conditions not supported #888

jordanglassman opened this issue Nov 2, 2017 · 11 comments · Fixed by #1718
Assignees

Comments

@jordanglassman
Copy link

Description

docker-compose.yml

version: '2.1'
services:
  redis1:
    image: redis
    depends_on:
      redis2:
        condition: service_started

  redis2:
    image: redis

Output:

/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java -Dmaven.multiModuleProjectDirectory=/Users/jglassman/iiworkspace/sandbox "-Dmaven.home=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=58768:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2017.2.5 io.fabric8:docker-maven-plugin:0.22.1:build
objc[32441]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java (0x105d3a4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x107dc04e0). One of the two will be used. Which one is undefined.
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.me.sandbox:sandbox:jar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 12, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building sandbox 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- docker-maven-plugin:0.22.1:build (default-cli) @ sandbox ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.292 s
[INFO] Finished at: 2017-11-02T14:31:01-04:00
[INFO] Final Memory: 14M/308M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.22.1:build (default-cli) on project sandbox: A type incompatibility occurred while executing io.fabric8:docker-maven-plugin:0.22.1:build: Cannot cast java.util.LinkedHashMap to java.util.List
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>io.fabric8:docker-maven-plugin:0.22.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/Users/jglassman/.m2/repository/io/fabric8/docker-maven-plugin/0.22.1/docker-maven-plugin-0.22.1.jar
[ERROR] urls[1] = file:/Users/jglassman/.m2/repository/org/apache/httpcomponents/httpclient/4.5.3/httpclient-4.5.3.jar
[ERROR] urls[2] = file:/Users/jglassman/.m2/repository/org/apache/httpcomponents/httpcore/4.4.6/httpcore-4.4.6.jar
[ERROR] urls[3] = file:/Users/jglassman/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar
[ERROR] urls[4] = file:/Users/jglassman/.m2/repository/commons-codec/commons-codec/1.9/commons-codec-1.9.jar
[ERROR] urls[5] = file:/Users/jglassman/.m2/repository/com/github/jnr/jnr-unixsocket/0.12/jnr-unixsocket-0.12.jar
[ERROR] urls[6] = file:/Users/jglassman/.m2/repository/com/github/jnr/jnr-ffi/2.0.9/jnr-ffi-2.0.9.jar
[ERROR] urls[7] = file:/Users/jglassman/.m2/repository/com/github/jnr/jffi/1.2.11/jffi-1.2.11.jar
[ERROR] urls[8] = file:/Users/jglassman/.m2/repository/com/github/jnr/jffi/1.2.11/jffi-1.2.11-native.jar
[ERROR] urls[9] = file:/Users/jglassman/.m2/repository/org/ow2/asm/asm/5.0.3/asm-5.0.3.jar
[ERROR] urls[10] = file:/Users/jglassman/.m2/repository/org/ow2/asm/asm-commons/5.0.3/asm-commons-5.0.3.jar
[ERROR] urls[11] = file:/Users/jglassman/.m2/repository/org/ow2/asm/asm-analysis/5.0.3/asm-analysis-5.0.3.jar
[ERROR] urls[12] = file:/Users/jglassman/.m2/repository/org/ow2/asm/asm-tree/5.0.3/asm-tree-5.0.3.jar
[ERROR] urls[13] = file:/Users/jglassman/.m2/repository/org/ow2/asm/asm-util/5.0.3/asm-util-5.0.3.jar
[ERROR] urls[14] = file:/Users/jglassman/.m2/repository/com/github/jnr/jnr-x86asm/1.0.2/jnr-x86asm-1.0.2.jar
[ERROR] urls[15] = file:/Users/jglassman/.m2/repository/com/github/jnr/jnr-constants/0.9.1/jnr-constants-0.9.1.jar
[ERROR] urls[16] = file:/Users/jglassman/.m2/repository/com/github/jnr/jnr-enxio/0.12/jnr-enxio-0.12.jar
[ERROR] urls[17] = file:/Users/jglassman/.m2/repository/com/github/jnr/jnr-posix/3.0.29/jnr-posix-3.0.29.jar
[ERROR] urls[18] = file:/Users/jglassman/.m2/repository/org/apache/commons/commons-lang3/3.6/commons-lang3-3.6.jar
[ERROR] urls[19] = file:/Users/jglassman/.m2/repository/org/apache/commons/commons-text/1.1/commons-text-1.1.jar
[ERROR] urls[20] = file:/Users/jglassman/.m2/repository/org/json/json/20140107/json-20140107.jar
[ERROR] urls[21] = file:/Users/jglassman/.m2/repository/org/fusesource/jansi/jansi/1.16/jansi-1.16.jar
[ERROR] urls[22] = file:/Users/jglassman/.m2/repository/org/bouncycastle/bcpkix-jdk15on/1.57/bcpkix-jdk15on-1.57.jar
[ERROR] urls[23] = file:/Users/jglassman/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.57/bcprov-jdk15on-1.57.jar
[ERROR] urls[24] = file:/Users/jglassman/.m2/repository/org/apache/maven/plugins/maven-assembly-plugin/2.6/maven-assembly-plugin-2.6.jar
[ERROR] urls[25] = file:/Users/jglassman/.m2/repository/org/slf4j/slf4j-jdk14/1.5.6/slf4j-jdk14-1.5.6.jar
[ERROR] urls[26] = file:/Users/jglassman/.m2/repository/org/slf4j/jcl-over-slf4j/1.5.6/jcl-over-slf4j-1.5.6.jar
[ERROR] urls[27] = file:/Users/jglassman/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.2.1/maven-reporting-api-2.2.1.jar
[ERROR] urls[28] = file:/Users/jglassman/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.1/doxia-sink-api-1.1.jar
[ERROR] urls[29] = file:/Users/jglassman/.m2/repository/org/apache/maven/doxia/doxia-logging-api/1.1/doxia-logging-api-1.1.jar
[ERROR] urls[30] = file:/Users/jglassman/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
[ERROR] urls[31] = file:/Users/jglassman/.m2/repository/commons-cli/commons-cli/1.2/commons-cli-1.2.jar
[ERROR] urls[32] = file:/Users/jglassman/.m2/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar
[ERROR] urls[33] = file:/Users/jglassman/.m2/repository/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar
[ERROR] urls[34] = file:/Users/jglassman/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
[ERROR] urls[35] = file:/Users/jglassman/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[36] = file:/Users/jglassman/.m2/repository/org/apache/maven/shared/maven-common-artifact-filters/1.4/maven-common-artifact-filters-1.4.jar
[ERROR] urls[37] = file:/Users/jglassman/.m2/repository/org/codehaus/plexus/plexus-archiver/3.0.1/plexus-archiver-3.0.1.jar
[ERROR] urls[38] = file:/Users/jglassman/.m2/repository/org/iq80/snappy/snappy/0.3/snappy-0.3.jar
[ERROR] urls[39] = file:/Users/jglassman/.m2/repository/org/apache/maven/shared/file-management/1.1/file-management-1.1.jar
[ERROR] urls[40] = file:/Users/jglassman/.m2/repository/org/apache/maven/shared/maven-shared-io/1.1/maven-shared-io-1.1.jar
[ERROR] urls[41] = file:/Users/jglassman/.m2/repository/commons-io/commons-io/2.2/commons-io-2.2.jar
[ERROR] urls[42] = file:/Users/jglassman/.m2/repository/org/apache/maven/shared/maven-filtering/1.3/maven-filtering-1.3.jar
[ERROR] urls[43] = file:/Users/jglassman/.m2/repository/org/apache/maven/shared/maven-shared-utils/0.6/maven-shared-utils-0.6.jar
[ERROR] urls[44] = file:/Users/jglassman/.m2/repository/org/sonatype/plexus/plexus-build-api/0.0.4/plexus-build-api-0.0.4.jar
[ERROR] urls[45] = file:/Users/jglassman/.m2/repository/org/codehaus/plexus/plexus-io/2.6/plexus-io-2.6.jar
[ERROR] urls[46] = file:/Users/jglassman/.m2/repository/org/apache/maven/maven-archiver/2.5/maven-archiver-2.5.jar
[ERROR] urls[47] = file:/Users/jglassman/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.21/plexus-utils-3.0.21.jar
[ERROR] urls[48] = file:/Users/jglassman/.m2/repository/org/apache/maven/shared/maven-repository-builder/1.0/maven-repository-builder-1.0.jar
[ERROR] urls[49] = file:/Users/jglassman/.m2/repository/joda-time/joda-time/2.9.9/joda-time-2.9.9.jar
[ERROR] urls[50] = file:/Users/jglassman/.m2/repository/org/yaml/snakeyaml/1.18/snakeyaml-1.18.jar
[ERROR] urls[51] = file:/Users/jglassman/.m2/repository/com/google/guava/guava/23.0-android/guava-23.0-android.jar
[ERROR] urls[52] = file:/Users/jglassman/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar
[ERROR] urls[53] = file:/Users/jglassman/.m2/repository/com/google/errorprone/error_prone_annotations/2.0.18/error_prone_annotations-2.0.18.jar
[ERROR] urls[54] = file:/Users/jglassman/.m2/repository/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1.jar
[ERROR] urls[55] = file:/Users/jglassman/.m2/repository/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.jar
[ERROR] urls[56] = file:/Users/jglassman/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.24/plexus-interpolation-1.24.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

Process finished with exit code 1

Info

  • d-m-p version :
  • Maven version (mvn -v) :
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T15:39:06-04:00)
Maven home: /usr/local/Cellar/maven/3.5.0/libexec
Java version: 1.8.0_144, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"
  • Docker version :
ip-192-168-1-7:sse-service jglassman$ docker --version && docker-compose --version
Docker version 17.09.0-ce, build afdb6d4
docker-compose version 1.16.1, build 6d1ac21
@matt-shaw
Copy link

I've just hit the same problem. Is there any news on this issue?

@rhuss
Copy link
Collaborator

rhuss commented Jan 10, 2018

No, there is no news on this (mostly because of lack of time, there is also no support for version 3 yet). Happy to take PRs though ....

@jimusbobus
Copy link

jimusbobus commented Feb 19, 2018

I've created a test for this - https://github.com/jimusbobus/docker-maven-plugin/commit/b2fee7935e18edfa2e52821e4fe6b90335105b29

I'd be more than happy to try and fix this, but i'm lost as where to start :)

Swapping from lists to maps was not as simple as i had hoped....

@cdbennett
Copy link

For reference, here a full stack dump from v0.33 of the plugin.

Caused by: java.lang.ClassCastException: Cannot cast java.util.LinkedHashMap to java.util.List
    at java.lang.Class.cast (Class.java:3369)
    at io.fabric8.maven.docker.config.handler.compose.DockerComposeServiceWrapper.asList (DockerComposeServiceWrapper.java:400)
    at io.fabric8.maven.docker.config.handler.compose.DockerComposeServiceWrapper.getDependsOn (DockerComposeServiceWrapper.java:113)
    at io.fabric8.maven.docker.config.handler.compose.DockerComposeConfigHandler.createRunConfiguration (DockerComposeConfigHandler.java:175)
    at io.fabric8.maven.docker.config.handler.compose.DockerComposeConfigHandler.buildImageConfiguration (DockerComposeConfigHandler.java:96)
    at io.fabric8.maven.docker.config.handler.compose.DockerComposeConfigHandler.resolve (DockerComposeConfigHandler.java:56)
    at io.fabric8.maven.docker.config.handler.ImageConfigResolver.resolve (ImageConfigResolver.java:98)
    at io.fabric8.maven.docker.AbstractDockerMojo$1.resolve (AbstractDockerMojo.java:339)
    at io.fabric8.maven.docker.config.ConfigHelper.resolveConfiguration (ConfigHelper.java:159)
    at io.fabric8.maven.docker.config.ConfigHelper.resolveImages (ConfigHelper.java:57)
    at io.fabric8.maven.docker.AbstractDockerMojo.initImageConfiguration (AbstractDockerMojo.java:333)
    at io.fabric8.maven.docker.AbstractDockerMojo.execute (AbstractDockerMojo.java:232)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)

@cdbennett
Copy link

The docker-maven-plugin needs to look at the node type and if it's a map, then use asMap() and extract the keys. On the other hand, if it's a List, then use asList() as it already does.

It's unclear what the depends_on condition used by the docker-maven-plugin actually is, when not defined by the new condition docker-compose element. Does it was for healthy status?

@robson90
Copy link

@jimusbobus the link you provided returns a 404. Do you have it still on hand ?

@jimusbobus
Copy link

Sorry no I do not, I moved on from that job and cleaned up all my old repositories and had forgotten about this issue and have deleted the repo :/

@pdurbin
Copy link

pdurbin commented Nov 3, 2023

Hi! First of all, we love the Docker Maven Plugin! Thanks! ❤️

We're having the same problem trying to get our app to wait for postgres to start on Windows.

[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.43.4:run (default-cli) on project dataverse: A type incompatibility occurred while executing io.fabric8:docker-maven-plugin:0.43.4:run: Cannot cast java.util.LinkedHashMap to java.util.List

We're trying to add something like this:

depends_on:
      dev_postgres:
        condition: service_healthy
      dev_solr:
        condition: service_started
      dev_dv_initializer:
        condition: service_completed_successfully

poikilotherm added a commit to poikilotherm/docker-maven-plugin that referenced this issue Nov 3, 2023
fabric8io#888

As of Docker Compose v2.1, there is a new map-based long syntax to express dependencies
of containers among each other that is much more sophisticated than the old list based.

This commit solves the immediate problem described in fabric8io#888, where this new syntax
is simply rejected. The dependsOn concept of DMP is now feed with the map's keys.
Limitation: the wait conditions expressed with the new syntax are not added with this commit.

See also: fabric8io#888
See also: https://github.com/compose-spec/compose-spec/blob/master/spec.md#long-syntax-1
See also: https://docs.docker.com/compose/compose-file/compose-file-v2/#depends_on
@rhuss
Copy link
Collaborator

rhuss commented Nov 5, 2023

Thanks for raising this. Unfortunately, I'm not able to work on this plugin currently, and I have the feeling that the docker compose support is quite aged over the time.

I guess @rohanKanojia also don't has much bandwidth to rigorously work on this part of the plugin, too, but we are happy to integrate any PRs that improve the docker compose support.

@poikilotherm
Copy link
Contributor

poikilotherm commented Nov 5, 2023

I am already working on a feature branch to make this happen. PR forthcoming.

poikilotherm added a commit to poikilotherm/docker-maven-plugin that referenced this issue Nov 6, 2023
…bric8io#888

Extract the Docker Compose v2.1+ depends_on conditions and apply them
as Docker Maven Plugin waiting configurations.

Limitations: this mapping requires an inversion of the data model in use.
Docker Compose has waiting conditions located at the depending service,
while this plugin puts them on the dependent service/s.
poikilotherm added a commit to poikilotherm/docker-maven-plugin that referenced this issue Nov 6, 2023
@poikilotherm
Copy link
Contributor

poikilotherm commented Nov 6, 2023

@rohanKanojia @rhuss I implemented transfering the compose conditions to wait configuration now.

But I hit another wall: a compose file allows to specify a healthcheck for a container which is not added at build- but at runtime. The plugin currently is not capable to pick that up, as it looks like ContainerCreateConfig does not yet support adding a health check (which is possible as of Docker API 1.24). So someone using condition: service_healthy without a predefined HEALTHCHECK in an image (e.g. using plain Postgres) is kind of dead in the woods...

How shall I proceed? It takes quite a few changes to ship this kind of information. I'm also worried about compatibility: the current implementation supports adding healthchecks only via build configuration and not via compose file (at all).

Should we create a fresh issue for this? Should this be two distinct PRs or one closing both?

poikilotherm added a commit to poikilotherm/docker-maven-plugin that referenced this issue Nov 6, 2023
poikilotherm added a commit to poikilotherm/docker-maven-plugin that referenced this issue Nov 6, 2023
rohanKanojia pushed a commit that referenced this issue Nov 11, 2023
#888

As of Docker Compose v2.1, there is a new map-based long syntax to express dependencies
of containers among each other that is much more sophisticated than the old list based.

This commit solves the immediate problem described in #888, where this new syntax
is simply rejected. The dependsOn concept of DMP is now feed with the map's keys.
Limitation: the wait conditions expressed with the new syntax are not added with this commit.

See also: #888
See also: https://github.com/compose-spec/compose-spec/blob/master/spec.md#long-syntax-1
See also: https://docs.docker.com/compose/compose-file/compose-file-v2/#depends_on
rohanKanojia pushed a commit that referenced this issue Nov 11, 2023
Extract the Docker Compose v2.1+ depends_on conditions and apply them
as Docker Maven Plugin waiting configurations.

Limitations: this mapping requires an inversion of the data model in use.
Docker Compose has waiting conditions located at the depending service,
while this plugin puts them on the dependent service/s.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants