diff --git a/docker-compose.yml b/docker-compose.yml index 9cec3d31db..0b936a43ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,27 +1,28 @@ -services: - floci: - build: - context: . - dockerfile: Dockerfile - ports: - - "4566:4566" - - "6379-6399:6379-6399" - - "7001-7099:7001-7099" - volumes: - - /var/run/docker.sock:/var/run/docker.sock - - ./scripts:/etc/floci/init/start.d - - ./scripts:/etc/floci/init/stop.d - environment: - FLOCI_SERVICES_DOCKER_NETWORK: floci_default - FLOCI_SERVICES_RDS_PROXY_BASE_PORT: "7001" - FLOCI_STORAGE_PERSISTENT_PATH: /app/data - networks: - floci_default: - aliases: - - localhost.floci.cloud - -networks: - floci_default: - name: floci_default - - +services: + floci: + build: + context: . + dockerfile: Dockerfile + ports: + - "4566:4566" + - "5100-5199:5100-5199" + - "6379-6399:6379-6399" + - "7001-7099:7001-7099" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ./scripts:/etc/floci/init/start.d + - ./scripts:/etc/floci/init/stop.d + environment: + FLOCI_SERVICES_DOCKER_NETWORK: floci_default + FLOCI_SERVICES_RDS_PROXY_BASE_PORT: "7001" + FLOCI_STORAGE_PERSISTENT_PATH: /app/data + networks: + floci_default: + aliases: + - localhost.floci.cloud + +networks: + floci_default: + name: floci_default + + diff --git a/docs/configuration/ports.md b/docs/configuration/ports.md index 9703359138..2f989023d2 100644 --- a/docs/configuration/ports.md +++ b/docs/configuration/ports.md @@ -5,6 +5,7 @@ | Port / Range | Protocol | Purpose | |---|---|---| | `4566` | HTTP | All AWS API calls (every service) | +| `5100–5199` | HTTP | ECR Registry port, for `docker push` / `docker pull` | | `6379–6399` | TCP | ElastiCache Redis proxy, one port per replication group | | `7001–7099` | TCP | RDS proxy, one port per DB instance | | `9200–9299` | HTTP | Lambda Runtime API (internal: consumed by spawned Lambda containers, not host-mapped) | @@ -84,6 +85,7 @@ services: image: hectorvent/floci:latest ports: - "4566:4566" + - "5100-5199:5100-5199" - "6379-6399:6379-6399" - "7001-7099:7001-7099" ``` diff --git a/docs/services/ecr.md b/docs/services/ecr.md index a92bbcecf8..8ba487c9ed 100644 --- a/docs/services/ecr.md +++ b/docs/services/ecr.md @@ -48,8 +48,8 @@ floci: enabled: true registry-image: "registry:2" registry-container-name: floci-ecr-registry - registry-base-port: 5000 - registry-max-port: 5099 + registry-base-port: 5100 + registry-max-port: 5199 data-path: ./data/ecr tls-enabled: false keep-running-on-shutdown: true @@ -61,7 +61,7 @@ floci: | `enabled` | `true` | Enable the ECR control plane and lazy registry start | | `registry-image` | `registry:2` | Backing OCI registry image | | `registry-container-name` | `floci-ecr-registry` | Name used for idempotent reuse across restarts | -| `registry-base-port` / `-max-port` | `5000` / `5099` | Port range allocated for the published registry port | +| `registry-base-port` / `-max-port` | `5100` / `5199` | Port range allocated for the published registry port | | `data-path` | `./data/ecr` | Bind-mount root for `/registry` (the registry's `/var/lib/registry`) | | `keep-running-on-shutdown` | `true` | Leave the container up so the next Floci start adopts it | | `uri-style` | `hostname` | `hostname` returns `*.dkr.ecr..localhost`; `path` returns `localhost:///` | @@ -79,7 +79,7 @@ aws ecr create-repository \ # { # "repository": { # "repositoryArn": "arn:aws:ecr:us-east-1:000000000000:repository/floci-it/app", -# "repositoryUri": "000000000000.dkr.ecr.us-east-1.localhost:5000/floci-it/app", +# "repositoryUri": "000000000000.dkr.ecr.us-east-1.localhost:5100/floci-it/app", # "imageTagMutability": "MUTABLE", # ... # } @@ -88,27 +88,27 @@ aws ecr create-repository \ # Authenticate stock docker against the emulated registry aws ecr get-login-password --endpoint-url $AWS_ENDPOINT \ | docker login --username AWS --password-stdin \ - 000000000000.dkr.ecr.us-east-1.localhost:5000 + 000000000000.dkr.ecr.us-east-1.localhost:5100 # Push an image docker pull alpine:3.19 docker tag alpine:3.19 \ - 000000000000.dkr.ecr.us-east-1.localhost:5000/floci-it/app:v1 -docker push 000000000000.dkr.ecr.us-east-1.localhost:5000/floci-it/app:v1 + 000000000000.dkr.ecr.us-east-1.localhost:5100/floci-it/app:v1 +docker push 000000000000.dkr.ecr.us-east-1.localhost:5100/floci-it/app:v1 # Inspect via the AWS CLI aws ecr list-images --repository-name floci-it/app --endpoint-url $AWS_ENDPOINT aws ecr describe-images --repository-name floci-it/app --endpoint-url $AWS_ENDPOINT # Pull from a clean local image store -docker rmi 000000000000.dkr.ecr.us-east-1.localhost:5000/floci-it/app:v1 -docker pull 000000000000.dkr.ecr.us-east-1.localhost:5000/floci-it/app:v1 +docker rmi 000000000000.dkr.ecr.us-east-1.localhost:5100/floci-it/app:v1 +docker pull 000000000000.dkr.ecr.us-east-1.localhost:5100/floci-it/app:v1 # Use the image as a Lambda function aws lambda create-function \ --function-name my-image-fn \ --package-type Image \ - --code ImageUri=000000000000.dkr.ecr.us-east-1.localhost:5000/floci-it/app:v1 \ + --code ImageUri=000000000000.dkr.ecr.us-east-1.localhost:5100/floci-it/app:v1 \ --role arn:aws:iam::000000000000:role/lambda-role \ --endpoint-url $AWS_ENDPOINT diff --git a/mkdocs.yml b/mkdocs.yml index 859e86e89d..f76d782f0a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -90,6 +90,7 @@ nav: - CloudWatch: services/cloudwatch.md - ACM: services/acm.md - ECS: services/ecs.md + - ECR: services/ecr.md - OpenSearch: services/opensearch.md - EC2: services/ec2.md - AppConfig: services/appconfig.md diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java index 290da08924..054b4e533a 100644 --- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java +++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java @@ -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") diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java index a8663b90bd..f2246fee34 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java @@ -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()); diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilter.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilter.java index 96a2d6ca57..15beee754b 100644 --- a/src/main/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilter.java +++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilter.java @@ -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; } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b83d75c81f..771e58346c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -141,8 +141,8 @@ floci: enabled: true registry-image: "registry:2" registry-container-name: floci-ecr-registry - registry-base-port: 5000 - registry-max-port: 5099 + registry-base-port: 5100 + registry-max-port: 5199 data-path: ./data/ecr tls-enabled: false keep-running-on-shutdown: true