Search code examples
javaspring-bootdockergradlejib

Stop packaging application-local properties in Docker image


I have a Spring Boot application that includes several application-XXX.properties profiles. When I build Docker image using jib, I notice that all these properties files are packaged in the image in /app/resouces.

Is there a way to only include the main application.properties and prevent including the specific properties for various profiles in the Docker image? This could potentially leak some sensitive details if left there.

Is this some jib gradle configuration?


Solution

  • Don't include them in the folders packed to the JAR file. I suggest the following structure:

    app
    │
    ├── pom.xml
    ├── ext
    │   └── application-localhost.properties
    └── src
        ├── main
        │   ├── java
        │   │   └── ...
        │   └── resources
        │       └── application.properties
        └── test
            ├── java
            │   └── ...
            └── resources
                └── ...
    
    • src/main/resources are the resources packed and delivered with the JAR.
    • ext are the resources specific to each environment (ex. localhost)
      • if you run the application locally, mark the ext directory as the resources for the local build.
      • if you run the application on the environment, ex. a Docker container in K8S, mount the external properties as config-map.