Skip to content

Commit

Permalink
feat: Add support for Wolfi (#672)
Browse files Browse the repository at this point in the history
* feat: Add support for Wolfi

This adds support for updating Wolfi via Topgrade

* chore(wolfi): Add os release info and unit test

* chore(wolfi): Don't check ID_LIKE as it is unique
  • Loading branch information
EyeCantCU authored Jan 29, 2024
1 parent 37608a3 commit c311da1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/steps/os/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static OS_RELEASE_PATH: &str = "/etc/os-release";
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Distribution {
Alpine,
Wolfi,
Arch,
Bedrock,
CentOS,
Expand Down Expand Up @@ -52,6 +53,7 @@ impl Distribution {

Ok(match id {
Some("alpine") => Distribution::Alpine,
Some("wolfi") => Distribution::Wolfi,
Some("centos") | Some("rhel") | Some("ol") => Distribution::CentOS,
Some("clear-linux-os") => Distribution::ClearLinux,
Some("fedora") => {
Expand Down Expand Up @@ -136,6 +138,7 @@ impl Distribution {

match self {
Distribution::Alpine => upgrade_alpine_linux(ctx),
Distribution::Wolfi => upgrade_wolfi_linux(ctx),
Distribution::Arch => archlinux::upgrade_arch_linux(ctx),
Distribution::CentOS | Distribution::Fedora => upgrade_redhat(ctx),
Distribution::FedoraImmutable => upgrade_fedora_immutable(ctx),
Expand Down Expand Up @@ -201,6 +204,14 @@ fn upgrade_alpine_linux(ctx: &ExecutionContext) -> Result<()> {
ctx.run_type().execute(sudo).arg(&apk).arg("upgrade").status_checked()
}

fn upgrade_wolfi_linux(ctx: &ExecutionContext) -> Result<()> {
let apk = require("apk")?;
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;

ctx.run_type().execute(sudo).arg(&apk).arg("update").status_checked()?;
ctx.run_type().execute(sudo).arg(&apk).arg("upgrade").status_checked()
}

fn upgrade_redhat(ctx: &ExecutionContext) -> Result<()> {
if let Some(ostree) = which("rpm-ostree") {
if ctx.config().rpm_ostree() {
Expand Down Expand Up @@ -1021,6 +1032,11 @@ mod tests {
);
}

#[test]
fn test_wolfi() {
test_template(include_str!("os_release/wolfi"), Distribution::Wolfi);
}

#[test]
fn test_arch_linux() {
test_template(include_str!("os_release/arch"), Distribution::Arch);
Expand Down
5 changes: 5 additions & 0 deletions src/steps/os/os_release/wolfi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ID=wolfi
NAME="Wolfi"
PRETTY_NAME="Wolfi"
VERSION_ID="20230201"
HOME_URL="https://wolfi.dev"

0 comments on commit c311da1

Please sign in to comment.