opencode_cloud_core/docker/
mod.rs1mod client;
13pub mod container;
14mod dockerfile;
15mod error;
16pub mod image;
17pub mod progress;
18pub mod volume;
19
20pub use client::DockerClient;
22pub use error::DockerError;
23pub use progress::ProgressReporter;
24
25pub use dockerfile::{DOCKERFILE, IMAGE_NAME_DOCKERHUB, IMAGE_NAME_GHCR, IMAGE_TAG_DEFAULT};
27
28pub use image::{build_image, image_exists, pull_image};
30
31pub use volume::{
33 MOUNT_CONFIG, MOUNT_PROJECTS, MOUNT_SESSION, VOLUME_CONFIG, VOLUME_NAMES, VOLUME_PROJECTS,
34 VOLUME_SESSION, ensure_volumes_exist, remove_all_volumes, remove_volume, volume_exists,
35};
36
37pub use container::{
39 CONTAINER_NAME, OPENCODE_WEB_PORT, container_exists, container_is_running, container_state,
40 create_container, remove_container, start_container, stop_container,
41};
42
43pub async fn setup_and_start(
53 client: &DockerClient,
54 opencode_web_port: Option<u16>,
55 env_vars: Option<Vec<String>>,
56) -> Result<String, DockerError> {
57 volume::ensure_volumes_exist(client).await?;
59
60 let container_id = if container::container_exists(client, container::CONTAINER_NAME).await? {
62 let info = client
64 .inner()
65 .inspect_container(container::CONTAINER_NAME, None)
66 .await
67 .map_err(|e| {
68 DockerError::Container(format!("Failed to inspect existing container: {}", e))
69 })?;
70 info.id
71 .unwrap_or_else(|| container::CONTAINER_NAME.to_string())
72 } else {
73 container::create_container(client, None, None, opencode_web_port, env_vars).await?
75 };
76
77 if !container::container_is_running(client, container::CONTAINER_NAME).await? {
79 container::start_container(client, container::CONTAINER_NAME).await?;
80 }
81
82 Ok(container_id)
83}
84
85pub async fn stop_service(client: &DockerClient, remove: bool) -> Result<(), DockerError> {
91 let name = container::CONTAINER_NAME;
92
93 if !container::container_exists(client, name).await? {
95 return Err(DockerError::Container(format!(
96 "Container '{}' does not exist",
97 name
98 )));
99 }
100
101 if container::container_is_running(client, name).await? {
103 container::stop_container(client, name, None).await?;
104 }
105
106 if remove {
108 container::remove_container(client, name, false).await?;
109 }
110
111 Ok(())
112}