@opencode-cloud/core 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +1 -1
- package/package.json +1 -1
- package/src/config/mod.rs +1 -1
- package/src/config/schema.rs +51 -0
- package/src/docker/Dockerfile +1 -1
- package/src/docker/dockerfile.rs +18 -0
- package/src/docker/image.rs +3 -0
- package/src/docker/mod.rs +4 -1
package/Cargo.toml
CHANGED
package/package.json
CHANGED
package/src/config/mod.rs
CHANGED
|
@@ -15,7 +15,7 @@ use anyhow::{Context, Result};
|
|
|
15
15
|
use jsonc_parser::parse_to_serde_value;
|
|
16
16
|
|
|
17
17
|
pub use paths::{get_config_dir, get_config_path, get_data_dir, get_hosts_path, get_pid_path};
|
|
18
|
-
pub use schema::{Config, validate_bind_address};
|
|
18
|
+
pub use schema::{CommitSha, Config, validate_bind_address};
|
|
19
19
|
pub use validation::{
|
|
20
20
|
ValidationError, ValidationWarning, display_validation_error, display_validation_warning,
|
|
21
21
|
validate_config,
|
package/src/config/schema.rs
CHANGED
|
@@ -4,6 +4,50 @@
|
|
|
4
4
|
|
|
5
5
|
use serde::{Deserialize, Serialize};
|
|
6
6
|
use std::net::{IpAddr, Ipv4Addr};
|
|
7
|
+
use std::ops::Deref;
|
|
8
|
+
|
|
9
|
+
/// Validated opencode commit SHA (7-40 hex characters)
|
|
10
|
+
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
|
|
11
|
+
#[serde(transparent)]
|
|
12
|
+
pub struct CommitSha(String);
|
|
13
|
+
|
|
14
|
+
impl CommitSha {
|
|
15
|
+
pub fn parse(value: &str) -> Result<Self, String> {
|
|
16
|
+
let trimmed = value.trim();
|
|
17
|
+
if trimmed.is_empty() {
|
|
18
|
+
return Err("Commit cannot be empty".to_string());
|
|
19
|
+
}
|
|
20
|
+
if !(7..=40).contains(&trimmed.len()) {
|
|
21
|
+
return Err("Commit must be 7-40 hex characters".to_string());
|
|
22
|
+
}
|
|
23
|
+
if !trimmed.chars().all(|c| c.is_ascii_hexdigit()) {
|
|
24
|
+
return Err("Commit must be a hexadecimal SHA".to_string());
|
|
25
|
+
}
|
|
26
|
+
Ok(Self(trimmed.to_string()))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
pub fn as_str(&self) -> &str {
|
|
30
|
+
&self.0
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
impl Deref for CommitSha {
|
|
35
|
+
type Target = str;
|
|
36
|
+
|
|
37
|
+
fn deref(&self) -> &Self::Target {
|
|
38
|
+
self.as_str()
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
impl<'de> Deserialize<'de> for CommitSha {
|
|
43
|
+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
44
|
+
where
|
|
45
|
+
D: serde::Deserializer<'de>,
|
|
46
|
+
{
|
|
47
|
+
let value = String::deserialize(deserializer)?;
|
|
48
|
+
CommitSha::parse(&value).map_err(serde::de::Error::custom)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
7
51
|
|
|
8
52
|
/// Main configuration structure for opencode-cloud
|
|
9
53
|
///
|
|
@@ -112,6 +156,11 @@ pub struct Config {
|
|
|
112
156
|
#[serde(default = "default_image_source")]
|
|
113
157
|
pub image_source: String,
|
|
114
158
|
|
|
159
|
+
/// Override opencode commit used when building the Docker image (optional)
|
|
160
|
+
/// Must be a 7-40 character hex commit SHA.
|
|
161
|
+
#[serde(default)]
|
|
162
|
+
pub opencode_commit: Option<CommitSha>,
|
|
163
|
+
|
|
115
164
|
/// When to check for updates: 'always' (every start), 'once' (once per version), 'never'
|
|
116
165
|
#[serde(default = "default_update_check")]
|
|
117
166
|
pub update_check: String,
|
|
@@ -225,6 +274,7 @@ impl Default for Config {
|
|
|
225
274
|
cockpit_port: default_cockpit_port(),
|
|
226
275
|
cockpit_enabled: default_cockpit_enabled(),
|
|
227
276
|
image_source: default_image_source(),
|
|
277
|
+
opencode_commit: None,
|
|
228
278
|
update_check: default_update_check(),
|
|
229
279
|
mounts: Vec::new(),
|
|
230
280
|
}
|
|
@@ -366,6 +416,7 @@ mod tests {
|
|
|
366
416
|
cockpit_port: 9090,
|
|
367
417
|
cockpit_enabled: true,
|
|
368
418
|
image_source: default_image_source(),
|
|
419
|
+
opencode_commit: None,
|
|
369
420
|
update_check: default_update_check(),
|
|
370
421
|
mounts: Vec::new(),
|
|
371
422
|
};
|
package/src/docker/Dockerfile
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
FROM ubuntu:24.04 AS runtime
|
|
36
36
|
|
|
37
37
|
# Pin opencode fork commit used during build
|
|
38
|
-
ARG OPENCODE_COMMIT=
|
|
38
|
+
ARG OPENCODE_COMMIT=dac099a4892689d11abedb0fcc1098b50e0958c8
|
|
39
39
|
|
|
40
40
|
# OCI Labels for image metadata
|
|
41
41
|
LABEL org.opencontainers.image.title="opencode-cloud"
|
package/src/docker/dockerfile.rs
CHANGED
|
@@ -7,9 +7,27 @@
|
|
|
7
7
|
//! clearly indicate this is the sandboxed container environment that the
|
|
8
8
|
//! opencode-cloud CLI deploys, not the CLI tool itself.
|
|
9
9
|
|
|
10
|
+
use std::collections::HashMap;
|
|
11
|
+
|
|
10
12
|
/// The Dockerfile for building the opencode-cloud-sandbox container image
|
|
11
13
|
pub const DOCKERFILE: &str = include_str!("Dockerfile");
|
|
12
14
|
|
|
15
|
+
/// Build arg name for the opencode commit used in the Dockerfile.
|
|
16
|
+
pub const OPENCODE_COMMIT_BUILD_ARG: &str = "OPENCODE_COMMIT";
|
|
17
|
+
|
|
18
|
+
/// Default opencode commit pinned in the Dockerfile.
|
|
19
|
+
pub const OPENCODE_COMMIT_DEFAULT: &str = "dac099a4892689d11abedb0fcc1098b50e0958c8";
|
|
20
|
+
|
|
21
|
+
/// Build args for overriding the opencode commit in the Dockerfile.
|
|
22
|
+
pub fn build_args_for_opencode_commit(
|
|
23
|
+
maybe_commit: Option<&str>,
|
|
24
|
+
) -> Option<HashMap<String, String>> {
|
|
25
|
+
let commit = maybe_commit?;
|
|
26
|
+
let mut args = HashMap::new();
|
|
27
|
+
args.insert(OPENCODE_COMMIT_BUILD_ARG.to_string(), commit.to_string());
|
|
28
|
+
Some(args)
|
|
29
|
+
}
|
|
30
|
+
|
|
13
31
|
// =============================================================================
|
|
14
32
|
// Docker Image Naming
|
|
15
33
|
// =============================================================================
|
package/src/docker/image.rs
CHANGED
|
@@ -81,6 +81,7 @@ pub async fn build_image(
|
|
|
81
81
|
tag: Option<&str>,
|
|
82
82
|
progress: &mut ProgressReporter,
|
|
83
83
|
no_cache: bool,
|
|
84
|
+
build_args: Option<HashMap<String, String>>,
|
|
84
85
|
) -> Result<String, DockerError> {
|
|
85
86
|
let tag = tag.unwrap_or(IMAGE_TAG_DEFAULT);
|
|
86
87
|
let full_name = format!("{IMAGE_NAME_GHCR}:{tag}");
|
|
@@ -100,6 +101,7 @@ pub async fn build_image(
|
|
|
100
101
|
.unwrap_or_default()
|
|
101
102
|
.as_nanos()
|
|
102
103
|
);
|
|
104
|
+
let build_args = build_args.unwrap_or_default();
|
|
103
105
|
let options = BuildImageOptions {
|
|
104
106
|
t: full_name.clone(),
|
|
105
107
|
dockerfile: "Dockerfile".to_string(),
|
|
@@ -107,6 +109,7 @@ pub async fn build_image(
|
|
|
107
109
|
session: Some(session_id),
|
|
108
110
|
rm: true,
|
|
109
111
|
nocache: no_cache,
|
|
112
|
+
buildargs: build_args,
|
|
110
113
|
..Default::default()
|
|
111
114
|
};
|
|
112
115
|
|
package/src/docker/mod.rs
CHANGED
|
@@ -38,7 +38,10 @@ pub use health::{
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
// Dockerfile constants
|
|
41
|
-
pub use dockerfile::{
|
|
41
|
+
pub use dockerfile::{
|
|
42
|
+
DOCKERFILE, IMAGE_NAME_DOCKERHUB, IMAGE_NAME_GHCR, IMAGE_TAG_DEFAULT,
|
|
43
|
+
OPENCODE_COMMIT_BUILD_ARG, OPENCODE_COMMIT_DEFAULT, build_args_for_opencode_commit,
|
|
44
|
+
};
|
|
42
45
|
|
|
43
46
|
// Image operations
|
|
44
47
|
pub use image::{build_image, image_exists, pull_image};
|