Skip to content

Instantly share code, notes, and snippets.

@m-x-k
Last active April 8, 2018 02:13
Show Gist options
  • Save m-x-k/b5fa655ac7c17ecd48beee8ec96e15b0 to your computer and use it in GitHub Desktop.
Save m-x-k/b5fa655ac7c17ecd48beee8ec96e15b0 to your computer and use it in GitHub Desktop.
Spring Boot Docker Image with external environment configuration
spring:
data:
mongodb:
host: ${MONGO_HOST}
port: ${MONGO_PORT}
database: ${MONGO_DB}
bootRun {
// Defaults to DEVELOPMENT env file
File file = file('dev.env')
println "Loading environment configuration: "
def envProps = [:]
if (file.canRead()) {
def lines = file.readLines()
for (def line : lines){
def props = line.split("=")
println line
envProps[props[0]] = props[1]
}
}
environment(envProps)
}
MONGO_HOST=localhost
MONGO_PORT=27017
MONGO_DB=my_test_db
docker run --env-file=dev.env spring-boot-test-app
spring-boot-test-app:
build: .
env_file:
- dev.env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment