refactor: remove rustainers and passwd crates

Image testing has been migrated to goss in docker-nova-ssh repository.
Remove the custom Rust-based testing infrastructure:
- crates/rustainers/ - Docker container testing library
- crates/passwd/ - Unix passwd file parser
- tests/image_tests.rs - nova-ssh image tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Mohammed Naser <mnaser@vexxhost.com>
This commit is contained in:
Mohammed NaserandClaude Opus 4.5 committed 2025-12-14 00:27:24 -05:00
1 parent 049e489387
commit 15bd481d74
7 files changed
+296 -2049

No files matched your search

Generated
+294 -1665
View File
File diff suppressed because it is too large. Load diff
+2 -11
View File
@@ -1,12 +1,3 @@
[package]
name = "atmosphere"
edition = "2021"
[dependencies]
tokio = { version = "1.43.0", features = ["fs", "macros", "rt-multi-thread"] }
[dev-dependencies]
rustainers = { path = "crates/rustainers" }
[workspace]
members = [ "crates/*" ]
members = ["crates/*"]
resolver = "2"
-7
View File
@@ -1,7 +0,0 @@
[package]
name = "passwd"
version = "0.1.0"
edition = "2021"
[dependencies]
thiserror = "2.0.11"
-81
View File
@@ -1,81 +0,0 @@
use std::num::ParseIntError;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum PasswdEntryError {
#[error("Failed to parse ID: {0}")]
FailedToParseID(#[from] ParseIntError),
#[error("Invalid passwd entry: {0}")]
InvalidPasswdEntry(String),
}
#[derive(Debug, Clone)]
pub struct PasswdEntry {
pub name: String,
pub passwd: String,
pub uid: u32,
pub gid: u32,
pub gecos: String,
pub dir: String,
pub shell: String,
}
impl PasswdEntry {
pub fn from_line(line: &str) -> Result<PasswdEntry, PasswdEntryError> {
let parts: Vec<&str> = line.split(":").map(|part| part.trim()).collect();
if parts.len() != 7 {
return Err(PasswdEntryError::InvalidPasswdEntry(line.to_string()));
}
Ok(PasswdEntry {
name: parts[0].to_string(),
passwd: parts[1].to_string(),
uid: parts[2].parse()?,
gid: parts[3].parse()?,
gecos: parts[4].to_string(),
dir: parts[5].to_string(),
shell: parts[6].to_string(),
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_from_line_valid() {
let line = "username:x:1000:1000:User Name:/home/username:/bin/bash";
let entry = PasswdEntry::from_line(line).unwrap();
assert_eq!(entry.name, "username");
assert_eq!(entry.passwd, "x");
assert_eq!(entry.uid, 1000);
assert_eq!(entry.gid, 1000);
assert_eq!(entry.gecos, "User Name");
assert_eq!(entry.dir, "/home/username");
assert_eq!(entry.shell, "/bin/bash");
}
#[test]
fn test_from_line_invalid_uid() {
let line = "username:x:invalid:1000:User Name:/home/username:/bin/bash";
let result = PasswdEntry::from_line(line);
assert!(result.is_err());
}
#[test]
fn test_from_line_invalid_gid() {
let line = "username:x:1000:invalid:User Name:/home/username:/bin/bash";
let result = PasswdEntry::from_line(line);
assert!(result.is_err());
}
#[test]
fn test_from_line_missing_fields() {
let line = "username:x:1000:1000:User Name:/home/username";
let result = PasswdEntry::from_line(line);
assert!(result.is_err());
}
}
-14
View File
@@ -1,14 +0,0 @@
[package]
name = "rustainers"
version = "0.1.0"
edition = "2021"
[dependencies]
bollard = "0.18.1"
bytes = "1.10.0"
futures-util = "0.3.31"
rand = "0.8"
tar = "0.4.43"
thiserror = "2.0.11"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
passwd = { path = "../passwd" }
-250
View File
@@ -1,250 +0,0 @@
extern crate tar;
use bollard::Docker;
use bollard::container::{Config, CreateContainerOptions, StartContainerOptions};
use bollard::exec::{CreateExecOptions, StartExecResults};
use bytes::{BufMut, BytesMut};
use futures_util::TryStreamExt;
use futures_util::stream::StreamExt;
use passwd::PasswdEntry;
use rand::Rng;
use std::collections::HashMap;
use std::io::Read;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum DockerContainerGuardError {
#[error("Docker API error: {0}")]
DockerError(#[from] bollard::errors::Error),
#[error("File not found: {0}")]
FileNotFound(String),
#[error("Failed to extract file: {0}")]
FileExtractionFailed(#[from] std::io::Error),
#[error("Too many files in tarball")]
TooManyFilesInTarball,
#[error("Failed to parse password entry: {0}")]
FailedToParsePasswdEntry(#[from] passwd::PasswdEntryError),
#[error("User not found: {0}")]
UserNotFound(String),
}
#[derive(Debug)]
pub struct DockerContainerGuard {
pub id: String,
pub image: String,
docker: Docker,
}
impl DockerContainerGuard {
// Spawns a new container using Bollard.
//
// The container is automatically cleaned up when the guard goes out of scope.
pub async fn spawn(image_name: &str) -> Result<Self, DockerContainerGuardError> {
let docker = Docker::connect_with_local_defaults()?;
let container_name: String = rand::thread_rng()
.sample_iter(&rand::distributions::Alphanumeric)
.take(10)
.map(char::from)
.collect();
docker
.create_image(
Some(bollard::image::CreateImageOptions {
from_image: image_name,
..Default::default()
}),
None,
None,
)
.try_collect::<Vec<_>>()
.await?;
let container = docker
.create_container(
Some(CreateContainerOptions {
name: container_name,
..Default::default()
}),
Config {
image: Some(image_name),
cmd: Some(vec!["sh"]),
tty: Some(true),
..Default::default()
},
)
.await?;
docker
.start_container(&container.id, None::<StartContainerOptions<String>>)
.await?;
Ok(Self {
id: container.id,
image: image_name.to_string(),
docker,
})
}
/// Executes a command inside the container using Bollard.
///
/// Returns the output as a String.
pub async fn exec(&self, cmd: Vec<&str>) -> Result<String, bollard::errors::Error> {
let exec_instance = self
.docker
.create_exec(
&self.id,
CreateExecOptions {
attach_stdout: Some(true),
attach_stderr: Some(true),
cmd: Some(cmd.iter().map(|s| s.to_string()).collect()),
..Default::default()
},
)
.await?;
let start_exec_result = self.docker.start_exec(&exec_instance.id, None).await?;
if let StartExecResults::Attached {
output: out_stream, ..
} = start_exec_result
{
let output = out_stream
.filter_map(|chunk| async {
match chunk {
Ok(bollard::container::LogOutput::StdOut { message })
| Ok(bollard::container::LogOutput::StdErr { message }) => {
Some(String::from_utf8_lossy(&message).to_string())
}
_ => None,
}
})
.fold(String::new(), |mut acc, item| async move {
acc.push_str(&item);
acc
})
.await;
return Ok(output);
}
Ok(String::new())
}
// Read a file from the container.
pub async fn read_file(&self, path: &str) -> Result<String, DockerContainerGuardError> {
let bytes = self
.docker
.download_from_container::<String>(
&self.id,
Some(bollard::container::DownloadFromContainerOptions { path: path.into() }),
)
.try_fold(BytesMut::new(), |mut bytes, b| async move {
bytes.put(b);
Ok(bytes)
})
.await?;
if bytes.is_empty() {
return Err(DockerContainerGuardError::FileNotFound(path.into()));
}
if let Some(file) = (tar::Archive::new(&bytes[..]).entries()?).next() {
let mut s = String::new();
file?.read_to_string(&mut s).unwrap();
return Ok(s);
}
Err(DockerContainerGuardError::FileNotFound(path.into()))
}
// Get a HashMap of all users in the container.
pub async fn get_users(
&self,
) -> Result<HashMap<String, PasswdEntry>, DockerContainerGuardError> {
let output = self.read_file("/etc/passwd").await?;
output
.lines()
.map(|line| {
PasswdEntry::from_line(line)
.map(|entry| (entry.name.clone(), entry))
.map_err(DockerContainerGuardError::from)
})
.collect()
}
// Get a specific user from the container.
pub async fn get_user(&self, name: &str) -> Result<PasswdEntry, DockerContainerGuardError> {
let users = self.get_users().await?;
let user = users
.get(name)
.ok_or_else(|| DockerContainerGuardError::UserNotFound(name.into()))?;
Ok(user.clone())
}
}
impl Drop for DockerContainerGuard {
fn drop(&mut self) {
let docker = self.docker.clone();
let container_id = self.id.clone();
tokio::spawn(async move {
docker
.remove_container(
&container_id,
Some(bollard::container::RemoveContainerOptions {
force: true,
..Default::default()
}),
)
.await
});
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_container_exec() -> Result<(), DockerContainerGuardError> {
let guard =
DockerContainerGuard::spawn("registry.atmosphere.dev/docker.io/library/alpine:latest")
.await?;
let output = guard.exec(vec!["echo", "hello from container"]).await?;
assert!(output.contains("hello from container"));
Ok(())
}
#[tokio::test]
async fn test_container_read_file() -> Result<(), DockerContainerGuardError> {
let guard =
DockerContainerGuard::spawn("registry.atmosphere.dev/docker.io/library/alpine:latest")
.await?;
let file = guard.read_file("/usr/lib/os-release").await?;
assert!(file.len() > 0);
Ok(())
}
#[tokio::test]
async fn test_container_get_user() -> Result<(), DockerContainerGuardError> {
let guard =
DockerContainerGuard::spawn("registry.atmosphere.dev/docker.io/library/alpine:latest")
.await?;
let user = guard.get_user("root").await?;
assert_eq!(user.name, "root");
Ok(())
}
}
-21
View File
@@ -1,21 +0,0 @@
use rustainers::DockerContainerGuard;
use rustainers::DockerContainerGuardError;
use std::env;
#[tokio::test]
async fn test_nova_ssh() -> Result<(), DockerContainerGuardError> {
let guard = DockerContainerGuard::spawn(&format!(
"{}/nova-ssh:{}",
env::var("REGISTRY").unwrap_or_else(|_| "harbor.atmosphere.dev/library".to_string()),
env::var("TAG").unwrap_or_else(|_| "main".to_string())
))
.await?;
let user = guard.get_user("nova").await?;
assert_eq!(user.uid, 42424);
assert_eq!(user.gid, 42424);
assert_eq!(user.dir, "/var/lib/nova");
assert_eq!(user.shell, "/bin/bash");
Ok(())
}