derlin / docker-compose-viz-mermaid

Generate beautiful visuals from docker-compose files. The mermaid graph can be exported to PNG, SVG, or edited directly in https://mermaid.live.

Home Page:https://derlin.github.io/docker-compose-viz-mermaid

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fail parsing published port

mgaitan opened this issue · comments

Consider this compose file with a ports definition in extended format

services:
  app:
    image: hello-world
    ports:
      - mode: ingress
        target: 4444
        published: "4444"

It's a valid file as you can see

$ docker compose run app | head -n 2

Hello from Docker!

However, the app fails parsing the published port as a stirng value.

$ java -jar docker-compose-viz-mermaid_no_local-1.1.1-SNAPSHOT.jar 
Exception in thread "main" java.lang.IllegalArgumentException: Wrong type for 4444
	at ch.derlin.dcvizmermaid.helpers.YamlUtils.getByPath(YamlUtils.kt:31)
	at ch.derlin.dcvizmermaid.data.PortBinding$Companion.parseYaml(PortBinding.kt:31)
	at ch.derlin.dcvizmermaid.data.PortBinding$Companion.parse(PortBinding.kt:16)
	at ch.derlin.dcvizmermaid.data.Service.ports(Service.kt:31)
	at ch.derlin.dcvizmermaid.data.DockerCompose$ports$2.invoke(DockerCompose.kt:25)
	at ch.derlin.dcvizmermaid.data.DockerCompose$ports$2.invoke(DockerCompose.kt:25)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at ch.derlin.dcvizmermaid.data.DockerCompose.getPorts(DockerCompose.kt:25)
	at ch.derlin.dcvizmermaid.data.DockerCompose$implicitLinks$2.invoke(DockerCompose.kt:28)
	at ch.derlin.dcvizmermaid.data.DockerCompose$implicitLinks$2.invoke(DockerCompose.kt:27)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at ch.derlin.dcvizmermaid.data.DockerCompose.getImplicitLinks(DockerCompose.kt:27)
	at ch.derlin.dcvizmermaid.GenerateGraph.addLinks(GenerateGraph.kt:78)
	at ch.derlin.dcvizmermaid.GenerateGraph.invoke(GenerateGraph.kt:44)
	at ch.derlin.dcvizmermaid.Cli.run(Cli.kt:93)
	at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:170)
	at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:16)
	at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:258)
	at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:255)
	at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:273)
	at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:298)
	at ch.derlin.dcvizmermaid.MainKt.main(main.kt:3)

If I change the value as a integer it works, but a string is the normalized value (according to the spec) as it could be a port range. Thus docker compose config generates it a string. (see #9 )

Hello there! Thank you for reporting this issue. Can you have a look at the PR and see if this resolves your issue?

@derlin thanks for working on a fix. I'm a python developer and my knowledge of the kotlin ecosystem is really limited. The patch seems trivial and I can interpret it as semantically correct, but I don't know really how to compile/test it. Is there a jar file including that change available?

Anyway, if your fix solves my original example I guess it's done then.