Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
python3 \
python3-pip \
python3-venv \
&& rm -rf /var/lib/apt/lists/* \
&& ln -sf /usr/bin/python3 /usr/bin/python3.11 \
&& ln -sf /usr/bin/python3 /usr/bin/python3.12 \
&& ln -sf /usr/bin/python3 /usr/bin/python3.13
&& rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/target/release/ruststack /usr/local/bin/ruststack

Expand Down
46 changes: 20 additions & 26 deletions ruststack-lambda/src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ pub enum ExecutorMode {
Auto,
}

impl ExecutorMode {
pub fn from_str(s: &str) -> Option<Self> {
impl std::str::FromStr for ExecutorMode {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"subprocess" | "process" | "native" => Some(Self::Subprocess),
"docker" | "container" => Some(Self::Docker),
"auto" | "hybrid" => Some(Self::Auto),
_ => None,
"subprocess" | "process" | "native" => Ok(Self::Subprocess),
"docker" | "container" => Ok(Self::Docker),
"auto" | "hybrid" => Ok(Self::Auto),
_ => Err(()),
}
}
}
Expand All @@ -76,6 +78,7 @@ pub fn runtime_image(runtime: &Runtime) -> &'static str {
}

/// Warm container entry
#[allow(dead_code)]
struct WarmContainer {
container_id: String,
function_name: String,
Expand Down Expand Up @@ -242,7 +245,10 @@ impl DockerExecutor {

// Add Lambda-specific env vars
let lambda_env = [
("AWS_LAMBDA_FUNCTION_NAME", function.config.function_name.as_str()),
(
"AWS_LAMBDA_FUNCTION_NAME",
function.config.function_name.as_str(),
),
("AWS_LAMBDA_FUNCTION_VERSION", function.version.as_str()),
(
"AWS_LAMBDA_FUNCTION_MEMORY_SIZE",
Expand Down Expand Up @@ -293,9 +299,7 @@ impl DockerExecutor {
return Err(DockerError::StartFailed(stderr.to_string()));
}

let container_id = String::from_utf8_lossy(&output.stdout)
.trim()
.to_string();
let container_id = String::from_utf8_lossy(&output.stdout).trim().to_string();

info!(
container_id = %container_id,
Expand Down Expand Up @@ -468,14 +472,7 @@ except Exception as e:
let output = tokio::time::timeout(
Duration::from_secs(timeout_secs),
Command::new("docker")
.args([
"exec",
"-i",
&container_id,
"python3",
"-c",
&invoke_script,
])
.args(["exec", "-i", &container_id, "python3", "-c", &invoke_script])
.output(),
)
.await;
Expand Down Expand Up @@ -576,15 +573,12 @@ mod tests {

#[test]
fn test_executor_mode_from_str() {
assert_eq!("docker".parse::<ExecutorMode>(), Ok(ExecutorMode::Docker));
assert_eq!(
ExecutorMode::from_str("docker"),
Some(ExecutorMode::Docker)
);
assert_eq!(
ExecutorMode::from_str("subprocess"),
Some(ExecutorMode::Subprocess)
"subprocess".parse::<ExecutorMode>(),
Ok(ExecutorMode::Subprocess)
);
assert_eq!(ExecutorMode::from_str("auto"), Some(ExecutorMode::Auto));
assert_eq!(ExecutorMode::from_str("invalid"), None);
assert_eq!("auto".parse::<ExecutorMode>(), Ok(ExecutorMode::Auto));
assert!("invalid".parse::<ExecutorMode>().is_err());
}
}
6 changes: 5 additions & 1 deletion ruststack-lambda/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ pub struct LambdaState {
}

impl LambdaState {
#[allow(dead_code)]
pub fn new() -> Self {
Self {
service: LambdaService::new(),
}
}

pub fn new_with_config(executor_mode: ExecutorMode, docker_config: DockerExecutorConfig) -> Self {
pub fn new_with_config(
executor_mode: ExecutorMode,
docker_config: DockerExecutorConfig,
) -> Self {
Self {
service: LambdaService::with_mode_and_config(executor_mode, docker_config),
}
Expand Down
6 changes: 4 additions & 2 deletions ruststack/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ async fn main() -> anyhow::Result<()> {
.init();

// Parse Lambda executor mode
let lambda_executor = ruststack_lambda::ExecutorMode::from_str(&args.lambda_executor)
.unwrap_or_else(|| {
let lambda_executor = args
.lambda_executor
.parse::<ruststack_lambda::ExecutorMode>()
.unwrap_or_else(|_| {
tracing::warn!(
"Unknown lambda executor '{}', defaulting to subprocess",
args.lambda_executor
Expand Down
1 change: 1 addition & 0 deletions ruststack/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub struct AppState {
}

impl AppState {
#[allow(dead_code)]
pub fn new(s3_enabled: bool, dynamodb_enabled: bool, lambda_enabled: bool) -> Self {
Self::new_with_lambda_config(
s3_enabled,
Expand Down
Loading