mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 15:49:33 -05:00
fix(core): give launched containers the port Floci listens on (#5754)
ContainerReachableEndpoint now picks the port a launched container can reach (quarkus.http.port, or floci.port under TLS), but three sites kept their own copy of the old logic: - FlociDuckClient built the sidecar's S3 endpoint from the floci.base-url port, which under -p 4811:4566 is a host-only port. It now calls ContainerReachableEndpoint.baseUrl(). - CodeBuildRunner set AWS_ENDPOINT_URL from floci.port. It now takes the port from ContainerReachableEndpoint.port(); hostname logic unchanged. - EmulatorLifecycle.onHttpStart compared the started server's port with floci.port (or a hardcoded 4510 under TLS), so start/ready hooks never ran with QUARKUS_HTTP_PORT overridden alone. It now compares against quarkus.http.port, which TlsConfigSource already pins to the TLS backend. The DuckDB-backed test profiles set quarkus.http.port alongside their test port, as SidecarContainersProfile does.
This commit is contained in:
1 parent
ae3ff3405a
commit
8362d0817d
9 files changed
+105
-47
No files matched your search
+7
-2
@@ -21,6 +21,7 @@ import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
* <li>{@code Ec2ContainerManager}, for the {@code AWS_ENDPOINT_URL} of EC2 instance containers</li>
|
||||
* <li>{@code CustomResourceCfnProvisioner}, for the {@code ResponseURL} a custom resource
|
||||
* Lambda PUTs its result to</li>
|
||||
* <li>{@code FlociDuckClient}, for the S3 endpoint the DuckDB sidecar calls</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Kubernetes pods do not use it: {@code KubernetesFlociAddressResolver} builds their endpoint
|
||||
@@ -56,10 +57,14 @@ public class ContainerReachableEndpoint {
|
||||
* listener is {@code TlsProxyServer} on {@code floci.port}.
|
||||
*/
|
||||
public String baseUrl() {
|
||||
int flociPort = config.tls().enabled() ? config.port() : httpPort;
|
||||
String flociHostname = embeddedDnsServer.getServerIp().isPresent()
|
||||
? config.hostname().orElse(EmbeddedDnsServer.DEFAULT_SUFFIX)
|
||||
: dockerHostResolver.resolve();
|
||||
return "http://" + flociHostname + ":" + flociPort;
|
||||
return "http://" + flociHostname + ":" + port();
|
||||
}
|
||||
|
||||
/** The port of {@link #baseUrl()}: the one a launched container can reach Floci on. */
|
||||
public int port() {
|
||||
return config.tls().enabled() ? config.port() : httpPort;
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,6 @@ import java.util.Optional;
|
||||
public class EmulatorLifecycle {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(EmulatorLifecycle.class);
|
||||
private static final int TLS_HTTP_BACKEND_PORT = 4510;
|
||||
|
||||
@ConfigProperty(name = "quarkus.application.version", defaultValue = "")
|
||||
Optional<String> appVersion = Optional.empty();
|
||||
@@ -74,6 +73,10 @@ public class EmulatorLifecycle {
|
||||
@ConfigProperty(name = "localstack.parity", defaultValue = "true")
|
||||
String localstackParity = "true";
|
||||
|
||||
/** The port Quarkus HTTP listens on; under TLS, TlsConfigSource pins it to the internal backend. */
|
||||
@ConfigProperty(name = "quarkus.http.port")
|
||||
int httpPort = 4566;
|
||||
|
||||
private final StorageFactory storageFactory;
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
private final EmulatorConfig config;
|
||||
@@ -298,12 +301,10 @@ public class EmulatorLifecycle {
|
||||
}
|
||||
|
||||
void onHttpStart(@ObservesAsync HttpServerStart event) {
|
||||
// Non-TLS: Quarkus listens on floci.port (quarkus.http.port: ${floci.port} in
|
||||
// application.yml). TLS mode: TlsConfigSource pins the HTTP backend to 4510 and the
|
||||
// public port is served by TlsProxyServer. Comparing against a hardcoded 4566 here
|
||||
// made start/ready hooks never run when FLOCI_PORT was non-default (#2437).
|
||||
int expectedPort = config.tls().enabled() ? TLS_HTTP_BACKEND_PORT : config.port();
|
||||
if (event.options().getPort() != expectedPort) {
|
||||
// Compare against quarkus.http.port, not floci.port: it can be overridden alone, and
|
||||
// under TLS it is the internal backend while TlsProxyServer serves floci.port. A
|
||||
// hardcoded 4566 here made start/ready hooks never run on a non-default port (#2437).
|
||||
if (event.options().getPort() != httpPort) {
|
||||
return;
|
||||
}
|
||||
boolean hasStart = initializationHooksRunner.hasHooks(InitializationHook.START);
|
||||
|
||||
@@ -13,6 +13,7 @@ import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLogStreamer;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerReachableEndpoint;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerSpec;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
|
||||
import io.github.hectorvent.floci.services.codebuild.BuildspecParser.ParsedArtifacts;
|
||||
@@ -73,6 +74,7 @@ public class CodeBuildRunner implements ContainerTeardown {
|
||||
private final EmulatorConfig config;
|
||||
private final ContainerDetector containerDetector;
|
||||
private final RegionResolver regionResolver;
|
||||
private final ContainerReachableEndpoint containerEndpoint;
|
||||
|
||||
private final ConcurrentHashMap<String, String> runningContainers = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, AtomicBoolean> stopFlags = new ConcurrentHashMap<>();
|
||||
@@ -87,7 +89,8 @@ public class CodeBuildRunner implements ContainerTeardown {
|
||||
SecretsManagerService secretsManagerService,
|
||||
EmulatorConfig config,
|
||||
ContainerDetector containerDetector,
|
||||
RegionResolver regionResolver) {
|
||||
RegionResolver regionResolver,
|
||||
ContainerReachableEndpoint containerEndpoint) {
|
||||
this.dockerClient = dockerClient;
|
||||
this.containerBuilder = containerBuilder;
|
||||
this.lifecycleManager = lifecycleManager;
|
||||
@@ -98,6 +101,7 @@ public class CodeBuildRunner implements ContainerTeardown {
|
||||
this.config = config;
|
||||
this.containerDetector = containerDetector;
|
||||
this.regionResolver = regionResolver;
|
||||
this.containerEndpoint = containerEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -485,12 +489,12 @@ public class CodeBuildRunner implements ContainerTeardown {
|
||||
return result;
|
||||
}
|
||||
|
||||
private String resolveEndpointUrl() {
|
||||
String resolveEndpointUrl() {
|
||||
if (containerDetector.isRunningInContainer()) {
|
||||
String suffix = config.hostname().orElse(EmbeddedDnsServer.DEFAULT_SUFFIX);
|
||||
return "http://" + suffix + ":" + config.port();
|
||||
return "http://" + suffix + ":" + containerEndpoint.port();
|
||||
} else {
|
||||
return "http://host.docker.internal:" + config.port();
|
||||
return "http://host.docker.internal:" + containerEndpoint.port();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ package io.github.hectorvent.floci.services.floci.duck;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
|
||||
import io.github.hectorvent.floci.core.common.docker.DockerHostResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerReachableEndpoint;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
@@ -29,21 +28,18 @@ public class FlociDuckClient {
|
||||
|
||||
private final FlociDuckManager duckManager;
|
||||
private final EmulatorConfig config;
|
||||
private final EmbeddedDnsServer embeddedDnsServer;
|
||||
private final DockerHostResolver dockerHostResolver;
|
||||
private final ContainerReachableEndpoint containerEndpoint;
|
||||
private final ObjectMapper mapper;
|
||||
private final HttpClient httpClient;
|
||||
|
||||
@Inject
|
||||
public FlociDuckClient(FlociDuckManager duckManager,
|
||||
EmulatorConfig config,
|
||||
EmbeddedDnsServer embeddedDnsServer,
|
||||
DockerHostResolver dockerHostResolver,
|
||||
ContainerReachableEndpoint containerEndpoint,
|
||||
ObjectMapper mapper) {
|
||||
this.duckManager = duckManager;
|
||||
this.config = config;
|
||||
this.embeddedDnsServer = embeddedDnsServer;
|
||||
this.dockerHostResolver = dockerHostResolver;
|
||||
this.containerEndpoint = containerEndpoint;
|
||||
this.mapper = mapper;
|
||||
this.httpClient = HttpClient.newHttpClient();
|
||||
}
|
||||
@@ -125,7 +121,7 @@ public class FlociDuckClient {
|
||||
if (setupDdl != null && !setupDdl.isBlank()) {
|
||||
body.put("setup_sql", setupDdl);
|
||||
}
|
||||
body.put("s3_endpoint", resolveFlociEndpoint());
|
||||
body.put("s3_endpoint", containerEndpoint.baseUrl());
|
||||
body.put("s3_region", config.defaultRegion());
|
||||
// A 12-digit access key flows through AccountResolver and selects the
|
||||
// matching account partition for any S3 read/write the SQL performs.
|
||||
@@ -136,19 +132,6 @@ public class FlociDuckClient {
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Floci S3 endpoint URL as reachable from inside a floci-duck container.
|
||||
* Uses the embedded DNS hostname when the DNS server is active, falls back to the
|
||||
* raw Docker host IP for local dev mode.
|
||||
*/
|
||||
private String resolveFlociEndpoint() {
|
||||
int port = URI.create(config.baseUrl()).getPort();
|
||||
String hostname = embeddedDnsServer.getServerIp().isPresent()
|
||||
? config.hostname().orElse(EmbeddedDnsServer.DEFAULT_SUFFIX)
|
||||
: dockerHostResolver.resolve();
|
||||
return "http://" + hostname + ":" + port;
|
||||
}
|
||||
|
||||
private String post(String url, Map<String, Object> body, String operation) {
|
||||
try {
|
||||
String json = mapper.writeValueAsString(body);
|
||||
|
||||
Reference in new issue
Block a user