fix: updating with latest floci changes

This commit is contained in:
Hector Ventura committed 2026-05-15 02:34:27 -05:00
1 parent 0452664457
commit 1d7f9f81d0
16 files changed
+378 -116

No files matched your search

@@ -4,7 +4,18 @@ import io.floci.cli.GlobalOptions;
import io.floci.cli.doctor.Check;
import io.floci.cli.doctor.CheckResult;
import io.floci.cli.doctor.CheckStatus;
import io.floci.cli.doctor.checks.*;
import io.floci.cli.docker.DockerClient;
import io.floci.cli.doctor.checks.AwsCliEndpointCheck;
import io.floci.cli.doctor.checks.AwsCliS3PathStyleCheck;
import io.floci.cli.doctor.checks.ContainerRunningCheck;
import io.floci.cli.doctor.checks.DockerDaemonCheck;
import io.floci.cli.doctor.checks.DockerInstalledCheck;
import io.floci.cli.doctor.checks.DockerSocketCheck;
import io.floci.cli.doctor.checks.DockerVersionCheck;
import io.floci.cli.doctor.checks.EndpointReachableCheck;
import io.floci.cli.doctor.checks.ImagePresentCheck;
import io.floci.cli.doctor.checks.ImageVersionCheck;
import io.floci.cli.doctor.checks.PortAvailableCheck;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.OutputFormat;
import io.floci.cli.output.Printer;
@@ -43,27 +54,30 @@ public class DoctorCommand implements Callable<Integer> {
new ContainerRunningCheck(),
new EndpointReachableCheck(),
new AwsCliEndpointCheck(),
new AwsCliS3PathStyleCheck(),
new SdkRustS3XmlCheck(),
new SdkGoEndpointCheck()
new AwsCliS3PathStyleCheck()
);
@Override
public Integer call() {
Printer printer = global.printer();
List<CheckResult> results = new ArrayList<>();
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
printer.println(Ansi.bold("Floci Doctor") + " — checking your environment");
printer.println("");
boolean textMode = printer.format() == OutputFormat.text;
for (Check check : ALL_CHECKS) {
CheckResult result = check.run(global.endpoint, global.container);
if (checkName != null && !result.name().equals(checkName)) continue;
results.add(result);
printResult(printer, result);
if (textMode) {
printer.println(Ansi.bold("Floci Doctor") + " — checking your environment");
printer.println("");
}
if (printer.format() != OutputFormat.text) {
for (Check check : ALL_CHECKS) {
CheckResult result = check.run(effectiveEndpoint, global.container);
if (checkName != null && !result.name().equals(checkName)) continue;
results.add(result);
if (textMode) printResult(printer, result);
}
if (!textMode) {
List<Map<String, Object>> structured = new ArrayList<>();
for (CheckResult r : results) {
Map<String, Object> m = new LinkedHashMap<>();
@@ -0,0 +1,83 @@
package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.OutputFormat;
import io.floci.cli.output.Printer;
import picocli.CommandLine.*;
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.Callable;
@Command(
name = "env",
description = "Print AWS environment variables to connect to Floci",
mixinStandardHelpOptions = true
)
public class EnvCommand implements Callable<Integer> {
@Mixin
GlobalOptions global;
@Option(names = {"--host"},
description = "Hostname for the AWS endpoint URL (default: localhost.floci.io)",
defaultValue = "${FLOCI_HOST:-localhost.floci.io}",
paramLabel = "<host>")
String host;
@Option(names = {"--region"},
description = "AWS region (default: us-east-1)",
defaultValue = "${AWS_DEFAULT_REGION:-us-east-1}",
paramLabel = "<region>")
String region;
@Option(names = {"--shell"},
description = "Shell format: bash, fish, powershell (default: bash)",
defaultValue = "bash",
paramLabel = "bash|fish|powershell")
String shell;
@Override
public Integer call() {
Printer printer = global.printer();
int port = extractPort(global.endpoint);
String endpointUrl = "http://" + host + ":" + port;
Map<String, String> vars = new LinkedHashMap<>();
vars.put("AWS_ENDPOINT_URL", endpointUrl);
vars.put("AWS_ACCESS_KEY_ID", "test");
vars.put("AWS_SECRET_ACCESS_KEY", "test");
vars.put("AWS_DEFAULT_REGION", region);
if (printer.format() != OutputFormat.text) {
printer.structured(vars);
return 0;
}
for (Map.Entry<String, String> entry : vars.entrySet()) {
printer.println(formatExport(entry.getKey(), entry.getValue()));
}
printer.println("");
printer.println(Ansi.gray("# Run: eval $(floci env)"));
return 0;
}
private String formatExport(String key, String value) {
return switch (shell.toLowerCase()) {
case "fish" -> "set -x " + key + " \"" + value + "\"";
case "powershell", "ps1" -> "$env:" + key + " = \"" + value + "\"";
default -> "export " + key + "=" + value;
};
}
private int extractPort(String endpoint) {
try {
int port = URI.create(endpoint).getPort();
return port == -1 ? 4566 : port;
} catch (Exception e) {
return 4566;
}
}
}
@@ -104,6 +104,9 @@ public class StartCommand implements Callable<Integer> {
return 0;
}
// Update endpoint to match the bound host port before polling readiness
global.endpoint = "http://localhost:" + port;
// Wait for readiness
printer.println(Ansi.gray("Waiting for Floci to be ready..."));
WaitCommand wait = new WaitCommand();
@@ -33,12 +33,14 @@ public class StatusCommand implements Callable<Integer> {
String containerState = "not found";
String containerImage = "";
String containerPorts = "";
String effectiveEndpoint = global.endpoint;
try {
Optional<DockerClient.ContainerInfo> info = docker.inspectContainer(global.container);
if (info.isPresent()) {
containerState = info.get().state();
containerImage = info.get().image();
containerPorts = info.get().ports();
effectiveEndpoint = global.endpointFromPorts(containerPorts, global.endpoint);
}
} catch (DockerException e) {
containerState = "error: " + e.getMessage();
@@ -48,7 +50,7 @@ public class StatusCommand implements Callable<Integer> {
String serverVersion = "unavailable";
String serverEdition = "";
boolean reachable = false;
FlociHttpClient client = new FlociHttpClient(global.endpoint);
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint);
try {
var health = client.health();
serverVersion = health.version();
@@ -61,7 +63,7 @@ public class StatusCommand implements Callable<Integer> {
data.put("state", containerState);
data.put("image", containerImage);
data.put("ports", containerPorts);
data.put("endpoint", global.endpoint);
data.put("endpoint", effectiveEndpoint);
data.put("reachable", reachable);
data.put("version", serverVersion);
data.put("edition", serverEdition);
@@ -81,7 +83,7 @@ public class StatusCommand implements Callable<Integer> {
printer.println(" Container: " + global.container + " " + stateColor);
if (!containerImage.isBlank()) printer.println(" Image: " + containerImage);
if (!containerPorts.isBlank()) printer.println(" Ports: " + containerPorts);
printer.println(" Endpoint: " + global.endpoint);
printer.println(" Endpoint: " + effectiveEndpoint);
printer.println(" Reachable: " + (reachable ? Ansi.green("yes") : Ansi.red("no")));
if (reachable) {
printer.println(" Version: " + serverVersion);
@@ -95,4 +97,5 @@ public class StatusCommand implements Callable<Integer> {
return 0;
}
}
@@ -32,7 +32,10 @@ public class VersionCommand implements Callable<Integer> {
String serverEdition = null;
String imageDigest = null;
FlociHttpClient client = new FlociHttpClient(global.endpoint);
var docker = new io.floci.cli.docker.DockerClient();
String effectiveEndpoint = global.resolvedEndpoint(docker);
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint);
try {
var info = client.info();
serverVersion = info.version();
@@ -41,7 +44,6 @@ public class VersionCommand implements Callable<Integer> {
// Try to read image digest from Docker (best-effort)
try {
var docker = new io.floci.cli.docker.DockerClient();
imageDigest = docker.imageDigest("floci/floci").orElse(null);
} catch (Exception ignored) {}
@@ -3,7 +3,10 @@ package io.floci.cli.commands;
import io.floci.cli.GlobalOptions;
import io.floci.cli.http.FlociHttpClient;
import io.floci.cli.output.Ansi;
import io.floci.cli.output.OutputFormat;
import io.floci.cli.output.Printer;
import java.util.Map;
import picocli.CommandLine.*;
import java.time.Duration;
@@ -30,12 +33,17 @@ public class WaitCommand implements Callable<Integer> {
public Integer call() {
Printer printer = global.printer();
long timeoutMillis = parseDuration(timeout);
FlociHttpClient client = new FlociHttpClient(global.endpoint);
String effectiveEndpoint = global.resolvedEndpoint(new io.floci.cli.docker.DockerClient());
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint);
Instant deadline = Instant.now().plusMillis(timeoutMillis);
while (Instant.now().isBefore(deadline)) {
if (isReady(client, service)) {
printer.println(Ansi.green("Floci is ready") + " (" + global.endpoint + ")");
if (printer.format() != OutputFormat.text) {
printer.structured(Map.of("ready", true, "endpoint", effectiveEndpoint));
} else {
printer.println(Ansi.green("Floci is ready") + " (" + effectiveEndpoint + ")");
}
return 0;
}
printSpinner(printer, deadline);