Spring boot: Separating configuration from the image #319
Replies: 2 comments
-
From the buildpack perspective, what you supply will get packaged into the image. If you don't want it in the image, don't supply it. Options for controlling what is passed to buildpacks with Spring Boot:
There are also many ways you can handle conditional functionality & configuration in a Spring app, including profiles and a very flexible external configuration system. None of that changes with buildpacks. If the present options doesn't work for you, you might consider other options like using profiles or some of the options for external configuration. I think those would play nicer, but you can absolutely just do what you're doing above and it should work fine.
I would not really recommend volume mounting into these directories. There are existing files and directories. If those paths change, you could get weird results. Don't get me wrong, if you align everything correctly it'll work, but if something changes and you don't notice you may experience weird errors. In general, when volume mounting I recommend mounting files to a non-existent path that you made up so it's unlikely to conflict with anything else. Then point your app to that location. |
Beta Was this translation helpful? Give feedback.
-
Great. Thank you for your input.On Oct 28, 2024, at 8:54 AM, Daniel Mikusa ***@***.***> wrote:
From the buildpack perspective, what you supply will get packaged into the image. If you don't want it in the image, don't supply it.
Options for controlling what is passed to buildpacks with Spring Boot:
project.toml & excludes, like you found
remove the file from your jar/war (post-processing task in Gradle/Maven)
modify Gradle/Maven settings to not include that file in the jar/war
put an empty application.yml file so it just does nothing
There are also many ways you can handle conditional functionality & configuration in a Spring app, including profiles and a very flexible external configuration system. None of that changes with buildpacks. If the present options doesn't work for you, you might consider other options like using profiles or some of the options for external configuration. I think those would play nicer, but you can absolutely just do what you're doing above and it should work fine.
(this path was not obvious to me and I had to do trial and error to figure it out). So to me it looks like the working directory is not /workspace but /workspace/BOOT-INF/classes. Should this be documented?
/workspace is the root of your application in the buildpack. BOOT-INF/classes is the path that Spring uses and is not specific to buildpacks. If you look inside one of your executable Spring Boot JAR files, you'll see this path.
I would not really recommend volume mounting into these directories. There are existing files and directories. If those paths change, you could get weird results. Don't get me wrong, if you align everything correctly it'll work, but if something changes and you don't notice you may experience weird errors.
In general, when volume mounting I recommend mounting files to a non-existent path that you made up so it's unlikely to conflict with anything else. Then point your app to that location.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi,
Does the Spring boot buildpack have an option to not include configuration file (E.g. application.yml) as part of the image? Currently it seems to supply the checked in application.yml. In most cases, we do not use the same configuration in production but instead supply one dynamically using K8s configmaps. I would think this is a common use case. I had to do multiple steps to get this to work
Beta Was this translation helpful? Give feedback.
All reactions