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

Support externalized configuration for launching with bazel run #135

Closed
plaird opened this issue Jun 28, 2021 · 2 comments
Closed

Support externalized configuration for launching with bazel run #135

plaird opened this issue Jun 28, 2021 · 2 comments

Comments

@plaird
Copy link
Contributor

plaird commented Jun 28, 2021

It is a useful feature for Spring Boot to load external configuration files (files not included in the exectuable jar) at runtime. This allows you to override some properties in production for example. You can do this via command line arguments, but the property file approach is common.

https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.files

Spring Boot will automatically find and load application.properties and application.yaml files from the following locations when your application starts:

  • The current directory
  • The /config subdirectory in the current directory
  • Immediate child directories of the /config subdirectory

This works if you launch the rules_spring built executable jar with java -jar:

java -jar example.jar

But we don't have a great way to do this when launching the application with bazel run. As a workaround the developer can invoke bazel run like this:

bazel run //examples/demoapp -- --spring.config.location=/tmp/demoapp/config/

but it feels like we should automatically honor package level files like:

  • //examples/demoapp/application.properties
  • //examples/demoapp/config/application.properties
  • //examples/demoapp/config/secure/application.properties

When working on this, remember to support profile specific prop files: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.files.profile-specific

@plaird
Copy link
Contributor Author

plaird commented Dec 21, 2024

The right solution to this is to use bazelrun_data.

filegroup(
    name = "bazelrun_data_files",
    srcs = [
        "application.properties",
        "config/application.properties",
    ],
)

springboot(
   ...
   bazelrun_data = [":bazelrun_data_files"],
)

which adds the config files to the target's runfiles. Then, we should derive the directories from the data list that contain application*.properties files, and add those directories to a auto spring.config.location option passed when invoking the JVM.

That said, I am having problems finding a good way to resolve the paths to each data file prior to handing off to the write_bazelrun_env.sh shell script. This probably has to wait until we remove shell scripts from the impl.

@plaird
Copy link
Contributor Author

plaird commented Dec 22, 2024

@plaird plaird closed this as completed Dec 22, 2024
@plaird plaird added the 2.6.0 label Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant