mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ecr): advertise published host port when adopting registry container (#1715)
* fix(ecr): advertise published host port when adopting registry container When Floci runs inside Docker and adopts an already-running ECR registry container, adopt()'s endpoint resolves to the container IP and internal port 5000. That port was advertised in getRepositoryUri/getProxyEndpoint, but those URIs are consumed by the host-side Docker daemon, so docker login against the advertised endpoint failed. Read the published host binding when adopting and fall back to the configured port with a warning when no binding exists. * refactor(ecr): read published binding from adopt's existing inspect Applies the review suggestion: adopt() already inspects the container, so carry the published host bindings in ContainerInfo instead of re-inspecting via a separate publishedHostPort lookup. Removes the extra Docker round-trip on every adoption.
This commit is contained in:
1 parent
fb546d54c4
commit
6d1d892a19
3 files changed
+89
-5
No files matched your search
+36
@@ -9,10 +9,13 @@ import io.github.hectorvent.floci.core.common.docker.ContainerLogStreamer;
|
||||
import io.github.hectorvent.floci.core.common.docker.CurrentContainerNetworkResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerSpec;
|
||||
import io.github.hectorvent.floci.core.common.docker.PortAllocator;
|
||||
import com.github.dockerjava.api.model.Container;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -100,4 +103,37 @@ class EcrRegistryManagerTest {
|
||||
|
||||
assertEquals("http://" + REGISTRY_NAME + ":5000", manager.httpClient().baseUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adoptUsesPublishedHostPortEvenWhenRunningInsideDocker() {
|
||||
// Regression: in container mode adopt()'s endpoint resolves to the registry's
|
||||
// internal port (5000); the advertised proxy endpoint must use the published
|
||||
// host binding instead, or docker login from the host daemon fails.
|
||||
when(containerDetector.isRunningInContainer()).thenReturn(true);
|
||||
Container existing = Mockito.mock(Container.class);
|
||||
when(existing.getId()).thenReturn("0123456789abcdef");
|
||||
when(lifecycleManager.findByName(REGISTRY_NAME)).thenReturn(Optional.of(existing));
|
||||
when(lifecycleManager.adopt("0123456789abcdef", List.of(5000)))
|
||||
.thenReturn(new ContainerLifecycleManager.ContainerInfo("0123456789abcdef",
|
||||
Map.of(5000, new ContainerLifecycleManager.EndpointInfo("172.17.0.5", 5000)),
|
||||
Map.of(5000, BASE_PORT + 1)));
|
||||
|
||||
manager.ensureStarted();
|
||||
|
||||
assertEquals(BASE_PORT + 1, manager.effectivePort());
|
||||
assertEquals("http://localhost:" + (BASE_PORT + 1), manager.getProxyEndpoint());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adoptKeepsConfiguredPortWhenNoPublishedBindingExists() {
|
||||
Container existing = Mockito.mock(Container.class);
|
||||
when(existing.getId()).thenReturn("0123456789abcdef");
|
||||
when(lifecycleManager.findByName(REGISTRY_NAME)).thenReturn(Optional.of(existing));
|
||||
when(lifecycleManager.adopt("0123456789abcdef", List.of(5000)))
|
||||
.thenReturn(new ContainerLifecycleManager.ContainerInfo("0123456789abcdef", Map.of()));
|
||||
|
||||
manager.ensureStarted();
|
||||
|
||||
assertEquals(BASE_PORT, manager.effectivePort());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user