Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

spring-boot generator can not handle multi-profile configuration #797

Closed
ppatierno opened this issue Feb 2, 2017 · 11 comments · Fixed by #1745
Closed

spring-boot generator can not handle multi-profile configuration #797

ppatierno opened this issue Feb 2, 2017 · 11 comments · Fixed by #1745
Assignees

Comments

@ppatierno
Copy link

ppatierno commented Feb 2, 2017

Description

I have a Spring Boot application.yml file with following format :

spring:
  profiles:
    active: default
---

spring:
  profiles: default
hono:
  downstream:
    host: localhost
    port: 5672
    name: hono-server
  maxInstances: 0
  singleTenant: false
  server:
    bindaddress: 127.0.0.1
    port: 5672

Using the plugin I have the following error :

[ERROR] Failed to execute goal io.fabric8:fabric8-maven-plugin:3.2.14:resource (default) on project hono-app: Execution default of goal io.fabric8:fabric8-maven-plugin:3.2.14:resource failed: Cannot extract generator: expected a single document in the stream
[ERROR] in 'reader', line 1, column 1:
[ERROR] spring:
[ERROR] ^
[ERROR] but found another document
[ERROR] in 'reader', line 4, column 1:
[ERROR] ---
[ERROR] ^
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal io.fabric8:fabric8-maven-plugin:3.2.14:resource (default) on project hono-app: Execution default of goal io.fabric8:fabric8-maven-plugin:3.2.14:resource failed: Cannot extract generator: expected a single document in the stream
 in 'reader', line 1, column 1:
    spring:
    ^
but found another document
 in 'reader', line 4, column 1:
    ---
    ^

	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.MojoExecutor.executeForkedExecutions(MojoExecutor.java:352)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:197)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	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)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal io.fabric8:fabric8-maven-plugin:3.2.14:resource failed: Cannot extract generator: expected a single document in the stream
 in 'reader', line 1, column 1:
    spring:
    ^
but found another document
 in 'reader', line 4, column 1:
    ---
    ^

	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	... 24 more
Caused by: java.lang.IllegalArgumentException: Cannot extract generator: expected a single document in the stream
 in 'reader', line 1, column 1:
    spring:
    ^
but found another document
 in 'reader', line 4, column 1:
    ---
    ^

	at io.fabric8.maven.plugin.mojo.build.ResourceMojo$3.customizeConfig(ResourceMojo.java:620)
	at io.fabric8.maven.docker.config.ConfigHelper.resolveImages(ConfigHelper.java:51)
	at io.fabric8.maven.plugin.mojo.build.ResourceMojo.getResolvedImages(ResourceMojo.java:593)
	at io.fabric8.maven.plugin.mojo.build.ResourceMojo.executeInternal(ResourceMojo.java:225)
	at io.fabric8.maven.plugin.mojo.AbstractFabric8Mojo.execute(AbstractFabric8Mojo.java:74)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	... 25 more
Caused by: expected a single document in the stream
 in 'reader', line 1, column 1:
    spring:
    ^
but found another document
 in 'reader', line 4, column 1:
    ---
    ^

	at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:110)
	at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:120)
	at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:450)
	at org.yaml.snakeyaml.Yaml.loadAs(Yaml.java:444)
	at io.fabric8.maven.core.util.SpringBootUtil.getPropertiesFromYamlResource(SpringBootUtil.java:97)
	at io.fabric8.maven.core.util.SpringBootUtil.getSpringBootApplicationProperties(SpringBootUtil.java:51)
	at io.fabric8.maven.generator.springboot.SpringBootGenerator.extractPorts(SpringBootGenerator.java:99)
	at io.fabric8.maven.generator.javaexec.JavaExecGenerator.customize(JavaExecGenerator.java:116)
	at io.fabric8.maven.generator.springboot.SpringBootGenerator.customize(SpringBootGenerator.java:76)
	at io.fabric8.maven.plugin.generator.GeneratorManager.generate(GeneratorManager.java:62)
	at io.fabric8.maven.plugin.mojo.build.ResourceMojo$3.customizeConfig(ResourceMojo.java:618)
	... 30 more
[ERROR] 
[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

It seems that it's not able to handle the "---" separator.

Info

  • f-m-p version : 3.2.14
  • Maven version (mvn -v) : 3.3.9
@rhuss
Copy link
Contributor

rhuss commented Feb 2, 2017

Seems to be a limitation of the SpringBootGenerator which can't properly handle multi object YAML files. The generator examines the Spring Boot application for ports to expose, but I wonder what it should take in profile situation likes this. Should it pick randomly one of the given ports ? Check whether both are the same (which is very likely) and if not, throw an error ?

Something to discuss ...

@ppatierno
Copy link
Author

In my case the first part of the application.yml defines the active profile, so it means that the SpringBootGenerator should be able to get this information exposing port for that profile. Of course this is only one possible case even because the active profile could be specified on the command line and not inside the same application.yml.

@rhuss rhuss changed the title Spring Boot : Issue with Multi-profile YAML documents spring-boot generator can not handle multi-profile configuration Feb 3, 2017
@magick93
Copy link

We are trying to set the active springboot profile like so:

<plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>fabric8-maven-plugin</artifactId>
                <version>3.2.20</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>resource</goal>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <images>
                        <image>
                            <name>${docker.image}</name>
                            <build>
                                <from>${docker.from}</from>
                                <assembly>
                                    <basedir>/app</basedir>
                                    <descriptorRef>${docker.assemblyDescriptorRef}</descriptorRef>
                                </assembly>
                                <env>
                                    <HTTP_PORT>8080</HTTP_PORT>
                                    <JAVA_APP_JAR>${project.artifactId}-${project.version}.war</JAVA_APP_JAR>
                                </env>
                                <ports>
                                    <port>8080</port>
                                    <port>8778</port>
                                </ports>
                                <cmd>
                                    <shell>java -jar /app/${project.artifactId}-${project.version}.war --spring.profiles.active=prod</shell>
                                </cmd>
                            </build>
                        </image>
                    </images>

Not sure if this is the recommended way of doing it. But noticed that the --spring.profiles.active=prod arg is not passed.

@rhuss
Copy link
Contributor

rhuss commented Feb 14, 2017

So you are not using the spring-boot generator but you are specifying the image directly, right ?

Please note that if you do it this way your create an specific image for this environment which can't be changed later on.

Also, when you use OpenShift S2I builds then the definitions here are not use (i.e. the <shell> spec) since the S2I image determines how the application starts. Actually for an OpenShift S2I only the assembly and from (which specifies the builder image) is relevant all other information are ignored.

When you use a Docker build (kubernetes mode), then <cmd> specifies the default command, but it depends what command is used in the resource descriptor for the Deployment definition, as this overrides the specification here.

@tuyenttran
Copy link

Can we detect active profiles from system environment or parameter (spring.profiles.active) when parsing YAML file?

@stale
Copy link

stale bot commented Oct 4, 2018

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

@stale stale bot added the status/stale Issue/PR considered to be stale label Oct 4, 2018
@stale stale bot closed this as completed Oct 11, 2018
@anwarchk
Copy link

@rhuss This is a common pattern in Spring Boot applications and wondering was there a fix to the problem reported here. For eg: in this configuration, I declare common properties under the default implicit profile and then for the kubernetes profile, I add additional properties

spring:
 application:
    name: spring-boot-k8-recipes

management:
 endpoints:
   web:
     base-path: '/'
   enabled-by-default: false
 endpoint:
     health:
       enabled: true
     metrics:
       enabled: true
---
spring:
 profiles: kubernetes
cloud:
  kubernetes:
    reload:
     enabled: true```

@rohanKanojia rohanKanojia reopened this May 24, 2019
@stale stale bot removed the status/stale Issue/PR considered to be stale label May 24, 2019
@anwarchk
Copy link

@rhuss @rohanKanojia wondering if there is a way to fix this ? I would be happy to provide a PR if I get some pointers about to where to start looking in the code...thanks !!!

@stale
Copy link

stale bot commented Aug 29, 2019

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

@stale stale bot added the status/stale Issue/PR considered to be stale label Aug 29, 2019
@anwarchk
Copy link

@rohanKanojia @rhuss

@stale stale bot removed the status/stale Issue/PR considered to be stale label Aug 29, 2019
@rohanKanojia
Copy link
Member

ack, let me revisit this whenever I get time.

@rohanKanojia rohanKanojia self-assigned this Oct 24, 2019
rohanKanojia added a commit to rohanKanojia/fabric8-maven-plugin that referenced this issue Oct 24, 2019
rohanKanojia added a commit to rohanKanojia/fabric8-maven-plugin that referenced this issue Oct 24, 2019
rohanKanojia added a commit to rohanKanojia/fabric8-maven-plugin that referenced this issue Nov 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
6 participants