mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 14:30:28 -05:00
feat: add HOSTNAME_EXTERNAL support for multi-container Docker setups (#82)
Hey @justmeben, thanks for opening this! Great that you're willing to work on it. Feel free to go ahead, the issue is yours! -- * feat: add HOSTNAME_EXTERNAL support for multi-container Docker setups SQS, SNS, S3, EventBridge, and Lambda services all use `baseUrl` to construct URLs in API responses (e.g. SQS QueueUrl). This URL defaults to `http://localhost:4566`, which breaks in multi-container Docker Compose setups where "localhost" resolves to the wrong container. Add `hostnameExternal` config property (env: FLOCI_HOSTNAME_EXTERNAL) that overrides the hostname in all response URLs. When set to the Docker service name (e.g. "floci"), SQS returns `http://floci:4566/000000000000/queue` instead of `http://localhost:4566/...`. This is equivalent to LocalStack's HOSTNAME_EXTERNAL and is essential for any multi-container integration testing setup. Closes #81 * rename to FLOCI_HOSTNAME to match LocalStack's LOCALSTACK_HOSTNAME
This commit is contained in:
1 parent
e9461645ba
commit
20b40c1565
9 files changed
+52
-7
No files matched your search
@@ -10,6 +10,28 @@ public interface EmulatorConfig {
|
||||
@WithDefault("http://localhost:4566")
|
||||
String baseUrl();
|
||||
|
||||
/**
|
||||
* When set, overrides the hostname in base-url for URLs returned in API responses
|
||||
* (e.g. SQS QueueUrl, SNS TopicArn). This is needed in multi-container Docker setups
|
||||
* where "localhost" in the response URL would resolve to the wrong container.
|
||||
*
|
||||
* Example: FLOCI_HOSTNAME=floci makes SQS return
|
||||
* http://floci:4566/000000000000/my-queue instead of http://localhost:4566/...
|
||||
*
|
||||
* Equivalent to LocalStack's LOCALSTACK_HOSTNAME.
|
||||
*/
|
||||
Optional<String> hostname();
|
||||
|
||||
/**
|
||||
* Returns the effective base URL, taking hostname into account.
|
||||
* If hostname is set, replaces the host in baseUrl with it.
|
||||
*/
|
||||
default String effectiveBaseUrl() {
|
||||
return hostname()
|
||||
.map(h -> baseUrl().replaceFirst("://[^:/]+(:\\d+)?", "://" + h + "$1"))
|
||||
.orElse(baseUrl());
|
||||
}
|
||||
|
||||
@WithDefault("us-east-1")
|
||||
String defaultRegion();
|
||||
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public class EventBridgeService {
|
||||
new TypeReference<Map<String, Rule>>() {}),
|
||||
storageFactory.create("eventbridge", "eventbridge-targets.json",
|
||||
new TypeReference<Map<String, List<Target>>>() {}),
|
||||
regionResolver, lambdaService, sqsService, snsService, objectMapper, config.baseUrl()
|
||||
regionResolver, lambdaService, sqsService, snsService, objectMapper, config.effectiveBaseUrl()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ public class LambdaService {
|
||||
int batchSize = toInt(request.get("BatchSize"), 10);
|
||||
boolean enabled = !Boolean.FALSE.equals(request.get("Enabled"));
|
||||
|
||||
String queueUrl = eventSourceArn.contains(":sqs:") ? AwsArnUtils.arnToQueueUrl(eventSourceArn, config.baseUrl()) : null;
|
||||
String queueUrl = eventSourceArn.contains(":sqs:") ? AwsArnUtils.arnToQueueUrl(eventSourceArn, config.effectiveBaseUrl()) : null;
|
||||
|
||||
EventSourceMapping esm = new EventSourceMapping();
|
||||
esm.setUuid(UUID.randomUUID().toString());
|
||||
@@ -437,7 +437,7 @@ public class LambdaService {
|
||||
urlConfig.setAuthType((String) request.getOrDefault("AuthType", "NONE"));
|
||||
|
||||
String urlId = UUID.nameUUIDFromBytes((region + functionName + (qualifier != null ? qualifier : "")).getBytes()).toString().replace("-", "").substring(0, 32);
|
||||
String baseHost = config.baseUrl().replaceFirst("https?://", "");
|
||||
String baseHost = config.effectiveBaseUrl().replaceFirst("https?://", "");
|
||||
String url = String.format("http://%s.lambda-url.%s.%s/", urlId, region, baseHost);
|
||||
urlConfig.setFunctionUrl(url);
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public class SqsEventSourcePoller {
|
||||
this.functionStore = functionStore;
|
||||
this.esmStore = esmStore;
|
||||
this.pollIntervalMs = config.services().lambda().pollIntervalMs();
|
||||
this.baseUrl = config.baseUrl();
|
||||
this.baseUrl = config.effectiveBaseUrl();
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class S3Service {
|
||||
new TypeReference<Map<String, S3Object>>() {
|
||||
}),
|
||||
Path.of(config.storage().persistentPath()).resolve("s3"),
|
||||
sqsService, snsService, regionResolver, config.baseUrl(), objectMapper
|
||||
sqsService, snsService, regionResolver, config.effectiveBaseUrl(), objectMapper
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class SnsService {
|
||||
regionResolver,
|
||||
sqsService,
|
||||
lambdaService,
|
||||
config.baseUrl(),
|
||||
config.effectiveBaseUrl(),
|
||||
objectMapper
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class SqsService {
|
||||
}),
|
||||
config.services().sqs().defaultVisibilityTimeout(),
|
||||
config.services().sqs().maxMessageSize(),
|
||||
config.baseUrl(),
|
||||
config.effectiveBaseUrl(),
|
||||
regionResolver
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user