Skip to content

Commit

Permalink
oci-cli-wrapper: remove system-supplied OCI tool support
Browse files Browse the repository at this point in the history
With support for krane bundled with twoliter, these codepaths are at
risk of succumbing to bitrot. We will remove them in favor of providing
the functionality ourselves.
  • Loading branch information
cbgbt committed Oct 8, 2024
1 parent acfc016 commit c8a787c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 200 deletions.
148 changes: 0 additions & 148 deletions tools/oci-cli-wrapper/src/docker.rs

This file was deleted.

45 changes: 2 additions & 43 deletions tools/oci-cli-wrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,27 @@
//! metadata. In addition, in order to operate with OCI image format, the containerd-snapshotter
//! feature has to be enabled in the docker daemon
use std::fmt::{Display, Formatter};
use std::{collections::HashMap, env, path::Path};
use std::{collections::HashMap, path::Path};

use async_trait::async_trait;
use cli::CommandLine;
use crane::CraneCLI;
use docker::DockerCLI;
use krane_bundle::KRANE;
use olpc_cjson::CanonicalFormatter;
use serde::{Deserialize, Serialize};
use snafu::ResultExt;
use which::which;

mod cli;
mod crane;
mod docker;

#[derive(Debug)]
pub struct ImageTool {
image_tool_impl: Box<dyn ImageToolImpl>,
}

impl ImageTool {
/// Uses the container tool specified by the given tool name.
///
/// The specified tool must be present in the unix search path.
fn from_tool_name(tool_name: &str) -> Result<Self> {
let image_tool_impl: Box<dyn ImageToolImpl> = match tool_name {
"docker" => Box::new(DockerCLI {
cli: CommandLine {
path: which("docker").context(error::NotFoundSnafu { name: "docker" })?,
},
}),
tool @ ("crane" | "gcrane" | "krane") => Box::new(CraneCLI {
cli: CommandLine {
path: which(tool).context(error::NotFoundSnafu { name: tool })?,
},
}),
_ => return error::UnsupportedSnafu { name: tool_name }.fail(),
};

Ok(Self { image_tool_impl })
}

/// Uses the builtin `krane` provided by the `tools/krane` crate.
fn from_builtin_krane() -> Self {
pub fn from_builtin_krane() -> Self {
let image_tool_impl = Box::new(CraneCLI {
cli: CommandLine {
path: KRANE.path().to_path_buf(),
Expand All @@ -65,23 +41,6 @@ impl ImageTool {
Self { image_tool_impl }
}

/// Auto-select the container tool to use by environment variable
/// and-or auto detection.
///
/// By default, uses a bundled `krane` from go-containerregistry.
///
/// If TWOLITER_KIT_IMAGE_TOOL environment variable is set, uses that value instead.
/// Valid values are:
/// * docker
/// * crane | gcrane | krane
pub fn from_environment() -> Result<Self> {
if let Ok(name) = env::var("TWOLITER_KIT_IMAGE_TOOL") {
Self::from_tool_name(&name)
} else {
Ok(Self::from_builtin_krane())
}
}

pub fn new(image_tool_impl: Box<dyn ImageToolImpl>) -> Self {
Self { image_tool_impl }
}
Expand Down
7 changes: 1 addition & 6 deletions tools/pubsys/src/kit/publish_kit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) struct PublishKitArgs {
}

pub(crate) async fn run(args: &Args, publish_kit_args: &PublishKitArgs) -> Result<()> {
let image_tool = ImageTool::from_environment().context(error::ImageToolSnafu)?;
let image_tool = ImageTool::from_builtin_krane();

// If a lock file exists, use that, otherwise use Infra.toml
let infra_config = InfraConfig::from_path_or_lock(&args.infra_config_path, false)
Expand Down Expand Up @@ -137,11 +137,6 @@ mod error {
#[snafu(display("Error reading config: {}", source))]
Config { source: pubsys_config::Error },

#[snafu(display("Could not find image tool: {}", source))]
ImageTool {
source: oci_cli_wrapper::error::Error,
},

#[snafu(display("Could not convert {} to docker architecture: {}", arch, source))]
InvalidArchitecture {
source: oci_cli_wrapper::error::Error,
Expand Down
6 changes: 3 additions & 3 deletions twoliter/src/project/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl LockedSDK {
};

debug!(?sdk, "Resolving workspace SDK");
let image_tool = ImageTool::from_environment()?;
let image_tool = ImageTool::from_builtin_krane();
ImageResolver::from_image(&sdk)?
.skip_metadata_retrieval() // SDKs don't have metadata
.resolve(&image_tool)
Expand Down Expand Up @@ -203,7 +203,7 @@ impl Lock {
/// Fetches all external kits defined in a Twoliter.lock to the build directory
#[instrument(level = "trace", skip_all)]
pub(crate) async fn fetch(&self, project: &Project<Locked>, arch: &str) -> Result<()> {
let image_tool = ImageTool::from_environment()?;
let image_tool = ImageTool::from_builtin_krane();
let target_dir = project.external_kits_dir();
create_dir_all(&target_dir).await.context(format!(
"failed to create external-kits directory at {}",
Expand Down Expand Up @@ -257,7 +257,7 @@ impl Lock {
async fn resolve(project: &Project<Unlocked>) -> Result<Self> {
let mut known: HashMap<(ValidIdentifier, ValidIdentifier), Version> = HashMap::new();
let mut locked: Vec<LockedImage> = Vec::new();
let image_tool = ImageTool::from_environment()?;
let image_tool = ImageTool::from_builtin_krane();
let mut remaining = project.direct_kit_deps()?;

let mut sdk_set = HashSet::new();
Expand Down

0 comments on commit c8a787c

Please sign in to comment.