diff options
| author | salmonik <salmonik@tuta.io> | 2026-07-12 22:06:54 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-07-12 22:06:54 +0200 |
| commit | ce30a8732c21a1c936ac560b5c94576df2e26b22 (patch) | |
| tree | 259a81d24b84ddfda51a6aa96c80ecb4a4afcfae /src/docker.rs | |
| parent | second stable (diff) | |
| download | minecraft-ui-ce30a8732c21a1c936ac560b5c94576df2e26b22.tar.gz minecraft-ui-ce30a8732c21a1c936ac560b5c94576df2e26b22.zip | |
remove unused code, also, third stable
Diffstat (limited to '')
| -rw-r--r-- | src/docker.rs | 39 |
1 files changed, 2 insertions, 37 deletions
diff --git a/src/docker.rs b/src/docker.rs index b18bb47..6b8640a 100644 --- a/src/docker.rs +++ b/src/docker.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use bollard::Docker; | 1 | use bollard::Docker; |
| 2 | use bollard::container::{ | 2 | use bollard::container::{ |
| 3 | Config as ContainerConfig, CreateContainerOptions, ListContainersOptions, | 3 | Config as ContainerConfig, CreateContainerOptions, RemoveContainerOptions, |
| 4 | RemoveContainerOptions, StartContainerOptions, StopContainerOptions, | 4 | StartContainerOptions, StopContainerOptions, |
| 5 | }; | 5 | }; |
| 6 | use bollard::image::CreateImageOptions; | 6 | use bollard::image::CreateImageOptions; |
| 7 | use bollard::models::HostConfig; | 7 | use bollard::models::HostConfig; |
| @@ -17,47 +17,12 @@ pub struct DockerManager { | |||
| 17 | config: Config, | 17 | config: Config, |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | #[derive(Debug, Clone)] | ||
| 21 | pub enum ContainerStatus { | ||
| 22 | Running, | ||
| 23 | Stopped, | ||
| 24 | Starting, | ||
| 25 | NotFound, | ||
| 26 | Error(String), | ||
| 27 | } | ||
| 28 | |||
| 29 | impl DockerManager { | 20 | impl DockerManager { |
| 30 | pub fn new(config: Config) -> Result<Self, bollard::errors::Error> { | 21 | pub fn new(config: Config) -> Result<Self, bollard::errors::Error> { |
| 31 | let client = Docker::connect_with_local_defaults()?; | 22 | let client = Docker::connect_with_local_defaults()?; |
| 32 | Ok(Self { client, config }) | 23 | Ok(Self { client, config }) |
| 33 | } | 24 | } |
| 34 | 25 | ||
| 35 | pub async fn container_status(&self) -> ContainerStatus { | ||
| 36 | let mut filters = HashMap::new(); | ||
| 37 | filters.insert("name".to_string(), vec!["mc".to_string()]); | ||
| 38 | |||
| 39 | let options = ListContainersOptions { | ||
| 40 | all: true, | ||
| 41 | filters, | ||
| 42 | ..Default::default() | ||
| 43 | }; | ||
| 44 | |||
| 45 | match self.client.list_containers(Some(options)).await { | ||
| 46 | Ok(containers) => { | ||
| 47 | if containers.is_empty() { | ||
| 48 | ContainerStatus::NotFound | ||
| 49 | } else { | ||
| 50 | match containers[0].state.as_deref() { | ||
| 51 | Some("running") => ContainerStatus::Running, | ||
| 52 | Some("exited") | Some("stopped") => ContainerStatus::Stopped, | ||
| 53 | _ => ContainerStatus::Starting, | ||
| 54 | } | ||
| 55 | } | ||
| 56 | } | ||
| 57 | Err(e) => ContainerStatus::Error(e.to_string()), | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | pub async fn start_container(&self, instance: &Instance) -> Result<(), String> { | 26 | pub async fn start_container(&self, instance: &Instance) -> Result<(), String> { |
| 62 | tracing::info!("Pulling itzg/minecraft-server:latest image..."); | 27 | tracing::info!("Pulling itzg/minecraft-server:latest image..."); |
| 63 | self.pull_image().await?; | 28 | self.pull_image().await?; |
