fix(docker): launch an image in Floci's own ECR without the registry base (#8243)

With floci.docker.image-registry-base set, ContainerBuilder.resolveImage put
the base in front of every image, so an ECR image Floci had rewritten to its
loopback registry (localhost:<port>/<account>/<region>/<repo>), or a
repositoryUri it handed out, became <base>/localhost:<port>/...: a reference
Docker refuses, and no image a mirror holds. An ECS task, an image-backed
Lambda function or an EMR Serverless application with a custom image could not
run from Floci's ECR with the base set.

- An image in a registry on the Docker host's loopback (localhost, a
  .localhost name, Floci's localhost.floci.io alias or a loopback address in
  any spelling, checked with NetworkExposureGuard.isLoopback, with or without
  a port) is launched as it is; every other image still goes under the base.
- The setting's Javadoc, its environment variable row and the ECR page say so.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-13 22:28:27 -04:00
1 parent 3ae36eb7be
commit 3e02ff995f
5 files changed
+68 -4

No files matched your search

@@ -528,6 +528,41 @@ class ContainerBuilderTest {
assertEquals(imageId, fixture.builder.newContainer(imageId).build().image());
}
@ParameterizedTest
@ValueSource(strings = {
"localhost:4566/000000000000/us-east-1/spark/custom:7.5.0",
"000000000000.dkr.ecr.us-east-1.localhost:4566/spark/custom:7.5.0",
"000000000000.dkr.ecr.us-east-1.localhost.floci.io:4566/spark/custom:7.5.0",
"localhost.floci.io:4566/000000000000/us-east-1/spark/custom:7.5.0"})
void imageRegistryBaseLeavesAnImageInFlocisOwnEcrAlone(String image) {
TestFixture fixture = new TestFixture();
when(fixture.docker.imageRegistryBase()).thenReturn(Optional.of("ghcr.io/floci-io/mirror"));
assertEquals(image, fixture.builder.resolveImage(image));
assertEquals(image, fixture.builder.newContainer(image).build().image());
}
@ParameterizedTest
@ValueSource(strings = {"localhost/team/app:1", "LOCALHOST:5000/team/app:1", "registry.LOCALHOST:5000/team/app:1",
"127.0.0.1:5000/team/app:1",
"127.1.2.3:5000/team/app:1", "[::1]:5000/team/app:1", "[0:0:0:0:0:0:0:1]:5000/team/app:1"})
void imageRegistryBaseLeavesAnImageInAnotherLoopbackRegistryAlone(String image) {
TestFixture fixture = new TestFixture();
when(fixture.docker.imageRegistryBase()).thenReturn(Optional.of("ghcr.io/floci-io/mirror"));
assertEquals(image, fixture.builder.newContainer(image).build().image());
}
@ParameterizedTest
@ValueSource(strings = {"localhost:16", "team/localhost:16", "localhost.example.com/team/app:1",
"mylocalhost.example.com/team/app:1", "127.0.0.1.nip.io/team/app:1"})
void imageRegistryBasePrefixesAnImageOnlyNamedLikeALoopbackOne(String image) {
TestFixture fixture = new TestFixture();
when(fixture.docker.imageRegistryBase()).thenReturn(Optional.of("ghcr.io/floci-io/mirror"));
assertEquals("ghcr.io/floci-io/mirror/" + image, fixture.builder.newContainer(image).build().image());
}
private static class TestFixture {
final EmulatorConfig config = mock(EmulatorConfig.class);
final EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);