mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
fix(restart): keep the instance's port, image, data directory and services (#49)
* fix(restart): keep the instance's port, image, data directory and services Without a profile, restart reads the running container's settings (host port, image, the directory mounted at /app/data, its services and resource namespace) before stopping it and starts it with them, instead of falling back to the defaults and moving the instance to the default port without its state. A profile still decides when one is given, and restart now starts the container when none exists instead of failing. A container started without --persist has Docker's anonymous volume at /app/data; restart took that volume's internal path for a persist directory and failed to start again. Only a bind mount is a persist directory now. * fix(restart): stop before the stop when the running container's settings cannot be read A failed or timed-out inspect is no longer treated as a missing container, which removed the instance and started it on the defaults. Adds tests through call() for the missing-container, existing-container and unreadable-settings paths.
This commit is contained in:
1 parent
52ebdee98d
commit
f6cec794d7
4 files changed
+328
-5
No files matched your search
@@ -207,6 +207,49 @@ class DockerClientProcessTest {
|
||||
assertEquals(List.of("rm", "--", "--rm-everything"), args);
|
||||
}
|
||||
|
||||
/** BL-033: restart reads the image, host port, data mount and environment back from inspect. */
|
||||
@Test
|
||||
@DisabledOnOs(OS.WINDOWS)
|
||||
void runSettingsAreReadFromTheContainersInspectDocument() throws Exception {
|
||||
Path json = tempDir.resolve("inspect.json");
|
||||
Files.writeString(json, """
|
||||
{"Config":{"Image":"floci/floci-gcp:0.9","Env":["FLOCI_GCP_SERVICES=storage","PATH=/usr/bin"]},
|
||||
"HostConfig":{"PortBindings":{"4588/tcp":[{"HostIp":"","HostPort":"14588"}]}},
|
||||
"Mounts":[{"Type":"bind","Source":"/data/gcp","Destination":"/app/data"}]}
|
||||
""");
|
||||
Path fakeDocker = tempDir.resolve("docker");
|
||||
Files.writeString(fakeDocker, "#!/bin/sh\ncat '" + json + "'\n");
|
||||
assertTrue(fakeDocker.toFile().setExecutable(true));
|
||||
|
||||
DockerClient.RunSettings run = new DockerClient(fakeDocker.toString())
|
||||
.inspectRunSettings("floci-gcp", 4588).orElseThrow();
|
||||
|
||||
assertEquals("floci/floci-gcp:0.9", run.image());
|
||||
assertEquals(14588, run.hostPort());
|
||||
assertEquals("/data/gcp", run.persistSource());
|
||||
assertEquals("storage", run.env().get("FLOCI_GCP_SERVICES"));
|
||||
}
|
||||
|
||||
/** Without --persist the image's /app/data volume is mounted; that is not a persist directory. */
|
||||
@Test
|
||||
@DisabledOnOs(OS.WINDOWS)
|
||||
void anAnonymousDataVolumeIsNotAPersistDirectory() throws Exception {
|
||||
Path json = tempDir.resolve("inspect.json");
|
||||
Files.writeString(json, """
|
||||
{"Config":{"Image":"floci/floci-oci:latest","Env":[]},
|
||||
"HostConfig":{"PortBindings":{"4599/tcp":[{"HostIp":"","HostPort":"4599"}]}},
|
||||
"Mounts":[{"Type":"volume","Name":"3c3aef44","Source":"/var/lib/docker/volumes/3c3aef44/_data","Destination":"/app/data"}]}
|
||||
""");
|
||||
Path fakeDocker = tempDir.resolve("docker");
|
||||
Files.writeString(fakeDocker, "#!/bin/sh\ncat '" + json + "'\n");
|
||||
assertTrue(fakeDocker.toFile().setExecutable(true));
|
||||
|
||||
DockerClient.RunSettings run = new DockerClient(fakeDocker.toString())
|
||||
.inspectRunSettings("floci-oci", 4599).orElseThrow();
|
||||
|
||||
assertNull(run.persistSource());
|
||||
}
|
||||
|
||||
/** BL-041: with --verbose set, each docker command is echoed to stderr before it runs. */
|
||||
@Test
|
||||
@DisabledOnOs(OS.WINDOWS)
|
||||
|
||||
Reference in new issue
Block a user