From 1d7f9f81d0f280ba4262dfb251e2ec605495808d Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Fri, 15 May 2026 02:34:27 -0500 Subject: [PATCH] fix: updating with latest floci changes --- .github/workflows/ci.yml | 10 +- .github/workflows/release.yml | 10 +- README.md | 182 ++++++++++++++++-- src/main/java/io/floci/cli/FlociCli.java | 4 +- src/main/java/io/floci/cli/GlobalOptions.java | 35 ++++ .../io/floci/cli/commands/DoctorCommand.java | 38 ++-- .../io/floci/cli/commands/EnvCommand.java | 83 ++++++++ .../io/floci/cli/commands/StartCommand.java | 3 + .../io/floci/cli/commands/StatusCommand.java | 9 +- .../io/floci/cli/commands/VersionCommand.java | 6 +- .../io/floci/cli/commands/WaitCommand.java | 12 +- .../io/floci/cli/docker/DockerClient.java | 4 +- .../doctor/checks/AwsCliEndpointCheck.java | 34 +++- .../cli/doctor/checks/SdkGoEndpointCheck.java | 30 --- .../cli/doctor/checks/SdkRustS3XmlCheck.java | 30 --- .../io/floci/cli/http/FlociHttpClient.java | 4 +- 16 files changed, 378 insertions(+), 116 deletions(-) create mode 100644 src/main/java/io/floci/cli/commands/EnvCommand.java delete mode 100644 src/main/java/io/floci/cli/doctor/checks/SdkGoEndpointCheck.java delete mode 100644 src/main/java/io/floci/cli/doctor/checks/SdkRustS3XmlCheck.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65146c3..2d0a616 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: - uses: graalvm/setup-graalvm@v1 with: - java-version: '24' + java-version: '25' distribution: 'graalvm-community' cache: maven github-token: ${{ secrets.GITHUB_TOKEN }} @@ -75,7 +75,7 @@ jobs: - uses: graalvm/setup-graalvm@v1 with: - java-version: '24' + java-version: '25' distribution: 'graalvm-community' cache: maven github-token: ${{ secrets.GITHUB_TOKEN }} @@ -101,7 +101,7 @@ jobs: - uses: graalvm/setup-graalvm@v1 with: - java-version: '24' + java-version: '25' distribution: 'graalvm-community' cache: maven github-token: ${{ secrets.GITHUB_TOKEN }} @@ -127,7 +127,7 @@ jobs: - uses: graalvm/setup-graalvm@v1 with: - java-version: '24' + java-version: '25' distribution: 'graalvm-community' cache: maven github-token: ${{ secrets.GITHUB_TOKEN }} @@ -153,7 +153,7 @@ jobs: - uses: graalvm/setup-graalvm@v1 with: - java-version: '24' + java-version: '25' distribution: 'graalvm-community' cache: maven github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 445a7ca..6342e71 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,7 +28,7 @@ jobs: - uses: actions/checkout@v4 - uses: graalvm/setup-graalvm@v1 with: - java-version: '24' + java-version: '25' distribution: 'graalvm-community' cache: maven github-token: ${{ secrets.GITHUB_TOKEN }} @@ -47,7 +47,7 @@ jobs: - uses: actions/checkout@v4 - uses: graalvm/setup-graalvm@v1 with: - java-version: '24' + java-version: '25' distribution: 'graalvm-community' cache: maven github-token: ${{ secrets.GITHUB_TOKEN }} @@ -66,7 +66,7 @@ jobs: - uses: actions/checkout@v4 - uses: graalvm/setup-graalvm@v1 with: - java-version: '24' + java-version: '25' distribution: 'graalvm-community' cache: maven github-token: ${{ secrets.GITHUB_TOKEN }} @@ -85,7 +85,7 @@ jobs: - uses: actions/checkout@v4 - uses: graalvm/setup-graalvm@v1 with: - java-version: '24' + java-version: '25' distribution: 'graalvm-community' cache: maven github-token: ${{ secrets.GITHUB_TOKEN }} @@ -104,7 +104,7 @@ jobs: - uses: actions/checkout@v4 - uses: graalvm/setup-graalvm@v1 with: - java-version: '24' + java-version: '25' distribution: 'graalvm-community' cache: maven github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 87b23c7..e19d824 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ Official command-line interface for [Floci](https://floci.io) — the free, open-source local AWS emulator. -``` +```sh floci start floci doctor -export AWS_ENDPOINT_URL=http://localhost:4566 +eval $(floci env) aws s3 mb s3://my-bucket ``` @@ -36,14 +36,6 @@ scoop bucket add floci https://github.com/floci-io/scoop-floci scoop install floci ``` -### Docker - -```sh -docker run --rm floci/cli:latest version -# With Docker socket for lifecycle commands: -docker run --rm -v /var/run/docker.sock:/var/run/docker.sock floci/cli status -``` - ### JVM fallback Download `floci.jar` from the [latest release](https://github.com/floci-io/floci-cli/releases/latest) and run: @@ -63,8 +55,8 @@ floci start # Check environment floci doctor -# Point the AWS CLI at Floci -export AWS_ENDPOINT_URL=http://localhost:4566 +# Export AWS environment variables +eval $(floci env) # Use AWS services normally aws s3 mb s3://my-bucket @@ -92,21 +84,162 @@ floci stop | `floci version` | Show CLI and server versions | | `floci services` | List enabled AWS services | | `floci doctor` | Run environment diagnostics | +| `floci env` | Print AWS environment variables | | `floci config show` | Show active configuration | | `floci config validate` | Validate a docker-compose.yml | | `floci config profile` | Manage named profiles | | `floci snapshot save/load/list/delete` | Manage state snapshots | | `floci completion bash\|zsh` | Generate shell completion | -All commands support `--help`. Global flags: +All commands support `--help`. Global flags available on every command: ``` ---endpoint Floci server URL (default: http://localhost:4566, env: FLOCI_ENDPOINT) ---container Container name (default: floci, env: FLOCI_CONTAINER) ---output text|json|yaml Output format (default: text) ---quiet, -q Suppress non-error output ---verbose, -v Debug logging to stderr ---no-color Disable ANSI colors +--endpoint Floci server URL (default: http://localhost:4566, env: FLOCI_ENDPOINT) +--container Container name (default: floci, env: FLOCI_CONTAINER) +--output|-o text|json|yaml Output format (default: text) +--quiet, -q Suppress non-error output +--verbose, -v Debug logging to stderr +--no-color Disable ANSI colors +--profile Load settings from ~/.floci/profiles/.yaml +``` + +> **Port auto-detection** — `status`, `version`, and `wait` automatically derive the correct +> endpoint from the container's port mapping. You don't need to pass `--endpoint` when using +> a non-default port, as long as `--container` points to the right container. + +--- + +## Commands + +### `floci start` + +Pulls the image (if needed), starts the container, and waits for readiness. + +```sh +floci start # default port 4566 +floci start --port 4599 # custom host port +floci start --services s3,dynamodb # enable specific services +floci start --persist ./data # persist state to a host directory +floci start --pull always # always pull the latest image +floci start --detach # return immediately, don't wait +``` + +### `floci stop` + +```sh +floci stop # graceful stop (10s timeout) +floci stop --timeout 30 # wait up to 30s before force-kill +floci stop --remove # also remove the container after stopping +``` + +### `floci status` + +```sh +floci status # auto-detects endpoint from container port mapping +floci status --container myfloci # target a specific container +floci status -o json # structured output +``` + +### `floci env` + +Prints AWS environment variables pointing at the running Floci instance. The default +hostname is `localhost.floci.io` (resolves to `127.0.0.1`, enables virtual-hosted S3 bucket names). + +```sh +eval $(floci env) # bash/zsh — sets all four AWS vars +floci env --shell fish | source # fish +floci env --shell powershell | Invoke-Expression # PowerShell + +floci env --host myhost.local # custom hostname +floci env --region eu-west-1 # custom region (default: us-east-1) +floci env --endpoint http://localhost:4599 # pick up port from a non-default instance +floci env -o json # structured output for scripts +``` + +Variables exported: + +| Variable | Default value | +|----------|---------------| +| `AWS_ENDPOINT_URL` | `http://localhost.floci.io:4566` | +| `AWS_ACCESS_KEY_ID` | `test` | +| `AWS_SECRET_ACCESS_KEY` | `test` | +| `AWS_DEFAULT_REGION` | `us-east-1` | + +### `floci logs` + +```sh +floci logs # last logs from the container +floci logs --tail 50 # last 50 lines +floci logs --since 5m # logs from the last 5 minutes +floci logs --follow # stream live logs (Ctrl-C to stop) +``` + +### `floci wait` + +```sh +floci wait # wait up to 30s (default) +floci wait --timeout 2m # custom timeout (supports s, m, h) +floci wait --service dynamodb # wait until a specific service is ready +floci wait -o json # machine-readable output +``` + +### `floci doctor` + +```sh +floci doctor # run all checks +floci doctor --check docker.installed # run a single check by name +floci doctor --fix # auto-fix fixable issues +floci doctor -o json # structured output for scripts +``` + +### `floci version` + +```sh +floci version # CLI version, server version, image digest +floci version -o json +``` + +### `floci services` + +```sh +floci services # list all enabled services +floci services --mode docker # only docker-backed services +floci services --mode in-process # only in-process services +floci services -o json +``` + +### `floci config` + +```sh +floci config show # show active configuration +floci config profile list # list saved profiles +floci config profile create # create a new profile +floci config profile show # show a profile +floci config profile delete # delete a profile +floci config validate -f docker-compose.yml # validate a Compose file +``` + +Profiles are stored in `~/.floci/profiles/.yaml` and can override any global option. +Use `--profile ` on any command to load one. + +### `floci snapshot` + +Save and restore named snapshots of Floci state (requires server-side support — coming soon). + +```sh +floci snapshot list +floci snapshot save --message "before migration" +floci snapshot load +floci snapshot delete +floci snapshot export -o tarball.tar.gz +floci snapshot import tarball.tar.gz +``` + +### `floci completion` + +```sh +floci completion bash >> ~/.bashrc +floci completion zsh >> ~/.zshrc ``` --- @@ -114,12 +247,21 @@ All commands support `--help`. Global flags: ## CI Usage ```sh -floci start --detach +floci start --port 4566 --detach floci wait --timeout 60s pytest # or your test command floci stop --remove ``` +Set AWS environment variables in CI before running tests: + +```sh +export AWS_ENDPOINT_URL=http://localhost:4566 +export AWS_ACCESS_KEY_ID=test +export AWS_SECRET_ACCESS_KEY=test +export AWS_DEFAULT_REGION=us-east-1 +``` + With Docker Compose: ```yaml diff --git a/src/main/java/io/floci/cli/FlociCli.java b/src/main/java/io/floci/cli/FlociCli.java index 527b659..191dc8c 100644 --- a/src/main/java/io/floci/cli/FlociCli.java +++ b/src/main/java/io/floci/cli/FlociCli.java @@ -14,7 +14,8 @@ import picocli.CommandLine.*; " floci stop — stop the container%n" + " floci status — show health and version%n" + " floci doctor — diagnose environment issues%n" + - " floci logs — stream container logs%n", + " floci logs — stream container logs%n" + + " floci env — print AWS environment variables%n", mixinStandardHelpOptions = true, versionProvider = FlociCli.VersionProvider.class, subcommands = { @@ -27,6 +28,7 @@ import picocli.CommandLine.*; VersionCommand.class, ServicesCommand.class, DoctorCommand.class, + EnvCommand.class, ConfigCommand.class, SnapshotCommand.class, CompletionCommand.class, diff --git a/src/main/java/io/floci/cli/GlobalOptions.java b/src/main/java/io/floci/cli/GlobalOptions.java index 649d1f1..66fdf4f 100644 --- a/src/main/java/io/floci/cli/GlobalOptions.java +++ b/src/main/java/io/floci/cli/GlobalOptions.java @@ -1,10 +1,13 @@ package io.floci.cli; +import io.floci.cli.docker.DockerClient; import io.floci.cli.output.Ansi; import io.floci.cli.output.OutputFormat; import io.floci.cli.output.Printer; import picocli.CommandLine.Option; +import java.net.URI; + public class GlobalOptions { @Option(names = {"--endpoint"}, @@ -46,6 +49,38 @@ public class GlobalOptions { return new Printer(System.out, System.err, output, quiet); } + // Inspects the container and derives the endpoint from its host port mapping. + // Falls back to the configured endpoint if the container is not found or has no mapping. + public String resolvedEndpoint(DockerClient docker) { + try { + return docker.inspectContainer(container) + .map(info -> endpointFromPorts(info.ports(), endpoint)) + .orElse(endpoint); + } catch (Exception e) { + return endpoint; + } + } + + // Matches the container-side port from the configured endpoint to find the actual host port. + public String endpointFromPorts(String ports, String fallback) { + if (ports == null || ports.isBlank()) return fallback; + try { + int containerPort = URI.create(fallback).getPort(); + if (containerPort == -1) containerPort = 4566; + for (String mapping : ports.trim().split("\\s+")) { + int arrow = mapping.indexOf("->"); + if (arrow < 0) continue; + String hostPort = mapping.substring(0, arrow); + String rest = mapping.substring(arrow + 2); + String cPort = rest.contains("/") ? rest.substring(0, rest.indexOf('/')) : rest; + if (String.valueOf(containerPort).equals(cPort)) { + return "http://localhost:" + hostPort; + } + } + } catch (Exception ignored) {} + return fallback; + } + private static boolean isStdoutTty() { return System.console() != null; } diff --git a/src/main/java/io/floci/cli/commands/DoctorCommand.java b/src/main/java/io/floci/cli/commands/DoctorCommand.java index 98fca5a..39b69f2 100644 --- a/src/main/java/io/floci/cli/commands/DoctorCommand.java +++ b/src/main/java/io/floci/cli/commands/DoctorCommand.java @@ -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 { new ContainerRunningCheck(), new EndpointReachableCheck(), new AwsCliEndpointCheck(), - new AwsCliS3PathStyleCheck(), - new SdkRustS3XmlCheck(), - new SdkGoEndpointCheck() + new AwsCliS3PathStyleCheck() ); @Override public Integer call() { Printer printer = global.printer(); List 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> structured = new ArrayList<>(); for (CheckResult r : results) { Map m = new LinkedHashMap<>(); diff --git a/src/main/java/io/floci/cli/commands/EnvCommand.java b/src/main/java/io/floci/cli/commands/EnvCommand.java new file mode 100644 index 0000000..694fb08 --- /dev/null +++ b/src/main/java/io/floci/cli/commands/EnvCommand.java @@ -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 { + + @Mixin + GlobalOptions global; + + @Option(names = {"--host"}, + description = "Hostname for the AWS endpoint URL (default: localhost.floci.io)", + defaultValue = "${FLOCI_HOST:-localhost.floci.io}", + paramLabel = "") + String host; + + @Option(names = {"--region"}, + description = "AWS region (default: us-east-1)", + defaultValue = "${AWS_DEFAULT_REGION:-us-east-1}", + paramLabel = "") + 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 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 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; + } + } +} diff --git a/src/main/java/io/floci/cli/commands/StartCommand.java b/src/main/java/io/floci/cli/commands/StartCommand.java index ec5f350..7569f3a 100644 --- a/src/main/java/io/floci/cli/commands/StartCommand.java +++ b/src/main/java/io/floci/cli/commands/StartCommand.java @@ -104,6 +104,9 @@ public class StartCommand implements Callable { 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(); diff --git a/src/main/java/io/floci/cli/commands/StatusCommand.java b/src/main/java/io/floci/cli/commands/StatusCommand.java index a14b950..99f70cf 100644 --- a/src/main/java/io/floci/cli/commands/StatusCommand.java +++ b/src/main/java/io/floci/cli/commands/StatusCommand.java @@ -33,12 +33,14 @@ public class StatusCommand implements Callable { String containerState = "not found"; String containerImage = ""; String containerPorts = ""; + String effectiveEndpoint = global.endpoint; try { Optional 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 { 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 { 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 { 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 { return 0; } + } diff --git a/src/main/java/io/floci/cli/commands/VersionCommand.java b/src/main/java/io/floci/cli/commands/VersionCommand.java index 7fde322..767c506 100644 --- a/src/main/java/io/floci/cli/commands/VersionCommand.java +++ b/src/main/java/io/floci/cli/commands/VersionCommand.java @@ -32,7 +32,10 @@ public class VersionCommand implements Callable { 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 { // 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) {} diff --git a/src/main/java/io/floci/cli/commands/WaitCommand.java b/src/main/java/io/floci/cli/commands/WaitCommand.java index d25a3e4..0014d78 100644 --- a/src/main/java/io/floci/cli/commands/WaitCommand.java +++ b/src/main/java/io/floci/cli/commands/WaitCommand.java @@ -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 { 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); diff --git a/src/main/java/io/floci/cli/docker/DockerClient.java b/src/main/java/io/floci/cli/docker/DockerClient.java index e4f6205..e006b7d 100644 --- a/src/main/java/io/floci/cli/docker/DockerClient.java +++ b/src/main/java/io/floci/cli/docker/DockerClient.java @@ -40,7 +40,7 @@ public class DockerClient { public Optional inspectContainer(String name) throws DockerException { try { String out = run("docker", "inspect", "--format", - "{{.Id}}|{{.Name}}|{{.Config.Image}}|{{.Status}}|{{.State.Status}}|{{range $p, $b := .NetworkSettings.Ports}}{{$p}} {{end}}", + "{{.Id}}|{{.Name}}|{{.Config.Image}}|{{.State.Status}}|{{.State.Status}}|{{range $p, $b := .NetworkSettings.Ports}}{{if $b}}{{(index $b 0).HostPort}}->{{$p}} {{end}}{{end}}", name); if (out.isBlank()) return Optional.empty(); String[] parts = out.trim().split("\\|", -1); @@ -52,7 +52,7 @@ public class DockerClient { parts.length > 4 ? parts[4] : "", parts.length > 5 ? parts[5].trim() : "")); } catch (DockerException e) { - if (e.getMessage() != null && e.getMessage().contains("No such")) { + if (e.getMessage() != null && e.getMessage().toLowerCase().contains("no such")) { return Optional.empty(); } throw e; diff --git a/src/main/java/io/floci/cli/doctor/checks/AwsCliEndpointCheck.java b/src/main/java/io/floci/cli/doctor/checks/AwsCliEndpointCheck.java index 542859b..53f376a 100644 --- a/src/main/java/io/floci/cli/doctor/checks/AwsCliEndpointCheck.java +++ b/src/main/java/io/floci/cli/doctor/checks/AwsCliEndpointCheck.java @@ -3,21 +3,51 @@ package io.floci.cli.doctor.checks; import io.floci.cli.doctor.Check; import io.floci.cli.doctor.CheckResult; +import java.net.URI; +import java.net.URISyntaxException; + public class AwsCliEndpointCheck implements Check { @Override public CheckResult run(String endpoint, String container) { - // Check if aws CLI is installed first if (!isAwsCliInstalled()) { return CheckResult.ok("aws.cli.endpoint", "aws CLI not installed — skipped"); } String envVar = System.getenv("AWS_ENDPOINT_URL"); + int effectivePort = extractPort(endpoint); if (envVar != null && !envVar.isBlank()) { + int envPort = extractPort(envVar); + if (envPort != -1 && effectivePort != -1 && envPort != effectivePort) { + String corrected = replacePort(envVar, effectivePort); + return CheckResult.warn("aws.cli.endpoint", + "AWS_ENDPOINT_URL=" + envVar + " (port mismatch — Floci is on port " + effectivePort + ")", + "export AWS_ENDPOINT_URL=" + corrected); + } return CheckResult.ok("aws.cli.endpoint", "AWS_ENDPOINT_URL=" + envVar); } + String suggested = "http://localhost.floci.io:" + (effectivePort != -1 ? effectivePort : 4566); return CheckResult.warn("aws.cli.endpoint", "AWS_ENDPOINT_URL is not set", - "export AWS_ENDPOINT_URL=" + endpoint); + "export AWS_ENDPOINT_URL=" + suggested); + } + + private int extractPort(String url) { + try { + int port = URI.create(url).getPort(); + return port == -1 ? 80 : port; + } catch (Exception e) { + return -1; + } + } + + private String replacePort(String url, int newPort) { + try { + URI uri = URI.create(url); + return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), + newPort, uri.getPath(), uri.getQuery(), uri.getFragment()).toString(); + } catch (Exception e) { + return url; + } } private boolean isAwsCliInstalled() { diff --git a/src/main/java/io/floci/cli/doctor/checks/SdkGoEndpointCheck.java b/src/main/java/io/floci/cli/doctor/checks/SdkGoEndpointCheck.java deleted file mode 100644 index 18d8277..0000000 --- a/src/main/java/io/floci/cli/doctor/checks/SdkGoEndpointCheck.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.floci.cli.doctor.checks; - -import io.floci.cli.doctor.Check; -import io.floci.cli.doctor.CheckResult; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -public class SdkGoEndpointCheck implements Check { - - @Override - public CheckResult run(String endpoint, String container) { - Path goMod = Path.of("go.mod"); - if (!Files.exists(goMod)) { - return CheckResult.ok("sdk.go.endpoint", "No go.mod in CWD — skipped"); - } - try { - String content = Files.readString(goMod); - if (!content.contains("aws-sdk-go-v2")) { - return CheckResult.ok("sdk.go.endpoint", "aws-sdk-go-v2 not in go.mod — skipped"); - } - return CheckResult.warn("sdk.go.endpoint", - "aws-sdk-go-v2 detected — use BaseEndpoint instead of deprecated EndpointResolver", - "See https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/endpoints/ for migration guide"); - } catch (IOException e) { - return CheckResult.warn("sdk.go.endpoint", "Could not read go.mod", null); - } - } -} diff --git a/src/main/java/io/floci/cli/doctor/checks/SdkRustS3XmlCheck.java b/src/main/java/io/floci/cli/doctor/checks/SdkRustS3XmlCheck.java deleted file mode 100644 index 3c6a572..0000000 --- a/src/main/java/io/floci/cli/doctor/checks/SdkRustS3XmlCheck.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.floci.cli.doctor.checks; - -import io.floci.cli.doctor.Check; -import io.floci.cli.doctor.CheckResult; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -public class SdkRustS3XmlCheck implements Check { - - @Override - public CheckResult run(String endpoint, String container) { - Path cargoToml = Path.of("Cargo.toml"); - if (!Files.exists(cargoToml)) { - return CheckResult.ok("sdk.rust.s3.xml", "No Cargo.toml in CWD — skipped"); - } - try { - String content = Files.readString(cargoToml); - if (!content.contains("aws-sdk-s3")) { - return CheckResult.ok("sdk.rust.s3.xml", "aws-sdk-s3 not in Cargo.toml — skipped"); - } - return CheckResult.warn("sdk.rust.s3.xml", - "aws-sdk-s3 detected — known issue: XmlDecodeError on S3 error responses", - "See https://github.com/floci-io/floci/issues/11 for workaround"); - } catch (IOException e) { - return CheckResult.warn("sdk.rust.s3.xml", "Could not read Cargo.toml", null); - } - } -} diff --git a/src/main/java/io/floci/cli/http/FlociHttpClient.java b/src/main/java/io/floci/cli/http/FlociHttpClient.java index dc7d42b..7ea8dc3 100644 --- a/src/main/java/io/floci/cli/http/FlociHttpClient.java +++ b/src/main/java/io/floci/cli/http/FlociHttpClient.java @@ -29,7 +29,7 @@ public class FlociHttpClient { JsonNode node = getJson("/_floci/health"); return new HealthInfo( node.path("version").asText("unknown"), - node.path("edition").asText("community"), + node.path("original_edition").asText(node.path("edition").asText("community")), node.path("services").isArray() ? MAPPER.convertValue(node.path("services"), String[].class) : new String[0]); @@ -47,7 +47,7 @@ public class FlociHttpClient { JsonNode node = getJson("/_floci/info"); return new ServerInfo( node.path("version").asText("unknown"), - node.path("edition").asText("community")); + node.path("original_edition").asText(node.path("edition").asText("community"))); } public InitState initState() throws FlociException {