Initialize registry experimental implementation and documentation
This commit is contained in:
commit
ff1e74781d
4 changed files with 101 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/target/
|
||||
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "archipelago-registry"
|
||||
version = "0.0.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.90"
|
||||
publish = false
|
||||
21
README.md
Normal file
21
README.md
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Archipelago registry storage
|
||||
|
||||
Rust module linked into the single `archipelago` binary. Initial commands:
|
||||
|
||||
```
|
||||
archipelago registry init /storage/ostree/layers
|
||||
archipelago registry init /storage/ostree/images
|
||||
archipelago registry verify /storage/ostree/layers
|
||||
```
|
||||
|
||||
Initialization creates native archive-mode repositories with an empty summary.
|
||||
It is idempotent for an existing healthy archive repository and rejects nonempty
|
||||
unrecognized directories, symlink destinations and incompatible repository modes.
|
||||
Administrative operations share a nonblocking OS file lock outside the repository.
|
||||
Use trusted parent directories and the same lock for future publisher operations.
|
||||
`verify` runs native OSTree integrity checks; it does not certify signatures,
|
||||
Archipelago metadata, reproducibility or release eligibility.
|
||||
|
||||
This storage primitive can initialize public empty stores or private staging stores.
|
||||
It does not import artifacts, expose staging, create channels or sign releases.
|
||||
The signed publisher requires the release/trust contracts tracked in RFC-0010.
|
||||
73
src/lib.rs
Normal file
73
src/lib.rs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
//! Native OSTree storage administration. This is not a release publisher.
|
||||
use std::{fs::{self, File, OpenOptions}, path::{Path, PathBuf}, process::Command};
|
||||
|
||||
type Result<T> = std::result::Result<T, String>;
|
||||
|
||||
fn ostree(repo: &Path, args: &[&str]) -> Result<String> {
|
||||
let output = Command::new("ostree").arg(format!("--repo={}", repo.display()))
|
||||
.args(args).env("LC_ALL", "C").output().map_err(|e| e.to_string())?;
|
||||
if !output.status.success() {
|
||||
return Err(format!("ostree {}: {}", args[0], String::from_utf8_lossy(&output.stderr)));
|
||||
}
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
}
|
||||
|
||||
// Lock outside the repository so initialization and subsequent checks serialize.
|
||||
// Administrative paths must be in a trusted directory; no package scripts run here.
|
||||
fn location(path: &str) -> Result<(PathBuf, File)> {
|
||||
let path = Path::new(path);
|
||||
let name = path.file_name().and_then(|s| s.to_str()).ok_or("Repository needs a directory name")?;
|
||||
let parent = path.parent().filter(|p| !p.as_os_str().is_empty()).unwrap_or(Path::new("."));
|
||||
fs::create_dir_all(parent).map_err(|e| e.to_string())?;
|
||||
let parent = fs::canonicalize(parent).map_err(|e| e.to_string())?;
|
||||
let repo = parent.join(name);
|
||||
if fs::symlink_metadata(&repo).is_ok_and(|m| m.file_type().is_symlink()) {
|
||||
return Err("Repository path must not be a symlink".into());
|
||||
}
|
||||
let lock = OpenOptions::new().create(true).truncate(false).read(true).write(true)
|
||||
.open(parent.join(format!(".{name}.archipelago.lock"))).map_err(|e| e.to_string())?;
|
||||
lock.try_lock().map_err(|e| format!("Repository is busy: {e}"))?;
|
||||
Ok((repo, lock))
|
||||
}
|
||||
|
||||
fn archive(repo: &Path) -> Result<()> {
|
||||
let mode = ostree(repo, &["config", "get", "core.mode"])?;
|
||||
if mode != "archive-z2" && mode != "archive" {
|
||||
return Err(format!("HTTP registry requires archive mode, found {mode}"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn init(path: &str) -> Result<()> {
|
||||
let (repo, _lock) = location(path)?;
|
||||
if repo.join("config").exists() {
|
||||
archive(&repo)?;
|
||||
ostree(&repo, &["fsck"])?;
|
||||
println!("Existing archive repository verified: {}", repo.display());
|
||||
return Ok(());
|
||||
}
|
||||
if repo.exists() && fs::read_dir(&repo).map_err(|e| e.to_string())?.next().is_some() {
|
||||
return Err("Refusing to initialize a nonempty non-repository directory".into());
|
||||
}
|
||||
let temporary = repo.with_file_name(format!(".{}.init-{}", repo.file_name().unwrap().to_string_lossy(), std::process::id()));
|
||||
fs::create_dir(&temporary).map_err(|e| e.to_string())?;
|
||||
let result = (|| {
|
||||
ostree(&temporary, &["init", "--mode=archive"])?;
|
||||
ostree(&temporary, &["summary", "--update"])?;
|
||||
ostree(&temporary, &["fsck"])?;
|
||||
fs::rename(&temporary, &repo).map_err(|e| e.to_string())?;
|
||||
File::open(repo.parent().unwrap()).and_then(|f| f.sync_all()).map_err(|e| e.to_string())?;
|
||||
println!("Initialized empty archive repository: {}", repo.display());
|
||||
Ok(())
|
||||
})();
|
||||
if temporary.exists() { let _ = fs::remove_dir_all(&temporary); }
|
||||
result
|
||||
}
|
||||
|
||||
pub fn verify(path: &str) -> Result<()> {
|
||||
let (repo, _lock) = location(path)?;
|
||||
archive(&repo)?;
|
||||
let result = ostree(&repo, &["fsck"])?;
|
||||
println!("{}\nVerified archive repository: {}", result, repo.display());
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue