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

Environment Variables not replaced in application.properties when running as Docker container #4571

Closed
ivangfr opened this issue Oct 15, 2019 · 6 comments
Labels
area/config area/smallrye kind/bug Something isn't working triage/out-of-date This issue/PR is no longer valid or relevant

Comments

@ivangfr
Copy link

ivangfr commented Oct 15, 2019

Describe the bug
In my application.properties, I have the following property

mp.messaging.outgoing.news.bootstrap.servers=${KAFKA_HOST:localhost}:${KAFKA_PORT:9092}

When I run the application in development mode ./mvnw compile quarkus:dev the url to local kafka cluster is written correctly, i.e, localhost:9092

Then, I build the Docker image

./mvnw clean package -DskipTests
docker build -f src/main/docker/Dockerfile.jvm -t docker.mycompany.com/quarkus-producer-api-jvm:1.0.0 .

Finally, when I run the container

docker run -d --rm --name quarkus-producer-api-jvm \
  --network producer-consumer_default \
  -e KAFKA_HOST=kafka \
  -p 9100:8080 \
  docker.mycompany.com/quarkus-producer-api-jvm:1.0.0

I get the following in the logs

INFO  [org.apa.kaf.cli.pro.ProducerConfig] (main) ProducerConfig values: 
	...
	bootstrap.servers = [${KAFKA_HOST:localhost}:${KAFKA_PORT:9092}]
	...
Caused by: org.apache.kafka.common.config.ConfigException: Invalid url in bootstrap.servers: ${KAFKA_HOST:localhost}:${KAFKA_PORT:9092}

Expected behavior
The correct url to Kafka cluster should be

INFO  [org.apa.kaf.cli.pro.ProducerConfig] (main) ProducerConfig values: 
	...
	bootstrap.servers = [kafka:9092]
	...

Actual behavior

INFO  [org.apa.kaf.cli.pro.ProducerConfig] (main) ProducerConfig values: 
	...
	bootstrap.servers = [${KAFKA_HOST:localhost}:${KAFKA_PORT:9092}]
	...

Configuration

mp.messaging.outgoing.news.connector=smallrye-kafka
mp.messaging.outgoing.news.topic=quarkus.news.json
mp.messaging.outgoing.news.bootstrap.servers=${KAFKA_HOST:localhost}:${KAFKA_PORT:9092}
mp.messaging.outgoing.news.value.serializer=io.quarkus.kafka.client.serialization.JsonbSerializer

Environment (please complete the following information):

  • Output of uname -a or ver:
  • Output of java -version:
    openjdk version "1.8.0_222"
    OpenJDK Runtime Environment (build 1.8.0_222-20190711112007.graal.jdk8u-src-tar-gz-b08)
    OpenJDK 64-Bit GraalVM CE 19.2.0 (build 25.222-b08-jvmci-19.2-b02, mixed mode)
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 0.24.0
@ivangfr ivangfr added the kind/bug Something isn't working label Oct 15, 2019
@xfh
Copy link
Contributor

xfh commented Oct 27, 2019

Did this ever work? I don't know how far the Quarkus support for configuration properties at runtime is supposed to go.

@ivangfr you can add the environment variable KAFKA_BOOTSTRAP_SERVERS to your Quarkus container, to specify the bootstrap server globally, and remove mp.messaging.outgoing.news.bootstrap.servers. Maybe that works for you? You can also try if you get it working with MP_MESSAGING_OUTGOING_NEWS_BOOTSTRAP_SERVERS=HOST:PORT.
See also https://quarkus.io/guides/application-configuration-guide#overriding-properties-at-runtime

I think the Kafka Guide is not very specific about how properties are handled and which properties are fixed at build time. The Kafka Streams Guide is more explicit about properties.

@ivangfr
Copy link
Author

ivangfr commented Oct 27, 2019

Hey @xfh,

Using MP_MESSAGING_OUTGOING_NEWS_BOOTSTRAP_SERVERS=HOST:PORT works.

So now, my docker command looks like

docker run -d --rm --name quarkus-producer-api-jvm \
  -p 9100:8080 \
  -e MP_MESSAGING_OUTGOING_NEWS_BOOTSTRAP_SERVERS=kafka:9092 \
  --network producer-consumer_default \
  docker.mycompany.com/quarkus-producer-api-jvm:1.0.0

What I also did was to set two properties in application.properties, one for development and another for "production"

%dev.mp.messaging.outgoing.news.bootstrap.servers=localhost:9092
mp.messaging.outgoing.news.bootstrap.servers=kafka:9092

So, for "production" the default is kafka:9092. If for some reason the kafka host or port is different (for example, kafka-service:9093), I can overwrite it using the environment variable MP_MESSAGING_OUTGOING_NEWS_BOOTSTRAP_SERVERS=kafka-service:9093

I have just asked because other frameworks like Spring Boot and Micronaut work when the property in application.properties has the format as shown below

mp.messaging.outgoing.news.bootstrap.servers=${KAFKA_HOST:localhost}:${KAFKA_PORT:9092}

@djajcevic
Copy link

This works for me: quarkus.datasource.username=${DB_USERNAME:na}.
Configuration for REST clients do no work; mp-rest/url=${SOME_URL:http://...}, but this is OK since it's evaluated at build time. Would be great if this can be dynamic.

@xfh
Copy link
Contributor

xfh commented Nov 14, 2019

I think more of the properties with the mp.messaging.* should be evaluated at runtime. I've found another issue in combination with confluentinc's Schema Registry: the URL of the schema registry should be configurable for different environments as well.

A non-breaking strategy would be to make all these properties runtime configurable, unless they are known to be static, like *.connector, *.value.serializer, *.value.deserializer, *.key.serializer, *.key.deserializer

@xfh
Copy link
Contributor

xfh commented Nov 15, 2019

Hi @dmlloyd does #5387 also fix this issue?

@dmlloyd
Copy link
Member

dmlloyd commented Nov 15, 2019

Yes it should but we'll need to explicitly verify it to be sure.

xfh added a commit to dvbern/kibon-exchange-service that referenced this issue Nov 21, 2019
All the mp.messagging.* properties are hard-coded during build time.
Variables with run-time configuration are unfortunately not supported.

This limits configuration for specific environments and has been
reported: quarkusio/quarkus#4571 (comment)

Currently, it works, as long as quarkus runs in the same docker network
as the schema-registry. The http://schema-registry:8081 URL must be
resolvable at run-time.
@gsmet gsmet added the triage/out-of-date This issue/PR is no longer valid or relevant label Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config area/smallrye kind/bug Something isn't working triage/out-of-date This issue/PR is no longer valid or relevant
Projects
None yet
Development

No branches or pull requests

7 participants