feat(ui): serve a landing page and launch the floci-ui console on demand (#1313)

* feat(ui): serve a landing page and launch the floci-ui console on demand

A browser hitting the Floci endpoint (GET / with Accept: text/html) now gets a
small embedded landing page; SDK/CLI traffic falls through to S3 ListBuckets
unchanged. The 'Open Floci UI' button hits /_floci/ui, which lazily starts the
floci-ui sidecar container, injects FLOCI_ENDPOINT so its API can reach Floci,
and serves an interstitial that polls /_floci/ui/status and redirects to the UI
once ready.

The sidecar is a single instance on one configured host port
(floci.services.ui.port, default 8080) and is adopted if already running. A
missing or unavailable image is reported as a friendly message instead of a 500.
Embedded ui/*.html is registered in quarkus.native.resources.includes so it is
present in the native image.

* feat(ui): branded landing dashboard, port 4500, reachable endpoint

Reskin the landing page to floci.io branding and surface live data from
/_floci/* (version, ready state, services grid). Publish the UI sidecar on a
fixed 4500 host+container port. Inject a self-discovered FLOCI_ENDPOINT via
DockerHostResolver so the UI reaches Floci over the Docker network instead of
hardcoded host.docker.internal logic; add FlociUiManagerTest.

* fix(s3): keep ListBuckets Content-Type as application/xml for non-HTML callers

The landing-page content negotiation listed text/html first in @Produces and
returned the ListBuckets XML without an explicit media type, so RESTEasy
negotiated Accept: */* (SDK/CLI default) to text/html and stamped that on the
response. Put application/xml first and pin the XML response type so non-browser
callers always receive application/xml; browser (Accept: text/html) callers
still get the landing page.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-06-15 20:10:13 -05:00
1 parent 647d941ed8
commit 2536b4ab86
13 files changed
+957 -6

No files matched your search

@@ -65,6 +65,7 @@ class EmulatorLifecycleTest {
@Mock private PipesService pipesService;
@Mock private Ec2MetadataServer ec2MetadataServer;
@Mock private EcrRegistryManager ecrRegistryManager;
@Mock private io.github.hectorvent.floci.services.ui.FlociUiManager flociUiManager;
@Mock private InitLifecycleState initLifecycleState;
@Mock private EmulatorConfig.TlsConfig tlsConfig;
@@ -83,7 +84,7 @@ class EmulatorLifecycleTest {
elastiCacheContainerManager, elastiCacheMemcachedContainerManager,
elastiCacheProxyManager, rdsContainerManager, rdsProxyManager, rdsService,
initializationHooksRunner, sqsPoller, kinesisPoller, dynamodbStreamsPoller,
pipesService, ec2MetadataServer, ecrRegistryManager, initLifecycleState);
pipesService, ec2MetadataServer, ecrRegistryManager, flociUiManager, initLifecycleState);
}
private void stubStorageConfig() {
@@ -0,0 +1,80 @@
package io.github.hectorvent.floci.services.ui;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
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.CurrentContainerNetworkResolver;
import io.github.hectorvent.floci.core.common.docker.DockerHostResolver;
import org.junit.jupiter.api.Test;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class FlociUiManagerTest {
private final ContainerDetector containerDetector = mock(ContainerDetector.class);
private final DockerHostResolver dockerHostResolver = mock(DockerHostResolver.class);
private final EmulatorConfig config = mock(EmulatorConfig.class);
private final EmulatorConfig.TlsConfig tls = mock(EmulatorConfig.TlsConfig.class);
private FlociUiManager newManager() {
return new FlociUiManager(
mock(ContainerBuilder.class),
mock(ContainerLifecycleManager.class),
mock(ContainerLogStreamer.class),
containerDetector,
mock(CurrentContainerNetworkResolver.class),
dockerHostResolver,
config,
mock(RegionResolver.class));
}
@Test
void containerizedUsesResolvedContainerIpNotHostDockerInternal() {
when(containerDetector.isRunningInContainer()).thenReturn(true);
when(config.hostname()).thenReturn(Optional.empty());
when(config.port()).thenReturn(4566);
when(config.tls()).thenReturn(tls);
when(tls.enabled()).thenReturn(false);
when(dockerHostResolver.resolve()).thenReturn("172.24.0.2");
assertEquals("http://172.24.0.2:4566", newManager().resolveFlociEndpoint());
}
@Test
void explicitHostnameWinsWhenContainerized() {
when(containerDetector.isRunningInContainer()).thenReturn(true);
when(config.hostname()).thenReturn(Optional.of("floci"));
when(config.effectiveBaseUrl()).thenReturn("http://floci:4566");
assertEquals("http://floci:4566", newManager().resolveFlociEndpoint());
}
@Test
void onHostFallsBackToHostDockerInternal() {
when(containerDetector.isRunningInContainer()).thenReturn(false);
when(config.port()).thenReturn(4566);
when(config.tls()).thenReturn(tls);
when(tls.enabled()).thenReturn(false);
when(dockerHostResolver.resolve()).thenReturn("host.docker.internal");
assertEquals("http://host.docker.internal:4566", newManager().resolveFlociEndpoint());
}
@Test
void usesHttpsSchemeWhenTlsEnabled() {
when(containerDetector.isRunningInContainer()).thenReturn(false);
when(config.port()).thenReturn(4566);
when(config.tls()).thenReturn(tls);
when(tls.enabled()).thenReturn(true);
when(dockerHostResolver.resolve()).thenReturn("host.docker.internal");
assertEquals("https://host.docker.internal:4566", newManager().resolveFlociEndpoint());
}
}
@@ -0,0 +1,64 @@
package io.github.hectorvent.floci.services.ui;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
/**
* Verifies the browser landing page content-negotiation on {@code /} and the
* {@code /_floci/ui/status} contract. These do not spawn the sidecar (only
* {@code GET /_floci/ui} does), so they need no Docker.
*/
@QuarkusTest
class UiLandingIntegrationTest {
@Test
void browserAcceptHtmlGetsLandingPage() {
given()
.accept("text/html")
.when()
.get("/")
.then()
.statusCode(200)
.contentType(containsString("text/html"))
.body(containsString("Floci"))
.body(containsString("Open Floci UI"));
}
@Test
void sdkClientStillGetsListBucketsXml() {
// No Accept: text/html — must fall through to S3 ListBuckets, unchanged.
given()
.accept("application/xml")
.when()
.get("/")
.then()
.statusCode(200)
.body(containsString("ListAllMyBucketsResult"));
}
@Test
void wildcardAcceptIsTreatedAsSdkNotBrowser() {
// RestAssured default Accept is */* — the strict text/html check must not match.
given()
.when()
.get("/")
.then()
.statusCode(200)
.body(containsString("ListAllMyBucketsResult"));
}
@Test
void statusEndpointReportsNotReadyBeforeStart() {
given()
.accept("application/json")
.when()
.get("/_floci/ui/status")
.then()
.statusCode(200)
.body("ready", is(false));
}
}