Skip to content

Commit 1c0b6ec

Browse files
project: Use ImageReference from containers_image_proxy
Refactor `struct ImageReference` as an alias to `containers_image_proxy::ImageReference`, also refactor `enum Transport` as Transport from containers_image_proxy Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 53f16e3 commit 1c0b6ec

5 files changed

Lines changed: 10 additions & 126 deletions

File tree

crates/lib/src/bootc_composefs/status.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::{
2525
bls_config::{BLSConfig, BLSConfigType, parse_bls_config},
2626
grub_menuconfig::{MenuEntry, parse_grub_menuentry_file},
2727
},
28-
spec::{BootEntry, BootOrder, Host, HostSpec, ImageReference, ImageStatus},
28+
spec::{BootEntry, BootOrder, Host, HostSpec, ImageStatus},
2929
store::Storage,
3030
utils::{EfiError, read_uefi_var},
3131
};
@@ -501,7 +501,7 @@ fn boot_entry_from_composefs_deployment(
501501
let image = match origin.get::<String>("origin", ORIGIN_CONTAINER) {
502502
Some(img_name_from_config) => {
503503
let ostree_img_ref = OstreeImageReference::from_str(&img_name_from_config)?;
504-
let img_ref = ImageReference::from(ostree_img_ref);
504+
let img_ref = crate::spec::ImageReference::from(ostree_img_ref);
505505

506506
let img_conf = get_imginfo(storage, &verity)?;
507507

crates/ostree-ext/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn parse_imgref(s: &str) -> Result<OstreeImageReference> {
4343

4444
/// Parse a base [`ImageReference`] from a CLI argument.
4545
pub fn parse_base_imgref(s: &str) -> Result<ImageReference> {
46-
ImageReference::try_from(s)
46+
Ok(ImageReference::try_from(s)?)
4747
}
4848

4949
/// Parse an [`ostree::Repo`] from a CLI argument.

crates/ostree-ext/src/container/mod.rs

Lines changed: 3 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -187,34 +187,10 @@ pub(crate) const COMPONENT_SEPARATOR: char = ',';
187187
type Result<T> = anyhow::Result<T>;
188188

189189
/// A backend/transport for OCI/Docker images.
190-
#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq)]
191-
pub enum Transport {
192-
/// A remote Docker/OCI registry (`registry:` or `docker://`)
193-
Registry,
194-
/// A local OCI directory (`oci:`)
195-
OciDir,
196-
/// A local OCI archive tarball (`oci-archive:`)
197-
OciArchive,
198-
/// A local Docker archive tarball (`docker-archive:`)
199-
DockerArchive,
200-
/// Local container storage (`containers-storage:`)
201-
ContainerStorage,
202-
/// Local directory (`dir:`)
203-
Dir,
204-
/// Local Docker daemon (`docker-daemon:`)
205-
DockerDaemon,
206-
}
190+
pub type Transport = containers_image_proxy::transport::Transport;
207191

208192
/// Combination of a remote image reference and transport.
209-
///
210-
/// For example,
211-
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
212-
pub struct ImageReference {
213-
/// The storage and transport for the image
214-
pub transport: Transport,
215-
/// The image name (e.g. `quay.io/somerepo/someimage:latest`)
216-
pub name: String,
217-
}
193+
pub type ImageReference = containers_image_proxy::ImageReference;
218194

219195
/// Policy for signature verification.
220196
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -240,77 +216,6 @@ pub struct OstreeImageReference {
240216
pub imgref: ImageReference,
241217
}
242218

243-
impl TryFrom<&str> for Transport {
244-
type Error = anyhow::Error;
245-
246-
fn try_from(value: &str) -> Result<Self> {
247-
Ok(match value {
248-
Self::REGISTRY_STR | "docker" => Self::Registry,
249-
Self::OCI_STR => Self::OciDir,
250-
Self::OCI_ARCHIVE_STR => Self::OciArchive,
251-
Self::DOCKER_ARCHIVE_STR => Self::DockerArchive,
252-
Self::CONTAINERS_STORAGE_STR => Self::ContainerStorage,
253-
Self::LOCAL_DIRECTORY_STR => Self::Dir,
254-
Self::DOCKER_DAEMON_STR => Self::DockerDaemon,
255-
o => return Err(anyhow!("Unknown transport '{}'", o)),
256-
})
257-
}
258-
}
259-
260-
impl Transport {
261-
const OCI_STR: &'static str = "oci";
262-
const OCI_ARCHIVE_STR: &'static str = "oci-archive";
263-
const DOCKER_ARCHIVE_STR: &'static str = "docker-archive";
264-
const CONTAINERS_STORAGE_STR: &'static str = "containers-storage";
265-
const LOCAL_DIRECTORY_STR: &'static str = "dir";
266-
const REGISTRY_STR: &'static str = "registry";
267-
const DOCKER_DAEMON_STR: &'static str = "docker-daemon";
268-
269-
/// Retrieve an identifier that can then be re-parsed from [`Transport::try_from::<&str>`].
270-
pub fn serializable_name(&self) -> &'static str {
271-
match self {
272-
Transport::Registry => Self::REGISTRY_STR,
273-
Transport::OciDir => Self::OCI_STR,
274-
Transport::OciArchive => Self::OCI_ARCHIVE_STR,
275-
Transport::DockerArchive => Self::DOCKER_ARCHIVE_STR,
276-
Transport::ContainerStorage => Self::CONTAINERS_STORAGE_STR,
277-
Transport::Dir => Self::LOCAL_DIRECTORY_STR,
278-
Transport::DockerDaemon => Self::DOCKER_DAEMON_STR,
279-
}
280-
}
281-
}
282-
283-
impl TryFrom<&str> for ImageReference {
284-
type Error = anyhow::Error;
285-
286-
fn try_from(value: &str) -> Result<Self> {
287-
let (transport_name, mut name) = value
288-
.split_once(':')
289-
.ok_or_else(|| anyhow!("Missing ':' in {}", value))?;
290-
let transport: Transport = transport_name.try_into()?;
291-
if name.is_empty() {
292-
return Err(anyhow!("Invalid empty name in {}", value));
293-
}
294-
if transport_name == "docker" {
295-
name = name
296-
.strip_prefix("//")
297-
.ok_or_else(|| anyhow!("Missing // in docker:// in {}", value))?;
298-
}
299-
Ok(Self {
300-
transport,
301-
name: name.to_string(),
302-
})
303-
}
304-
}
305-
306-
impl FromStr for ImageReference {
307-
type Err = anyhow::Error;
308-
309-
fn from_str(s: &str) -> Result<Self> {
310-
Self::try_from(s)
311-
}
312-
}
313-
314219
impl TryFrom<&str> for SignatureSource {
315220
type Error = anyhow::Error;
316221

@@ -388,28 +293,6 @@ impl FromStr for OstreeImageReference {
388293
}
389294
}
390295

391-
impl std::fmt::Display for Transport {
392-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
393-
let s = match self {
394-
// TODO once skopeo supports this, canonicalize as registry:
395-
Self::Registry => "docker://",
396-
Self::OciArchive => "oci-archive:",
397-
Self::DockerArchive => "docker-archive:",
398-
Self::OciDir => "oci:",
399-
Self::ContainerStorage => "containers-storage:",
400-
Self::Dir => "dir:",
401-
Self::DockerDaemon => "docker-daemon:",
402-
};
403-
f.write_str(s)
404-
}
405-
}
406-
407-
impl std::fmt::Display for ImageReference {
408-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
409-
write!(f, "{}{}", self.transport, self.name)
410-
}
411-
}
412-
413296
impl std::fmt::Display for SignatureSource {
414297
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
415298
match self {
@@ -642,7 +525,7 @@ mod tests {
642525
Transport::DockerArchive,
643526
Transport::OciDir,
644527
] {
645-
assert_eq!(Transport::try_from(v.serializable_name()).unwrap(), v);
528+
assert_eq!(Transport::try_from(v.to_string().as_ref()).unwrap(), v);
646529
}
647530
}
648531

crates/ostree-ext/src/container/store.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,8 +2096,9 @@ fn gc_image_layers_impl(
20962096
let deployment_commits = list_container_deployment_manifests(repo, cancellable)?;
20972097
let all_manifests = all_images
20982098
.into_iter()
2099-
.map(|img| {
2100-
ImageReference::try_from(img.as_str()).and_then(|ir| manifest_for_image(repo, &ir))
2099+
.map(|img| -> Result<_> {
2100+
let ir = ImageReference::try_from(img.as_str())?;
2101+
manifest_for_image(repo, &ir)
21012102
})
21022103
.chain(deployment_commits.into_iter().map(Ok))
21032104
.collect::<Result<Vec<_>>>()?;

crates/ostree-ext/src/repair.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub fn analyze_for_repair(sysroot: &SysrootLock, verbose: bool) -> Result<Repair
183183
let all_images = container_store::list_images(repo)?;
184184
let all_images = all_images
185185
.into_iter()
186-
.map(|img| crate::container::ImageReference::try_from(img.as_str()))
186+
.map(|img| -> Result<_> { Ok(crate::container::ImageReference::try_from(img.as_str())?) })
187187
.collect::<Result<Vec<_>>>()?;
188188
println!("Verifying ostree-container images: {}", all_images.len());
189189
let mut likely_corrupted_container_image_merges = Vec::new();

0 commit comments

Comments
 (0)