Light, fluffy, and always free - The AWS Local Emulator alternative
feat(ui): serve a landing page and launch the floci-ui console on demand (#1313)
Hector Ventura2536b4ab867f
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.javaindex 8ae11ba62f..5f25f33f3d 100644--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java@@ -379,6 +379,7 @@ public interface EmulatorConfig {CloudFrontServiceConfig cloudfront();AppSyncServiceConfig appsync();BatchServiceConfig batch();+ UiServiceConfig ui();}interface CloudTrailServiceConfig {@@ -886,6 +887,26 @@ public interface EmulatorConfig {String emitMode();}+ interface UiServiceConfig {+ @WithDefault("true")+ boolean enabled();++ @WithDefault("floci/floci-ui:latest")+ String image();++ @WithDefault("floci-ui")+ String containerName();++ /** Single fixed host port the UI is published on (single-instance service). */+ @WithDefault("4500")+ int port();++ @WithDefault("false")+ boolean keepRunningOnShutdown();++ Optional<String> dockerNetwork();+ }+interface EcrServiceConfig {@WithDefault("true")boolean enabled();diff --git a/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java b/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.javaindex e0f70b5ec6..44297fa53d 100644--- a/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java+++ b/src/main/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycle.java@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.lifecycle.inithook.InitializationHook;import io.github.hectorvent.floci.lifecycle.inithook.InitializationHooksRunner;import io.github.hectorvent.floci.services.ec2.Ec2MetadataServer;import io.github.hectorvent.floci.services.ecr.registry.EcrRegistryManager;+import io.github.hectorvent.floci.services.ui.FlociUiManager;import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerManager;import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheMemcachedContainerManager;import io.github.hectorvent.floci.services.elasticache.proxy.ElastiCacheProxyManager;@@ -66,6 +67,7 @@ public class EmulatorLifecycle {private final PipesService pipesService;private final Ec2MetadataServer ec2MetadataServer;private final EcrRegistryManager ecrRegistryManager;+ private final FlociUiManager flociUiManager;private final InitLifecycleState initLifecycleState;@Inject@@ -84,6 +86,7 @@ public class EmulatorLifecycle {PipesService pipesService,Ec2MetadataServer ec2MetadataServer,EcrRegistryManager ecrRegistryManager,+ FlociUiManager flociUiManager,InitLifecycleState initLifecycleState) {this.storageFactory = storageFactory;this.serviceRegistry = serviceRegistry;@@ -101,6 +104,7 @@ public class EmulatorLifecycle {this.pipesService = pipesService;this.ec2MetadataServer = ec2MetadataServer;this.ecrRegistryManager = ecrRegistryManager;+ this.flociUiManager = flociUiManager;this.initLifecycleState = initLifecycleState;}@@ -218,6 +222,7 @@ public class EmulatorLifecycle {elastiCacheMemcachedContainerManager.stopAll();rdsContainerManager.stopAll();ecrRegistryManager.shutdown();+ flociUiManager.shutdown();storageFactory.shutdownAll();LOG.info("=== AWS Local Emulator Stopped ===");diff --git a/src/main/java/io/github/hectorvent/floci/lifecycle/UiController.java b/src/main/java/io/github/hectorvent/floci/lifecycle/UiController.javanew file mode 100644index 0000000000..fcbc44bed1--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/lifecycle/UiController.java@@ -0,0 +1,68 @@+package io.github.hectorvent.floci.lifecycle;++import io.github.hectorvent.floci.services.ui.FlociUiManager;+import io.github.hectorvent.floci.services.ui.FlociUiManager.UiStatus;+import io.github.hectorvent.floci.services.ui.UiPages;+import jakarta.inject.Inject;+import jakarta.ws.rs.GET;+import jakarta.ws.rs.HeaderParam;+import jakarta.ws.rs.Path;+import jakarta.ws.rs.Produces;+import jakarta.ws.rs.core.MediaType;+import jakarta.ws.rs.core.Response;++/**+ * Browser-facing endpoints that launch and redirect to the floci-ui sidecar.+ *+ * <ul>+ * <li>{@code GET /_floci/ui} — kicks off the sidecar start (async) and returns a+ * small interstitial page that polls {@code /status} and redirects when ready.</li>+ * <li>{@code GET /_floci/ui/status} — JSON {@code {ready, url, error}} the+ * interstitial polls.</li>+ * </ul>+ */+@Path("{prefix:(_floci|_localstack)}/ui")+public class UiController {++ private final FlociUiManager uiManager;+ private final UiPages uiPages;++ @Inject+ public UiController(FlociUiManager uiManager, UiPages uiPages) {+ this.uiManager = uiManager;+ this.uiPages = uiPages;+ }++ @GET+ @Produces(MediaType.TEXT_HTML)+ public Response ui() {+ uiManager.ensureStartedAsync();+ return Response.ok(uiPages.startingHtml()).build();+ }++ public record StatusResponse(boolean ready, String url, String error) {}++ @GET+ @Path("/status")+ @Produces(MediaType.APPLICATION_JSON)+ public Response status(@HeaderParam("Host") String host) {+ UiStatus s = uiManager.status();+ if (s.error() != null) {+ return Response.ok(new StatusResponse(false, null, s.error())).build();+ }+ if (s.ready() && s.hostPort() > 0) {+ return Response.ok(new StatusResponse(true, redirectUrl(host, s.hostPort()), null)).build();+ }+ return Response.ok(new StatusResponse(false, null, null)).build();+ }++ /** Builds the browser-reachable UI URL from the request Host and the published port. */+ private static String redirectUrl(String host, int port) {+ String hostname = (host == null || host.isBlank()) ? "localhost" : host;+ int colon = hostname.indexOf(':');+ if (colon >= 0) {+ hostname = hostname.substring(0, colon);+ }+ return "http://" + hostname + ":" + port + "/";+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.javaindex ac6fb98b34..d339a0be67 100644--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java@@ -87,25 +87,35 @@ public class S3Controller {private final S3SelectService s3SelectService;private final RegionResolver regionResolver;private final io.quarkus.vertx.http.runtime.CurrentVertxRequest currentVertxRequest;+ private final io.github.hectorvent.floci.services.ui.UiPages uiPages;@Injectpublic S3Controller(S3Service s3Service, S3SelectService s3SelectService,RegionResolver regionResolver,- io.quarkus.vertx.http.runtime.CurrentVertxRequest currentVertxRequest) {+ io.quarkus.vertx.http.runtime.CurrentVertxRequest currentVertxRequest,+ io.github.hectorvent.floci.services.ui.UiPages uiPages) {this.s3Service = s3Service;this.s3SelectService = s3SelectService;this.regionResolver = regionResolver;this.currentVertxRequest = currentVertxRequest;+ this.uiPages = uiPages;}// --- Bucket operations ---@GET- @Produces(MediaType.APPLICATION_XML)- public Response listBuckets(@HeaderParam("X-Amz-Target") String target) {+ @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_HTML})+ public Response listBuckets(@HeaderParam("X-Amz-Target") String target,+ @HeaderParam("Accept") String accept) {if (target != null) {return null;}+ // A browser hitting the root endpoint (Accept: text/html) gets the Floci+ // landing page; SDK/CLI callers (no Accept, */*, or an XML/JSON Accept) fall+ // through to the normal S3 ListBuckets behavior untouched.+ if (accept != null && accept.contains(MediaType.TEXT_HTML)) {+ return Response.ok(uiPages.landingHtml(), MediaType.TEXT_HTML).build();+ }try {List<Bucket> buckets = s3Service.listBuckets();XmlBuilder xml = new XmlBuilder()@@ -123,7 +133,7 @@ public class S3Controller {.end("Bucket");}xml.end("Buckets").end("ListAllMyBucketsResult");- return Response.ok(xml.build()).build();+ return Response.ok(xml.build()).type(MediaType.APPLICATION_XML).build();} catch (AwsException e) {return xmlErrorResponse(e);}diff --git a/src/main/java/io/github/hectorvent/floci/services/ui/FlociUiManager.java b/src/main/java/io/github/hectorvent/floci/services/ui/FlociUiManager.javanew file mode 100644index 0000000000..beabc39166--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/ui/FlociUiManager.java@@ -0,0 +1,271 @@+package io.github.hectorvent.floci.services.ui;++import java.io.Closeable;+import java.net.HttpURLConnection;+import java.net.URI;+import java.util.ArrayList;+import java.util.List;+import java.util.Optional;+import java.util.concurrent.ExecutorService;+import java.util.concurrent.Executors;+import java.util.concurrent.atomic.AtomicBoolean;++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.ContainerLifecycleManager.ContainerInfo;+import io.github.hectorvent.floci.core.common.docker.ContainerLogStreamer;+import io.github.hectorvent.floci.core.common.docker.ContainerSpec;+import io.github.hectorvent.floci.core.common.docker.CurrentContainerNetworkResolver;+import io.github.hectorvent.floci.core.common.docker.DockerHostResolver;+import com.github.dockerjava.api.model.Container;+import jakarta.enterprise.context.ApplicationScoped;+import jakarta.inject.Inject;+import org.jboss.logging.Logger;++/**+ * Manages the lifecycle of the {@code floci/floci-ui} sidecar container — the+ * browser-facing Floci web console. The container is started lazily on the first+ * {@code /_floci/ui} hit and reused across restarts (one per Floci instance).+ *+ * <p>Unlike other sidecars, a failed start (typically a missing/unavailable image)+ * is <em>not</em> fatal: it is recorded in {@link #status()} so the interstitial+ * page can show a friendly message instead of a 500.+ */+@ApplicationScoped+public class FlociUiManager {++ private static final Logger LOG = Logger.getLogger(FlociUiManager.class);+ private static final int CONTAINER_INTERNAL_PORT = 4500;++ private final ContainerBuilder containerBuilder;+ private final ContainerLifecycleManager lifecycleManager;+ private final ContainerLogStreamer logStreamer;+ private final ContainerDetector containerDetector;+ private final CurrentContainerNetworkResolver currentContainerNetworkResolver;+ private final DockerHostResolver dockerHostResolver;+ private final EmulatorConfig config;+ private final RegionResolver regionResolver;++ private volatile boolean started;+ private volatile int hostPort;+ private volatile String containerId;+ private volatile Closeable logStream;+ private volatile String lastError;++ private final ExecutorService starter = Executors.newSingleThreadExecutor(r -> {+ Thread t = new Thread(r, "floci-ui-starter");+ t.setDaemon(true);+ return t;+ });+ private final AtomicBoolean kicked = new AtomicBoolean(false);++ @Inject+ public FlociUiManager(ContainerBuilder containerBuilder,+ ContainerLifecycleManager lifecycleManager,+ ContainerLogStreamer logStreamer,+ ContainerDetector containerDetector,+ CurrentContainerNetworkResolver currentContainerNetworkResolver,+ DockerHostResolver dockerHostResolver,+ EmulatorConfig config,+ RegionResolver regionResolver) {+ this.containerBuilder = containerBuilder;+ this.lifecycleManager = lifecycleManager;+ this.logStreamer = logStreamer;+ this.containerDetector = containerDetector;+ this.currentContainerNetworkResolver = currentContainerNetworkResolver;+ this.dockerHostResolver = dockerHostResolver;+ this.config = config;+ this.regionResolver = regionResolver;+ }++ /** Snapshot of the sidecar state for the interstitial page. */+ public record UiStatus(boolean started, boolean ready, int hostPort, String error) {}++ /**+ * Lazily starts (or adopts) the floci-ui container. Idempotent and thread-safe.+ * Does not throw on a failed start — the failure is captured for {@link #status()}.+ */+ public synchronized void ensureStarted() {+ if (started) {+ return;+ }+ if (!config.services().ui().enabled()) {+ this.lastError = "The Floci UI is disabled (set floci.services.ui.enabled=true to enable it).";+ return;+ }+ // Clear any error from a prior failed attempt so status() reports this retry+ // as in-progress rather than surfacing the stale failure.+ this.lastError = null;+ String name = config.services().ui().containerName();++ Optional<Container> existing = lifecycleManager.findByName(name);+ if (existing.isPresent()) {+ adoptExisting(existing.get());+ return;+ }++ String image = config.services().ui().image();+ int chosenPort = config.services().ui().port();+ try {+ ContainerBuilder.Builder specBuilder = containerBuilder.newContainer(image)+ .withName(name)+ .withEnv(injectedEnv())+ .withPortBinding(CONTAINER_INTERNAL_PORT, chosenPort)+ .withDockerNetwork(resolveDockerNetwork())+ .withLogRotation();+ if (!containerDetector.isRunningInContainer()) {+ specBuilder.withHostDockerInternalOnLinux();+ }++ ContainerSpec spec = specBuilder.build();+ ContainerInfo info = lifecycleManager.createAndStart(spec);+ this.containerId = info.containerId();+ this.hostPort = chosenPort;+ this.started = true;+ this.lastError = null;+ LOG.infov("Started floci-ui sidecar {0} on host port {1}", name, String.valueOf(chosenPort));+ attachLogStream();+ } catch (Exception e) {+ this.lastError = "Could not start the Floci UI from image '" + image + "': " + e.getMessage()+ + ". Ensure the image is available (docker pull " + image+ + ", or build it from the floci-ui repo).";+ LOG.errorv(e, "Failed to start floci-ui sidecar from image {0}", image);+ }+ }++ /**+ * Triggers {@link #ensureStarted()} on a background thread and returns immediately,+ * so the caller can serve the interstitial page while the (possibly slow) image+ * pull and boot happen. De-duplicated; re-armed after a failed start so the user+ * can fix the image and retry.+ */+ public void ensureStartedAsync() {+ if (started) {+ return;+ }+ if (kicked.compareAndSet(false, true)) {+ starter.submit(() -> {+ try {+ ensureStarted();+ } finally {+ if (!started) {+ kicked.set(false);+ }+ }+ });+ }+ }++ /** Current state, including a probe of whether the UI is accepting connections. */+ public UiStatus status() {+ if (lastError != null) {+ return new UiStatus(started, false, hostPort, lastError);+ }+ boolean ready = started && probeReady();+ return new UiStatus(started, ready, hostPort, null);+ }++ /** Host port the UI is published on. Valid once {@link #ensureStarted()} succeeds. */+ public int hostPort() {+ return hostPort;+ }++ /** Stops the container unless {@code keep-running-on-shutdown=true}. */+ public void shutdown() {+ if (!started || containerId == null) {+ return;+ }+ if (config.services().ui().keepRunningOnShutdown()) {+ LOG.infov("Leaving floci-ui sidecar {0} running for next start-up", containerId);+ return;+ }+ lifecycleManager.stopAndRemove(containerId, logStream);+ }++ private List<String> injectedEnv() {+ List<String> env = new ArrayList<>();+ env.add("FLOCI_ENDPOINT=" + resolveFlociEndpoint());+ env.add("AWS_REGION=" + regionResolver.getDefaultRegion());+ env.add("AWS_ACCESS_KEY_ID=test");+ env.add("AWS_SECRET_ACCESS_KEY=test");+ env.add("PORT=" + CONTAINER_INTERNAL_PORT);+ return env;+ }++ /**+ * The endpoint the UI's API server uses to reach Floci from inside its container.+ *+ * <p>Reuses {@link DockerHostResolver}, the same mechanism Lambda and CodeBuild use:+ * when Floci runs in a container the sibling UI reaches it directly by Floci's own+ * container IP over the shared Docker network (no {@code host.docker.internal}, no+ * manual {@code FLOCI_HOSTNAME}); when Floci runs on the host the only path from a+ * container is the host gateway ({@code host.docker.internal}). An explicitly+ * configured {@code FLOCI_HOSTNAME} still wins so name-based compose setups keep+ * working.+ */+ String resolveFlociEndpoint() {+ if (containerDetector.isRunningInContainer() && config.hostname().isPresent()) {+ return config.effectiveBaseUrl();+ }+ String scheme = config.tls().enabled() ? "https" : "http";+ return scheme + "://" + dockerHostResolver.resolve() + ":" + config.port();+ }++ private Optional<String> resolveDockerNetwork() {+ Optional<String> configured = config.services().ui().dockerNetwork();+ if (configured.isPresent() && !configured.get().isBlank()) {+ return configured;+ }+ if (containerDetector.isRunningInContainer()) {+ return currentContainerNetworkResolver.resolveNetworkName();+ }+ return Optional.empty();+ }++ private boolean probeReady() {+ String url = containerDetector.isRunningInContainer()+ ? "http://" + config.services().ui().containerName() + ":" + CONTAINER_INTERNAL_PORT + "/"+ : "http://localhost:" + hostPort + "/";+ try {+ HttpURLConnection conn = (HttpURLConnection) URI.create(url).toURL().openConnection();+ conn.setConnectTimeout(800);+ conn.setReadTimeout(800);+ conn.setRequestMethod("GET");+ int code = conn.getResponseCode();+ conn.disconnect();+ return code > 0;+ } catch (Exception e) {+ return false;+ }+ }++ private void adoptExisting(Container existing) {+ this.containerId = existing.getId();+ try {+ ContainerInfo info = lifecycleManager.adopt(containerId, List.of(CONTAINER_INTERNAL_PORT));+ var endpoint = info.getEndpoint(CONTAINER_INTERNAL_PORT);+ if (endpoint != null) {+ this.hostPort = endpoint.port();+ }+ this.started = true;+ this.lastError = null;+ LOG.infov("Adopted existing floci-ui sidecar {0} on host port {1}",+ containerId, String.valueOf(hostPort));+ attachLogStream();+ } catch (Exception e) {+ LOG.warnv("Failed to adopt existing floci-ui sidecar: {0}", e.getMessage());+ this.containerId = null;+ }+ }++ private void attachLogStream() {+ String shortId = containerId.length() >= 8 ? containerId.substring(0, 8) : containerId;+ String logGroup = "/floci/ui";+ String logStreamName = logStreamer.generateLogStreamName(shortId);+ String region = regionResolver.getDefaultRegion();+ this.logStream = logStreamer.attach(containerId, logGroup, logStreamName, region, "floci:ui");+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/ui/UiPages.java b/src/main/java/io/github/hectorvent/floci/services/ui/UiPages.javanew file mode 100644index 0000000000..cb5c1488b1--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/ui/UiPages.java@@ -0,0 +1,54 @@+package io.github.hectorvent.floci.services.ui;++import java.io.IOException;+import java.io.InputStream;+import java.nio.charset.StandardCharsets;++import jakarta.enterprise.context.ApplicationScoped;++/**+ * Loads and caches the small embedded HTML pages served to browsers: the Floci+ * landing page and the "starting the UI" interstitial. Resources are read from+ * the classpath ({@code ui/*.html}) and must be registered in+ * {@code quarkus.native.resources.includes} so they are embedded in the native+ * image.+ */+@ApplicationScoped+public class UiPages {++ private static final String LANDING_RESOURCE = "ui/index.html";+ private static final String STARTING_RESOURCE = "ui/starting.html";++ private volatile String landing;+ private volatile String starting;++ public String landingHtml() {+ String result = landing;+ if (result == null) {+ result = readResource(LANDING_RESOURCE);+ landing = result;+ }+ return result;+ }++ public String startingHtml() {+ String result = starting;+ if (result == null) {+ result = readResource(STARTING_RESOURCE);+ starting = result;+ }+ return result;+ }++ private static String readResource(String resourceName) {+ ClassLoader loader = UiPages.class.getClassLoader();+ try (InputStream input = loader.getResourceAsStream(resourceName)) {+ if (input == null) {+ throw new IllegalStateException("Missing UI resource: " + resourceName);+ }+ return new String(input.readAllBytes(), StandardCharsets.UTF_8);+ } catch (IOException e) {+ throw new IllegalStateException("Failed to load UI resource: " + resourceName, e);+ }+ }+}diff --git a/src/main/resources/application.yml b/src/main/resources/application.ymlindex 619e0b027a..bbf36f6826 100644--- a/src/main/resources/application.yml+++ b/src/main/resources/application.yml@@ -24,7 +24,7 @@ quarkus:# ClassLoader#getResourceAsStream. Quarkus's static resource analysis# cannot detect these dynamically-built paths, so they are registered# explicitly to ensure GraalVM includes every file in the native image.- includes: pricing-snapshots/**,ec2/*.yaml+ includes: pricing-snapshots/**,ui/*.html,ec2/*.yamladditional-build-args:- --report-unsupported-elements-at-runtime- --allow-incomplete-classpath@@ -275,6 +275,12 @@ floci:tls-enabled: falsekeep-running-on-shutdown: trueuri-style: hostname+ ui:+ enabled: true+ image: "floci/floci-ui:latest"+ container-name: floci-ui+ port: 4500+ keep-running-on-shutdown: falsebedrock-runtime:enabled: trueeks:diff --git a/src/main/resources/ui/index.html b/src/main/resources/ui/index.htmlnew file mode 100644index 0000000000..c40209e9f4--- /dev/null+++ b/src/main/resources/ui/index.html@@ -0,0 +1,289 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="utf-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1" />+ <title>Floci — local AWS emulator</title>+ <link rel="preconnect" href="https://fonts.googleapis.com">+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>+ <link href="https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Sora:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">+ <style>+ :root {+ color-scheme: dark;+ --bg: #070B14;+ --bg2: #161E2E;+ --bg3: #0F1520;+ --border: #2A3142;+ --border-bright: #3D4559;+ --text: #F8FAFC;+ --text-muted: #94A3B8;+ --text-dim: #64748B;+ --accent: #7A7FD6;+ --accent-deep: #5559A7;+ --accent-mid: #6368C2;+ --accent-dim: rgba(85,89,167,.12);+ --green: #22c55e;+ --sans: "Sora", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;+ --mono: "Space Mono", ui-monospace, SFMono-Regular, Menlo, monospace;+ }+ * { box-sizing: border-box; }+ body {+ margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center;+ font-family: var(--sans);+ background:+ radial-gradient(900px 480px at 50% -12%, rgba(122,127,214,0.18) 0%, rgba(85,89,167,0.06) 38%, transparent 70%),+ var(--bg);+ color: var(--text);+ -webkit-font-smoothing: antialiased;+ }+ .card {+ width: min(640px, 92vw); padding: 44px 46px; border-radius: 20px;+ background: linear-gradient(180deg, var(--bg2), var(--bg3));+ border: 1px solid var(--border);+ box-shadow: 0 30px 90px rgba(0,0,0,0.55);+ }+ .logo-wrap { display: flex; align-items: center; gap: 14px; margin: 0 0 10px; }+ .floci-logo { height: 40px; width: auto; display: block; }+ .floci-text { fill: var(--text); }+ .floci-cloud { fill: var(--text); }+ .floci-dot { fill: var(--accent); }+ .status {+ display: inline-flex; align-items: center; gap: 8px; margin-left: auto;+ font-family: var(--mono); font-size: 12px; color: var(--text-muted);+ padding: 5px 11px; border-radius: 999px;+ background: var(--bg3); border: 1px solid var(--border);+ }+ .status .dot {+ width: 9px; height: 9px; border-radius: 50%; flex: none;+ background: var(--text-dim); box-shadow: 0 0 0 0 transparent;+ transition: background .2s ease, box-shadow .2s ease;+ }+ .status.ready .dot { background: var(--green); box-shadow: 0 0 0 4px rgba(34,197,94,0.18); }+ .status.starting .dot { background: #e0b341; box-shadow: 0 0 0 4px rgba(224,179,65,0.18); }+ .status.offline .dot { background: var(--text-dim); }+ .tag {+ margin: 0 0 26px; color: var(--text-muted); font-size: 15px; font-weight: 400;+ }+ p { line-height: 1.65; color: #c4cde0; font-size: 15px; }+ .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; margin: 24px 0 30px; }+ .grid div { font-size: 13px; color: var(--text-muted); }+ .grid b { color: var(--text); font-weight: 600; letter-spacing: -0.01em; }+ .svc { margin: 0 0 28px; }+ .svc-head {+ display: flex; align-items: baseline; gap: 12px; margin: 0 0 12px;+ }+ .svc-head h2 {+ margin: 0; font-size: 13px; font-weight: 600; letter-spacing: 0.04em;+ text-transform: uppercase; color: var(--text-muted);+ }+ .svc-count { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }+ .svc-count b { color: var(--green); font-weight: 700; }+ .svc-search {+ width: 100%; margin: 0 0 12px; padding: 9px 13px; border-radius: 10px;+ background: var(--bg); border: 1px solid var(--border); color: var(--text);+ font-family: var(--mono); font-size: 12.5px; outline: none;+ transition: border-color .15s ease, box-shadow .15s ease;+ }+ .svc-search::placeholder { color: var(--text-dim); }+ .svc-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }+ .svc-list {+ display: grid; grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 7px;+ max-height: 188px; overflow-y: auto; padding: 4px;+ border: 1px solid var(--border); border-radius: 12px; background: var(--bg3);+ }+ .svc-list::-webkit-scrollbar { width: 9px; }+ .svc-list::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 9px; border: 2px solid var(--bg3); }+ .badge {+ display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 9px;+ font-family: var(--mono); font-size: 12px; color: var(--text-muted);+ background: var(--bg2); border: 1px solid transparent;+ }+ .badge .b-dot {+ width: 8px; height: 8px; border-radius: 50%; flex: none;+ border: 1.5px solid var(--text-dim); background: transparent;+ }+ .badge.running { color: var(--text); border-color: rgba(122,127,214,0.28); background: var(--accent-dim); }+ .badge.running .b-dot { background: var(--accent); border-color: var(--accent); }+ .badge .b-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }+ .svc-empty { padding: 16px; font-family: var(--mono); font-size: 12px; color: var(--text-dim); text-align: center; }+ code {+ font-family: var(--mono);+ background: var(--accent-dim); color: #cfd3f5;+ padding: 2px 7px; border-radius: 6px; font-size: 12.5px;+ border: 1px solid rgba(122,127,214,0.18);+ }+ .btn {+ display: inline-flex; align-items: center; gap: 9px; text-decoration: none;+ background: linear-gradient(180deg, var(--accent), var(--accent-deep)); color: #fff;+ font-family: var(--sans); font-weight: 600; font-size: 15px;+ padding: 13px 22px; border-radius: 12px; border: 1px solid rgba(122,127,214,0.35);+ transition: transform .08s ease, box-shadow .15s ease;+ box-shadow: 0 8px 26px rgba(85,89,167,0.45);+ }+ .btn:hover { transform: translateY(-1px); box-shadow: 0 12px 32px rgba(85,89,167,0.6); }+ .foot { margin-top: 24px; font-size: 12px; color: var(--text-dim); font-family: var(--mono); }+ .foot a { color: var(--accent); text-decoration: none; }+ .foot a:hover { color: #9aa0e6; }+ </style>+</head>+<body>+ <main class="card">+ <div class="logo-wrap">+ <svg class="floci-logo" viewBox="0 0 531.25 156.71" xmlns="http://www.w3.org/2000/svg" aria-label="floci" role="img">+ <g style="isolation:isolate"><g style="isolation:isolate">+ <path class="floci-text" d="M305.44,141.35h-15.94V39.04h-17.08c-13.18,0-16.75,7.81-16.59,17.4v8.95h17.4v13.34h-17.4v62.62h-15.94v-62.62h-14.64v-13.34h14.64v-7.16c0-20.66,8.95-34.16,29.6-34.16h35.95v117.28Z"></path>+ <path class="floci-text" d="M324.31,103.29c0-24.07,18.22-39.85,39.85-39.85s40.01,15.78,40.01,39.85-18.38,40.01-40.01,40.01-39.85-15.94-39.85-40.01ZM388.24,103.29c0-14.64-11.06-24.89-24.07-24.89s-23.91,10.25-23.91,24.89,10.9,25.05,23.91,25.05,24.07-10.25,24.07-25.05Z"></path>+ <path class="floci-text" d="M418,103.29c0-24.07,19.03-39.85,40.99-39.85,12.36,0,22.93,5.04,29.6,13.01l-10.57,9.92c-4.39-4.88-11.06-7.97-18.71-7.97-14.15,0-25.38,10.41-25.38,24.89s11.22,25.05,25.38,25.05c7.65,0,14.31-3.09,18.71-7.97l10.57,9.92c-6.67,7.97-17.24,13.01-29.6,13.01-21.96,0-40.99-15.94-40.99-40.01Z"></path>+ <path class="floci-text" d="M502.91,37.74c0-5.86,5.04-10.25,10.9-10.25s10.9,4.39,10.9,10.25-4.88,10.25-10.9,10.25-10.9-4.39-10.9-10.25ZM505.84,141.35v-75.96h15.94v75.96h-15.94Z"></path>+ </g></g>+ <g>+ <path class="floci-cloud" d="M44.46,52.16l-1.44,9.05c-.1.64-35.57,8.08-30.51,43.05,2.04,14.08,14.69,31.06,31.94,31.22l84.34.78c3.64.03,7.49.5,9.97,2.81,1.69,1.57,1.95,6.1-.29,9.22l-83.49.43c-22.68.12-43.45-11.19-51.76-32.9-8.64-22.56.61-49.48,22.58-59.54,5.11-2.34,7.7-4,8.39-9.37l10.28,5.24h-.01Z"></path>+ <path class="floci-cloud" d="M44.46,52.16l-10.28-5.24c1.94-15.09,10.61-28.25,23.15-36.38C74.85-.82,94.57-3.69,115.01,5.35c14.93,6.6,26.96,21.97,32.12,39.33,26.07,3.63,46.19,26.18,40.75,53.8-3.06.86-9.18-1.15-11.34-3.72,1.28-12.11-3.1-22.27-10.75-29.43-8.19-7.67-17.88-9.28-30.09-8.04-.09-25.91-19.81-43.97-43.82-45.33-22.91-1.29-43.59,16.13-47.42,40.2h0Z"></path>+ <ellipse class="floci-dot" cx="173.57" cy="127.13" rx="20.36" ry="20.4"></ellipse>+ <ellipse class="floci-dot" cx="513.02" cy="37.71" rx="13.22" ry="13.25"></ellipse>+ </g>+ </svg>+ <span class="status offline" id="status" title="Emulator status">+ <span class="dot"></span><span id="status-label">connecting…</span>+ </span>+ </div>+ <p class="tag">Any cloud. Locally. — a local AWS emulator speaking real AWS wire protocols.</p>+ <p>You've reached the Floci endpoint. Point your AWS SDK or CLI here with+ <code>--endpoint-url http://localhost:4566</code> and it behaves like AWS.</p>+ <div class="grid">+ <div><b>Endpoint</b><br>http://localhost:4566</div>+ <div><b>Region</b><br>us-east-1 (default)</div>+ <div><b>Account</b><br>000000000000</div>+ <div><b>Version</b><br><span id="version">…</span></div>+ </div>+ <section class="svc">+ <div class="svc-head">+ <h2>Services</h2>+ <span class="svc-count" id="svc-count"><b>—</b> running · — available</span>+ </div>+ <input class="svc-search" id="svc-search" type="text" placeholder="filter services…"+ autocomplete="off" autocapitalize="off" spellcheck="false" disabled />+ <div class="svc-list" id="svc-list">+ <div class="svc-empty">Loading services…</div>+ </div>+ </section>+ <a class="btn" href="/_floci/ui">+ Open Floci UI →+ </a>+ <p class="foot">The UI launches on demand as a sidecar container the first time you open it.+ · <a href="/_floci/health">health</a> · <a href="/_floci/info">info</a></p>+ </main>++ <script>+ (function () {+ var statusEl = document.getElementById("status");+ var statusLabel = document.getElementById("status-label");+ var versionEl = document.getElementById("version");+ var countEl = document.getElementById("svc-count");+ var listEl = document.getElementById("svc-list");+ var searchEl = document.getElementById("svc-search");++ var services = []; // [{ name, running }]+ var filter = "";++ function setStatus(state, label) {+ statusEl.className = "status " + state;+ statusLabel.textContent = label;+ }++ function renderCount() {+ var running = services.filter(function (s) { return s.running; }).length;+ var available = services.length - running;+ countEl.innerHTML = "<b>" + running + "</b> running · " + available + " available";+ }++ function renderList() {+ var q = filter.trim().toLowerCase();+ var shown = services.filter(function (s) { return !q || s.name.toLowerCase().indexOf(q) !== -1; });+ if (!services.length) {+ listEl.innerHTML = '<div class="svc-empty">No services reported.</div>';+ return;+ }+ if (!shown.length) {+ listEl.innerHTML = '<div class="svc-empty">No services match "' + escapeHtml(q) + '".</div>';+ return;+ }+ listEl.innerHTML = shown.map(function (s) {+ return '<span class="badge ' + (s.running ? "running" : "") + '" title="' ++ escapeHtml(s.name) + " — " + (s.running ? "running" : "available") + '">' ++ '<span class="b-dot"></span><span class="b-name">' + escapeHtml(s.name) + "</span></span>";+ }).join("");+ }++ function escapeHtml(str) {+ return String(str).replace(/[&<>"]/g, function (c) {+ return { "&": "&", "<": "<", ">": ">", '"': """ }[c];+ });+ }++ function sortServices(map) {+ return Object.keys(map).map(function (name) {+ return { name: name, running: map[name] === "running" };+ }).sort(function (a, b) {+ if (a.running !== b.running) { return a.running ? -1 : 1; }+ return a.name.localeCompare(b.name);+ });+ }++ function getJson(path) {+ return fetch(path, { headers: { Accept: "application/json" } }).then(function (r) {+ if (!r.ok) { throw new Error(path + " -> " + r.status); }+ return r.json();+ });+ }++ var refreshing = false;+ function refresh() {+ if (refreshing) { return; }+ refreshing = true;+ Promise.allSettled([getJson("/_floci/health"), getJson("/_floci/init")])+ .then(function (results) {+ var health = results[0].status === "fulfilled" ? results[0].value : null;+ var init = results[1].status === "fulfilled" ? results[1].value : null;++ if (!health) {+ setStatus("offline", "offline");+ if (!services.length) {+ listEl.innerHTML = '<div class="svc-empty">Couldn\'t reach Floci. Retrying…</div>';+ }+ return;+ }++ if (health.version) { versionEl.textContent = health.version; }+ if (health.edition) {+ versionEl.textContent = (health.version || "—") + " · " + health.edition;+ }++ services = sortServices(health.services || {});+ renderCount();+ renderList();+ if (searchEl.disabled) { searchEl.disabled = false; }++ var completed = (init && init.completed) || {};+ if (completed.ready || completed.start) {+ setStatus("ready", "ready");+ } else if (completed.boot) {+ setStatus("starting", "starting…");+ } else {+ setStatus("ready", "online");+ }+ })+ .finally(function () { refreshing = false; });+ }++ searchEl.addEventListener("input", function () {+ filter = searchEl.value;+ renderList();+ });++ refresh();+ setInterval(refresh, 5000);+ })();+ </script>+</body>+</html>diff --git a/src/main/resources/ui/starting.html b/src/main/resources/ui/starting.htmlnew file mode 100644index 0000000000..aeda6e5a10--- /dev/null+++ b/src/main/resources/ui/starting.html@@ -0,0 +1,80 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="utf-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1" />+ <title>Starting Floci UI…</title>+ <style>+ :root { color-scheme: dark; }+ body {+ margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center;+ font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;+ background: radial-gradient(1200px 600px at 50% -10%, #1b2a4a 0%, #0b1020 60%, #070a14 100%);+ color: #e6ebf5;+ }+ .card {+ width: min(480px, 92vw); padding: 40px 44px; border-radius: 18px; text-align: center;+ background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);+ box-shadow: 0 30px 80px rgba(0,0,0,0.45);+ }+ h1 { font-size: 22px; margin: 0 0 8px; font-weight: 700; letter-spacing: -0.02em; }+ p { color: #9aa6bd; font-size: 14px; line-height: 1.6; margin: 0; }+ .spinner {+ width: 46px; height: 46px; margin: 6px auto 22px; border-radius: 50%;+ border: 4px solid rgba(255,255,255,0.12); border-top-color: #5b9dff;+ animation: spin 0.9s linear infinite;+ }+ @keyframes spin { to { transform: rotate(360deg); } }+ .err { color: #ff9a9a; }+ code { background: rgba(255,255,255,0.07); padding: 2px 7px; border-radius: 6px; font-size: 13px; }+ </style>+</head>+<body>+ <main class="card">+ <div class="spinner" id="spinner"></div>+ <h1 id="title">Starting Floci UI…</h1>+ <p id="msg">Launching the UI container. This can take a moment the first time while the image is pulled.</p>+ </main>+ <script>+ (function () {+ var title = document.getElementById('title');+ var msg = document.getElementById('msg');+ var spinner = document.getElementById('spinner');+ var attempts = 0;++ function fail(text) {+ spinner.style.display = 'none';+ title.textContent = 'Floci UI unavailable';+ title.className = 'err';+ msg.innerHTML = text;+ }++ function poll() {+ attempts++;+ fetch('/_floci/ui/status', { headers: { 'Accept': 'application/json' } })+ .then(function (r) { return r.json(); })+ .then(function (s) {+ if (s.ready && s.url) {+ window.location.replace(s.url);+ return;+ }+ if (s.error) {+ fail(s.error);+ return;+ }+ if (attempts > 150) { // ~5 min at 2s+ fail('Timed out waiting for the UI to become ready.');+ return;+ }+ setTimeout(poll, 2000);+ })+ .catch(function () {+ if (attempts > 150) { fail('Could not reach Floci.'); return; }+ setTimeout(poll, 2000);+ });+ }+ poll();+ })();+ </script>+</body>+</html>diff --git a/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycleTest.java b/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycleTest.javaindex 20cfd4d839..51d2c60774 100644--- a/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycleTest.java+++ b/src/test/java/io/github/hectorvent/floci/lifecycle/EmulatorLifecycleTest.java@@ -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() {diff --git a/src/test/java/io/github/hectorvent/floci/services/ui/FlociUiManagerTest.java b/src/test/java/io/github/hectorvent/floci/services/ui/FlociUiManagerTest.javanew file mode 100644index 0000000000..ff1aefbfff--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/ui/FlociUiManagerTest.java@@ -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());+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/ui/UiLandingIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ui/UiLandingIntegrationTest.javanew file mode 100644index 0000000000..67af3a7dc0--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/ui/UiLandingIntegrationTest.java@@ -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));+ }+}diff --git a/src/test/resources/application.yml b/src/test/resources/application.ymlindex 03d7eaa3ed..ecdfdfb23b 100644--- a/src/test/resources/application.yml+++ b/src/test/resources/application.yml@@ -170,6 +170,8 @@ floci:enabled: trueecr:enabled: true+ ui:+ enabled: truebedrock-runtime:enabled: trueeks: