Last active
April 8, 2018 02:13
-
-
Save m-x-k/b5fa655ac7c17ecd48beee8ec96e15b0 to your computer and use it in GitHub Desktop.
Spring Boot Docker Image with external environment configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spring: | |
data: | |
mongodb: | |
host: ${MONGO_HOST} | |
port: ${MONGO_PORT} | |
database: ${MONGO_DB} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MONGO_HOST=localhost | |
MONGO_PORT=27017 | |
MONGO_DB=my_test_db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run --env-file=dev.env spring-boot-test-app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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