Merge remote-tracking branch 'origin/main' into fix/instance-hints

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

# Conflicts:
#	plugin.json
#	skills/floci/SKILL.md
#	src/main/java/io/floci/cli/commands/StartCommand.java
This commit is contained in:
Hector Ventura committed 2026-11-04 01:09:13 -06:00
commit df390501c8
13 files changed
+385 -11

No files matched your search

@@ -36,6 +36,11 @@ public record ProductProfile(
return "aws".equals(name) ? "floci" : "floci " + name;
}
/** Always names the tree: a bare {@code floci} goes to whatever default product is configured. */
public String explicitCommandPrefix() {
return "floci " + name;
}
/**
* The Docker resource namespace an instance in {@code container} gets when none is set: none
* for the default container, so its child containers keep their names; otherwise the container
@@ -96,7 +96,14 @@ public class RestartCommand implements Callable<Integer> {
int stopResult = buildStopCommand().call();
if (stopResult != 0) return stopResult;
return start.call();
// Capture before start mutates its endpoint while waiting. This command stands alone,
// even if the profile is edited or deleted after the failed restart.
String recovery = start.recoveryCommand();
int result = start.call();
if (result != 0) {
printer.error(recoveryMessage(recovery));
}
return result;
}
/**
@@ -125,7 +132,7 @@ public class RestartCommand implements Callable<Integer> {
public StartCommand buildStartCommand() throws DockerException {
// The outer parse's provider: its memoized profile is the snapshot the globals below were
// resolved from, so the start settings cannot come from a newer version of the file.
StartCommand start = StartCommand.resolvedFor(profile, ProfileDefaultValueProvider.of(spec), global.profile);
StartCommand start = StartCommand.resolvedFor(profile, ProfileDefaultValueProvider.of(spec), global.profile, docker);
// The real invocation's globals win: they already carry the profile plus any flag the
// user passed, resolved once by the outer parse.
@@ -153,6 +160,31 @@ public class RestartCommand implements Callable<Integer> {
});
}
// A new container that is up but has not answered yet cannot be started again: start refuses a
// running container. So the retry command is only for a container that did not come up.
private String recoveryMessage(String recovery) {
boolean running;
try {
running = docker.inspectContainer(global.container)
.filter(info -> "running".equals(info.state())).isPresent();
} catch (DockerException e) {
running = false;
}
if (running) {
String prefix = profile.explicitCommandPrefix();
String selector = global.instanceSelector();
// By now this is the endpoint start waited on, with the port it bound.
String wait = global.typed("--endpoint") && !selector.contains(" --endpoint ")
? selector + " --endpoint " + GlobalOptions.shellWord(global.endpoint)
: selector;
return "The new container is running but did not become ready.\n"
+ "Check it with '" + prefix + " logs" + selector + "', then run '"
+ prefix + " wait" + wait + "' to wait again.";
}
return "Restart did not finish after the old container was removed.\n"
+ "To retry with the same settings, run:\n" + recovery;
}
private boolean containerExists() {
try {
return docker.inspectContainer(global.container).isPresent();
@@ -99,7 +99,14 @@ public class StartCommand implements Callable<Integer> {
public static StartCommand resolvedFor(ProductProfile product,
ProfileDefaultValueProvider provider,
String profileName) {
StartCommand start = new StartCommand(product);
return resolvedFor(product, provider, profileName, new DockerClient());
}
/** Reuse the caller's Docker client when a restart starts the resolved instance. */
public static StartCommand resolvedFor(ProductProfile product,
ProfileDefaultValueProvider provider,
String profileName, DockerClient docker) {
StartCommand start = new StartCommand(product, docker);
if (profileName != null) {
new CommandLine(start)
.setCaseInsensitiveEnumValuesAllowed(true)
@@ -121,6 +128,25 @@ public class StartCommand implements Callable<Integer> {
return flags.toString();
}
/** A self-contained POSIX command that recovers the resolved settings after a failed restart. */
public String recoveryCommand() {
StringBuilder command = new StringBuilder(profile.explicitCommandPrefix()).append(" start");
command.append(" --container ").append(GlobalOptions.shellWord(global.container));
command.append(" --port ").append(port);
command.append(" --image ").append(GlobalOptions.shellWord(image));
// --port already moves the default endpoint, so only a different one is worth naming.
if (!profile.defaultEndpoint().equals(global.endpoint)) {
command.append(" --endpoint ").append(GlobalOptions.shellWord(global.endpoint));
}
// Resolved, so the retry mounts the same directory from wherever it is run.
if (persistDir != null && !persistDir.isBlank()) {
command.append(" --persist ").append(GlobalOptions.shellWord(bindSource(docker.daemonHost())));
}
if (services != null) command.append(" --services ").append(GlobalOptions.shellWord(services));
if (namespace != null) command.append(" --namespace ").append(GlobalOptions.shellWord(namespace));
return command.toString();
}
/** What a profile-resolved instance would start with. Read by {@code config show}. */
public String image() { return image; }
@@ -445,9 +471,16 @@ public class StartCommand implements Callable<Integer> {
return exit;
}
private String readinessTimeout = "30s";
/** How long start waits for the emulator to answer. A seam: tests do not wait half a minute. */
protected String readinessTimeout() {
return "30s";
return readinessTimeout;
}
/** Test seam for a start built by {@code restart}, which cannot be subclassed from outside. */
public void readinessTimeout(String timeout) {
this.readinessTimeout = timeout;
}
// What -o json/yaml reports for a start: 'ready' is left out when --detach did not wait for it.