appsody / stacks

Appsody application stacks. This repo will be archived soon.
https://appsody.dev
Apache License 2.0
89 stars 120 forks source link

How do you configure the Liberty server used by java-microprofile during appsody run? #516

Closed GregDritschler closed 4 years ago

GregDritschler commented 4 years ago

Summary

The java-microprofile stack runs a Liberty server. It is likely that this server will depend on external resources such as a database, a messaging provider, etc. In a Kubernetes environment it's possible to configure the Liberty server by using environment variables or volumes which are populated from secrets. However when the developer is running the stack locally the user needs some other way to configure the server.

It is possible to configure the Liberty server for appsody test by updating the pom to pass additional configuration files specifically for the correct maven phase and plugin goal.

            <plugin>
                <groupId>net.wasdev.wlp.maven.plugins</groupId>
                <artifactId>liberty-maven-plugin</artifactId>
                ...
                <executions>
                    <execution>
                        <id>test-start-server</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                          <goal>test-start-server</goal>
                        </goals>
                        <configuration>
                           <serverEnv>src/test/resources/server.env</serverEnv>
                        </configuration>
                    </execution>
                </executions>

However this approach does not work for appsody run because it runs the Liberty maven plugin's run goal directly from the command line.

mvn -B -Dmaven.repo.local=/mvn/repository liberty:run

Since this goal is run outside the build lifecycle, there is no phase to attach configuration. The only way to do it is to specify a configuration id on the command line, e.g.

mvn liberty:run@execution1

The user doesn't have the ability to alter the maven command so this doesn't work.

See https://maven.apache.org/guides/mini/guide-configuring-plugins.html

I would like to know how a user of the java-microprofile stack can configure the liberty server when using appsody run, without hardcoding the configuration into the server.

scottkurz commented 4 years ago

Interesting question. I'm more interested in how to do the equivalent in dev mode since that's the direction we're trying to move the stack towards ( in this PR).

scottkurz commented 4 years ago

@GregDritschler one answer to this would be to change appsody build so that we're NOT pulling in server.env. This is suggested by the updated https://openliberty.io/guides/getting-started.html guide where the Docker build:

https://github.com/OpenLiberty/guide-getting-started/blob/master/finish/Dockerfile

only copies in the WAR and the source 'config' dir.

That all said, this requires some thought about existing projects so might need to put that out for comment and roll this into a bigger change (like an 0.3 minor version bump).

GregDritschler commented 4 years ago

It can be solved by using docker options.

appsody run --docker-options="--env-file=src/.../server.env"

This works well enough for my case.

The server.env file needs to be included in .gitignore if you don't want the credentials checked in.

Closing the issue.

yeekangc commented 4 years ago

FYI, @gkwan-ibm.

scottkurz commented 4 years ago

See also https://github.com/OpenLiberty/ci.maven/issues/708