Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl Default for Os and Arch, use in ImageConfiguration::default() #90

Merged
merged 2 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/image/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ impl Default for ImageConfiguration {
Self {
created: Default::default(),
author: Default::default(),
architecture: Arch::Amd64,
os: Os::Linux,
architecture: Default::default(),
os: Default::default(),
os_version: Default::default(),
os_features: Default::default(),
variant: Default::default(),
Expand Down
4 changes: 2 additions & 2 deletions src/image/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ pub struct Platform {
impl Default for Platform {
fn default() -> Self {
Self {
architecture: Arch::Amd64,
os: Os::Linux,
architecture: Default::default(),
os: Default::default(),
os_version: Default::default(),
os_features: Default::default(),
variant: Default::default(),
Expand Down
19 changes: 19 additions & 0 deletions src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ impl<'de> Deserialize<'de> for Os {
}
}

impl Default for Os {
fn default() -> Self {
Os::from(std::env::consts::OS)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spot checked this and it seems like there's enough overlap with what Rust has in https://doc.rust-lang.org/std/env/consts/constant.OS.html and what OCI (really Go I guess) expects.

OK I just got a link to https://github.com/containerd/containerd/blob/140ecc9247386d3be21616fe285021c081f4ea08/platforms/database.go#L83
which seems to be a key player in this.

}
}

/// Name of the CPU target architecture.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Arch {
Expand Down Expand Up @@ -370,3 +376,16 @@ impl<'de> Deserialize<'de> for Arch {
Ok(arch.as_str().into())
}
}

impl Default for Arch {
fn default() -> Self {
// Translate from the Rust architecture names to the Go versions.
// I think the Rust ones are the same as the Linux kernel ones.
let goarch = match std::env::consts::ARCH {
"x86_64" => "amd64",
"aarch64" => "arm64",
saschagrunert marked this conversation as resolved.
Show resolved Hide resolved
o => o,
};
Arch::from(goarch)
}
}