mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(core): let a native host path follow a configured persistent path (#5777)
HostDefaultsConfigSource set floci.storage.host-persistent-path to the user
data directory as a fixed value. A persistent path set only in
config/application.yml then moved the state but not the directory child
containers bind. The host path now defaults to ${floci.storage.persistent-path},
so it follows whichever persistent path wins, and an explicit host path still
takes precedence.
Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
e24a2882bc
commit
f897dfc3b6
2 files changed
+36
-3
No files matched your search
@@ -20,6 +20,7 @@ public class HostDefaultsConfigSource implements ConfigSource {
|
||||
static final int ORDINAL = 260;
|
||||
static final String PERSISTENT_PATH = "floci.storage.persistent-path";
|
||||
static final String HOST_PERSISTENT_PATH = "floci.storage.host-persistent-path";
|
||||
static final String FOLLOW_PERSISTENT_PATH = "${" + PERSISTENT_PATH + "}";
|
||||
|
||||
private final Map<String, String> properties;
|
||||
|
||||
@@ -30,8 +31,9 @@ public class HostDefaultsConfigSource implements ConfigSource {
|
||||
HostDefaultsConfigSource(boolean nativeOnHost) {
|
||||
if (nativeOnHost) {
|
||||
String dir = HostDataDir.persistentPathDefault();
|
||||
// The binary and Docker share the host filesystem, so child containers bind the same path.
|
||||
this.properties = Map.of(PERSISTENT_PATH, dir, HOST_PERSISTENT_PATH, dir);
|
||||
// The binary and Docker share the host filesystem, so child containers bind the same path,
|
||||
// including one the user sets in config/application.yml.
|
||||
this.properties = Map.of(PERSISTENT_PATH, dir, HOST_PERSISTENT_PATH, FOLLOW_PERSISTENT_PATH);
|
||||
} else {
|
||||
this.properties = Map.of();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package io.github.hectorvent.floci.config;
|
||||
|
||||
import io.smallrye.config.PropertiesConfigSource;
|
||||
import io.smallrye.config.SmallRyeConfig;
|
||||
import io.smallrye.config.SmallRyeConfigBuilder;
|
||||
import org.eclipse.microprofile.config.spi.ConfigSource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.aMapWithSize;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
@@ -27,8 +33,28 @@ class HostDefaultsConfigSourceTest {
|
||||
@Test
|
||||
void nativeHostRunSetsBothPathsToTheSameDirectory() {
|
||||
HostDefaultsConfigSource source = new HostDefaultsConfigSource(true);
|
||||
SmallRyeConfig config = configWith(source);
|
||||
String dir = source.getValue(HostDefaultsConfigSource.PERSISTENT_PATH);
|
||||
assertThat(source.getValue(HostDefaultsConfigSource.HOST_PERSISTENT_PATH), equalTo(dir));
|
||||
assertThat(config.getValue(HostDefaultsConfigSource.PERSISTENT_PATH, String.class), equalTo(dir));
|
||||
assertThat(config.getValue(HostDefaultsConfigSource.HOST_PERSISTENT_PATH, String.class), equalTo(dir));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hostPathFollowsAPersistentPathTheUserConfigures() {
|
||||
SmallRyeConfig config = configWith(new HostDefaultsConfigSource(true),
|
||||
new PropertiesConfigSource(Map.of(HostDefaultsConfigSource.PERSISTENT_PATH, "/srv/floci"),
|
||||
"config/application.yml", 265));
|
||||
assertThat(config.getValue(HostDefaultsConfigSource.HOST_PERSISTENT_PATH, String.class),
|
||||
equalTo("/srv/floci"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anExplicitHostPathStillWins() {
|
||||
SmallRyeConfig config = configWith(new HostDefaultsConfigSource(true),
|
||||
new PropertiesConfigSource(Map.of(HostDefaultsConfigSource.PERSISTENT_PATH, "/srv/floci",
|
||||
HostDefaultsConfigSource.HOST_PERSISTENT_PATH, "/mnt/floci"), "env", 300));
|
||||
assertThat(config.getValue(HostDefaultsConfigSource.HOST_PERSISTENT_PATH, String.class),
|
||||
equalTo("/mnt/floci"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -36,4 +62,9 @@ class HostDefaultsConfigSourceTest {
|
||||
// classpath application.yml is 255, config/application.yml in the working directory 265.
|
||||
assertThat(new HostDefaultsConfigSource(false).getOrdinal(), allOf(greaterThan(255), lessThan(265)));
|
||||
}
|
||||
|
||||
private static SmallRyeConfig configWith(ConfigSource... sources) {
|
||||
// The default interceptors expand ${...} expressions, as the runtime config does.
|
||||
return new SmallRyeConfigBuilder().addDefaultInterceptors().withSources(sources).build();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user