Update React / Spring / MySQL example (#99)
* Update README.md title from NodeJS to Spring Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com> * Always restart spring backend service Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com> * Also pass db-password secret to spring backend Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com> * Add healthcheck to the mysql service - a start_period of 30s + 15s (interval * retries) should be long enough for mysql to initialize Signed-off-by: Friedrich Greiner <greinerfriedrich@gmail.com>master
parent
a92c067f75
commit
a2cf9cc9f3
@ -0,0 +1,30 @@
|
||||
package com.company.project.configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* Read property from docker secret file.
|
||||
*/
|
||||
public class DockerSecretsProcessor implements EnvironmentPostProcessor {
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
Resource resource = new FileSystemResource("/run/secrets/db-password");
|
||||
if (resource.exists() && System.getProperty("MYSQL_PASSWORD") == null) {
|
||||
try {
|
||||
String dbPassword = StreamUtils.copyToString(resource.getInputStream(), Charset.defaultCharset());
|
||||
System.setProperty("MYSQL_PASSWORD", dbPassword);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=com.company.project.configuration.DockerSecretsProcessor
|
Loading…
Reference in New Issue