fix(ecr,s3): fix CDK compatibility and resolve macOS ECR port conflict (#354)

* fix(ecr,s3): fix CDK compatibility and resolve macOS ECR port conflict
* fix: remove go.mod
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-04-11 15:32:06 -05:00
1 parent e6266fde0f
commit 788ccc8404
8 files changed
+71 -52

No files matched your search

@@ -425,10 +425,10 @@ public interface EmulatorConfig {
@WithDefault("floci-ecr-registry")
String registryContainerName();
@WithDefault("5000")
@WithDefault("5100")
int registryBasePort();
@WithDefault("5099")
@WithDefault("5199")
int registryMaxPort();
@WithDefault("./data/ecr")
@@ -13,6 +13,7 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import java.net.URI;
import java.time.Instant;
import java.util.*;
import java.util.regex.Matcher;
@@ -426,20 +427,29 @@ public class CloudFormationService {
private String fetchTemplateFromS3(String url) {
try {
// Parse S3 URL: http://host:port/bucket/key or https://bucket.s3.amazonaws.com/key
// Parse S3 URL:
// Virtual-hosted local: http://bucket.localhost:4566/key
// Virtual-hosted AWS: https://bucket.s3.region.amazonaws.com/key
// Path-style: http://host:port/bucket/key
String bucket;
String key;
if (url.contains(".s3.amazonaws.com") || url.contains(".s3.")) {
// Virtual-hosted: https://bucket.s3.region.amazonaws.com/key
String host = url.replaceFirst("https?://", "").split("/")[0];
URI uri = URI.create(url);
String host = uri.getHost();
String path = uri.getRawPath();
if (host != null && (host.contains(".s3.") || host.endsWith(".amazonaws.com") ||
(config.hostname().isPresent() && host.endsWith("." + config.hostname().get())) ||
(host.endsWith(".localhost")))) {
// Virtual-hosted style
bucket = host.split("\\.")[0];
key = url.substring(url.indexOf('/', url.indexOf("://") + 3) + 1);
key = path.startsWith("/") ? path.substring(1) : path;
} else {
// Path-style: http://host:port/bucket/key
String path = url.replaceFirst("https?://[^/]+/", "");
int slash = path.indexOf('/');
bucket = slash > 0 ? path.substring(0, slash) : path;
key = slash > 0 ? path.substring(slash + 1) : "";
// Path-style: /bucket/key
String rawPath = path.startsWith("/") ? path.substring(1) : path;
int slash = rawPath.indexOf('/');
bucket = slash > 0 ? rawPath.substring(0, slash) : rawPath;
key = slash > 0 ? rawPath.substring(slash + 1) : "";
}
var obj = s3Service.getObject(bucket, key);
return new String(obj.getData());
@@ -153,7 +153,7 @@ public class S3VirtualHostFilter implements ContainerRequestFilter {
return true;
}
/** Returns true for *.s3.amazonaws.com and *.s3.region.amazonaws.com domains. */
/** Returns true for *.s3.amazonaws.com and other well-known S3 domains. */
private static boolean isAwsS3Domain(String remainder) {
if ("s3.amazonaws.com".equals(remainder)) {
return true;
@@ -162,6 +162,11 @@ public class S3VirtualHostFilter implements ContainerRequestFilter {
if (remainder.startsWith("s3.") && remainder.endsWith(".amazonaws.com")) {
return true;
}
// Support localstack.cloud subdomains (used by cdklocal and other tools)
// Example: bucket.s3.localhost.localstack.cloud
if (remainder.endsWith(".localstack.cloud")) {
return remainder.startsWith("s3.");
}
return false;
}
}