-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
4 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
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
30 changes: 30 additions & 0 deletions
30
...mysql/backend/src/main/java/com/company/project/configuration/DockerSecretsProcessor.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
react-java-mysql/backend/src/main/resources/META-INF/spring.factories
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.springframework.boot.env.EnvironmentPostProcessor=com.company.project.configuration.DockerSecretsProcessor |
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