mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
feat(oci): add floci oci command group for the Floci OCI emulator (#15)
* feat(oci): add floci oci command group for the Floci OCI emulator
Adds the fourth product tree targeting floci-oci (port 4599, container
floci-oci, control prefix /_floci-oci, FLOCI_OCI_* env overrides):
start/stop/restart/status/logs/wait/version/services/doctor/env/config
plus stub snapshot commands, mirroring the GCP/Azure trees.
- 'floci oci env' exports OCI_CLI_ENDPOINT, FLOCI_OCI_ENDPOINT, and
TF_VAR_CLIENT_HOST_OVERRIDES for the OCI CLI, the ocilocal wrapper,
and the oracle/oci Terraform provider; also OCI_CLI_PROFILE=FLOCI
when that profile exists.
- 'floci oci setup' generates an RSA-2048 API signing key with a real
computed fingerprint and writes a throwaway [FLOCI] profile to
~/.oci/config (idempotent, never touches existing profiles) — the
OCI CLI/SDKs refuse to run without them.
- FlociHttpClient now accepts both health 'services' shapes: the array
reported by AWS/GCP/Azure servers and the {name: status} object
reported by floci-oci.
- 'floci config default-product oci' routes bare commands to the tree.
* fix(oci): address review findings on env, services, and setup profile
- Single-quote 'oci env' exports with per-shell escaping (bash/fish/
PowerShell) so endpoint values containing shell metacharacters cannot
inject commands through the documented 'eval $(floci oci env)' flow.
- 'oci services' resolves the endpoint from the container port mapping
like status/wait/env, so a container started with --port <n> is found
without passing --endpoint.
- 'oci env' exports OCI_CLI_PROFILE for whichever profile 'oci setup'
wrote (detected via its key_file marker) instead of only the
hardcoded FLOCI name; DEFAULT is skipped as the CLI uses it
implicitly.
This commit is contained in:
1 parent
2ff3181198
commit
0a65de2303
34 files changed
+1924
-33
No files matched your search
@@ -0,0 +1,73 @@
|
||||
package io.floci.cli.commands.oci;
|
||||
|
||||
import io.floci.cli.OciGlobalOptions;
|
||||
import io.floci.cli.docker.DockerClient;
|
||||
import io.floci.cli.docker.DockerException;
|
||||
import io.floci.cli.output.Ansi;
|
||||
import io.floci.cli.output.Printer;
|
||||
import picocli.CommandLine.*;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@Command(
|
||||
name = "stop",
|
||||
description = "Stop the Floci OCI container",
|
||||
mixinStandardHelpOptions = true
|
||||
)
|
||||
public class OciStopCommand implements Callable<Integer> {
|
||||
|
||||
@Mixin
|
||||
OciGlobalOptions global;
|
||||
|
||||
@Option(names = {"--remove", "-r"}, description = "Remove the container after stopping")
|
||||
boolean remove;
|
||||
|
||||
@Option(names = {"--timeout"}, description = "Seconds to wait before forcefully killing (default: 10)", defaultValue = "10", paramLabel = "<seconds>")
|
||||
int timeout;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Printer printer = global.printer();
|
||||
DockerClient docker = new DockerClient();
|
||||
|
||||
try {
|
||||
var info = docker.inspectContainer(global.container);
|
||||
if (info.isEmpty()) {
|
||||
printer.error("Container '" + global.container + "' not found.\nRun 'floci oci start' to launch one.");
|
||||
return 1;
|
||||
}
|
||||
if (!"running".equals(info.get().state())) {
|
||||
printer.println(Ansi.yellow("Container '" + global.container + "' is not running (state: " + info.get().state() + ")"));
|
||||
if (remove) {
|
||||
docker.removeContainer(global.container);
|
||||
printer.println("Container removed.");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} catch (DockerException e) {
|
||||
printer.error("Failed to inspect container: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
printer.println("Stopping " + Ansi.gold("Floci OCI") + " container '" + global.container + "'...");
|
||||
docker.stopContainer(global.container, timeout);
|
||||
printer.println(Ansi.green("Stopped."));
|
||||
} catch (DockerException e) {
|
||||
printer.error("Failed to stop container: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
try {
|
||||
docker.removeContainer(global.container);
|
||||
printer.println("Container removed.");
|
||||
} catch (DockerException e) {
|
||||
printer.error("Failed to remove container: " + e.getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user