diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java index 44601804a7..67fb198a53 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java @@ -2992,7 +2992,7 @@ public class LambdaService implements ResourceProvider { "Path '" + hostPath + "' is not under an allowed hot-reload mount prefix.", 400); } }); - String resolvedHostPath = normalized.toString(); + String resolvedHostPath = toDockerHostPath(normalized); fn.setHotReloadHostPath(resolvedHostPath); fn.setCodeLocalPath(null); fn.setS3Bucket(null); @@ -3002,6 +3002,15 @@ public class LambdaService implements ResourceProvider { LOG.infov("Hot-reload configured for function {0}: bind-mounting {1}", fn.getFunctionName(), resolvedHostPath); } + /** Docker on the host expects a POSIX path, whatever separator the JVM running Floci uses. */ + static String toDockerHostPath(Path normalized) { + StringBuilder path = new StringBuilder(); + for (Path name : normalized) { + path.append('/').append(name); + } + return path.length() == 0 ? "/" : path.toString(); + } + private static boolean isUnderHotReloadPrefix(Path normalizedPath, String prefix) { if (prefix == null || prefix.isBlank()) { return false; diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaServiceTest.java index a47034b490..d9f824c697 100644 --- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaServiceTest.java @@ -991,6 +991,13 @@ class LambdaServiceTest { assertEquals("InvalidParameterValueException", ex.getErrorCode()); } + @Test + void hotReload_dockerHostPathIsAlwaysPosixSeparated() { + assertEquals("/home/ci/code/lib", LambdaService.toDockerHostPath(Path.of("/home/ci/code/lib"))); + assertEquals("/home", LambdaService.toDockerHostPath(Path.of("/home"))); + assertEquals("/", LambdaService.toDockerHostPath(Path.of("/"))); + } + @Test void hotReload_allowListAcceptsThePrefixItselfAndItsChildren() { LambdaService svc = serviceWithHotReload(true, List.of("/home/ci/code"));