From 785fc2f7621782a1597b728c5b5e49c41364e85e Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Sat, 16 Dec 2023 20:46:29 -0500 Subject: [PATCH] feat!: Remove legacy code" --- Cargo.toml | 4 +- src/lib.rs | 63 +------------ templates/Containerfile.legacy | 93 ------------------- ...ntainerfile.modules => Containerfile.tera} | 0 4 files changed, 3 insertions(+), 157 deletions(-) delete mode 100644 templates/Containerfile.legacy rename templates/{Containerfile.modules => Containerfile.tera} (100%) diff --git a/Cargo.toml b/Cargo.toml index 5f715f4..de17701 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,7 @@ serde_yaml = "0.9.25" tera = "1.19.1" [features] -default = ["modules"] +default = [] nightly = ["init", "build"] init = [] build = [] -modules = [] -legacy = [] diff --git a/src/lib.rs b/src/lib.rs index f19d0a5..28ab635 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,16 +8,9 @@ //! to use both features at the same time. For now the 'legacy' feature //! is the default feature until modules works 1-1 with ublue starting point. -#[cfg(all(feature = "legacy", feature = "modules"))] -compile_error!("Both 'legacy' and 'modules' features cannot be used at the same time."); - #[cfg(feature = "init")] pub mod init; -#[cfg(feature = "legacy")] -pub mod recipe; - -#[cfg(feature = "modules")] pub mod module_recipe; use std::{ @@ -27,27 +20,15 @@ use std::{ }; use anyhow::Result; -use cfg_if; +use module_recipe::Recipe; use tera::{Context, Tera}; -cfg_if::cfg_if! { - if #[cfg(feature = "legacy")] { - use recipe::Recipe; - use std::fs::read_dir; - pub const DEFAULT_CONTAINERFILE: &str = include_str!("../templates/Containerfile.legacy"); - } else if #[cfg(feature = "modules")] { - use module_recipe::Recipe; - pub const DEFAULT_CONTAINERFILE: &str = include_str!("../templates/Containerfile.modules"); - } -} +pub const DEFAULT_CONTAINERFILE: &str = include_str!("../templates/Containerfile.tera"); pub fn setup_tera(recipe: String, containerfile: Option) -> Result<(Tera, Context)> { let recipe_de = serde_yaml::from_str::(fs::read_to_string(PathBuf::from(&recipe))?.as_str())?; - #[cfg(feature = "legacy")] - let recipe_de = recipe_de.process_repos(); - let mut context = Context::from_serialize(recipe_de)?; context.insert("recipe", &recipe); @@ -65,12 +46,6 @@ pub fn setup_tera(recipe: String, containerfile: Option) -> Result<(Ter |args: &HashMap| -> tera::Result { match args.get("containerfile") { Some(v) => match v.as_str() { - #[cfg(feature = "legacy")] - Some(containerfile) => Ok(read_to_string(format!( - "containerfiles/{containerfile}/Containerfile" - ))? - .into()), - #[cfg(feature = "modules")] Some(containerfile) => Ok(read_to_string(format!( "config/containerfiles/{containerfile}/Containerfile" ))? @@ -82,7 +57,6 @@ pub fn setup_tera(recipe: String, containerfile: Option) -> Result<(Ter }, ); - #[cfg(feature = "modules")] tera.register_function( "print_module_context", |args: &HashMap| -> tera::Result { @@ -97,7 +71,6 @@ pub fn setup_tera(recipe: String, containerfile: Option) -> Result<(Ter }, ); - #[cfg(feature = "modules")] tera.register_function( "get_module_from_file", |args: &HashMap| -> tera::Result { @@ -119,37 +92,5 @@ pub fn setup_tera(recipe: String, containerfile: Option) -> Result<(Ter }, ); - #[cfg(feature = "legacy")] - tera.register_function( - "print_autorun_scripts", - |args: &HashMap| -> tera::Result { - match args.get("mode") { - Some(v) => match from_value::(v.clone()) { - Ok(mode) if mode == "pre" || mode == "post" => { - Ok(read_dir(format!("scripts/{mode}"))? - .fold(String::from(""), |mut acc: String, script| match script { - Ok(entry) => { - let file_name = entry.file_name(); - if let Some(file_name) = file_name.to_str() { - if file_name.ends_with(".sh") { - acc += format!( - "RUN /tmp/scripts/{mode}/{file_name} {mode}\n" - ) - .as_str(); - } - } - acc - } - Err(_) => acc, - }) - .into()) - } - _ => Err("Mode must be pre/post".into()), - }, - None => Err("Need arg 'mode' set with 'pre' or 'post'".into()), - } - }, - ); - Ok((tera, context)) } diff --git a/templates/Containerfile.legacy b/templates/Containerfile.legacy deleted file mode 100644 index 0706640..0000000 --- a/templates/Containerfile.legacy +++ /dev/null @@ -1,93 +0,0 @@ -FROM {{ base_image }}:{{ fedora_version }} - -ARG RECIPE={{ recipe }} - -COPY usr/ /usr - -{% if usr_dir_overlays %} -{% for usr_dir in usr_dir_overlays %} -COPY {{ usr_dir }}/ /usr -{% endfor %} -{% endif %} - -COPY ${RECIPE} /usr/share/ublue-os/recipe.yml - -COPY --from=ghcr.io/ublue-os/bling:latest /rpms/ublue-os-wallpapers-0.1-1.fc38.noarch.rpm /tmp/ublue-os-wallpapers-0.1-1.fc38.noarch.rpm - -COPY --from=ghcr.io/ublue-os/bling:latest /files/usr/share/ublue-os/just /usr/share/ublue-os/just - -COPY --from=ghcr.io/ublue-os/bling:latest /files/usr/bin/ublue-nix* /usr/bin - -COPY --from=docker.io/mikefarah/yq /usr/bin/yq /usr/bin/yq - -COPY --from=gcr.io/projectsigstore/cosign /ko-app/cosign /usr/bin/cosign - -COPY scripts /tmp/scripts -RUN find /tmp/scripts -type f -exec chmod +x {} \; - -{% if containerfiles and containerfiles.pre %} -# Pre: Containerfiles - {% for containerfile in containerfiles.pre %} -{{ print_containerfile(containerfile = containerfile) }} - {% endfor %} -{% endif %} - -{{ print_autorun_scripts(mode = "pre") }} - -{% if scripts and scripts.pre %} -{% for script in scripts.pre %} -RUN /bin/bash -c '/tmp/scripts/{{ script }} pre' -{% endfor %} -{% endif %} - -{% if rpm and rpm.repos %} -{% for repo in rpm.repos %} -RUN wget "{{ repo }}" -P "/etc/yum.repos.d/" -{% endfor %} -{% endif %} - -{% if rpm and rpm.remove %} -RUN rpm-ostree override remove {% for app in rpm.remove %}{{ app }} {% endfor %} -{% endif %} - -ARG FIRSTBOOT_DATA="/usr/share/ublue-os/firstboot" -ARG FIRSTBOOT_LINK="/usr/etc/profile.d/ublue-firstboot.sh" -{% if firstboot.yafti -%} -RUN echo "-- firstboot: Installing and enabling \"yafti\" --"; \ - pip install --prefix=/usr yafti; \ - mkdir -p "$(dirname "${FIRSTBOOT_LINK}")"; \ - ln -s "${FIRSTBOOT_DATA}/launcher/login-profile.sh" "${FIRSTBOOT_LINK}" -ARG YAFTI_FILE="${FIRSTBOOT_DATA}/yafti.yml" -RUN echo "-- yafti: Adding Flatpaks defined in recipe.yml --"; \ - yq -i '.screens.applications.values.groups.Custom.description = "Flatpaks suggested by the image maintainer."' "${YAFTI_FILE}"; \ - yq -i '.screens.applications.values.groups.Custom.default = true' "${YAFTI_FILE}"; \ -{%- for pkg in firstboot.flatpaks %} - echo "Adding to yafti: {{ pkg }}"; \ - yq -i ".screens.applications.values.groups.Custom.packages += [{\"{{ pkg }}\": \"{{ pkg }}\"}]" "${YAFTI_FILE}"; \ -{%- endfor %} - echo "Done setting up Yafti" -{% else %} -RUN echo "-- firstboot: Removing all \"firstboot\" components --"; \ - rm -f "${FIRSTBOOT_LINK}"; \ - rm -rf "${FIRSTBOOT_DATA}" -{% endif %} - -{% if rpm and rpm.install %} -RUN rpm-ostree install {% for app in rpm.install %}{{ app }} {% endfor %} -{% endif %} - -{{ print_autorun_scripts(mode = "post") }} - -{% if scripts and scripts.pre %} -{% for script in scripts.post -%} -RUN /bin/bash -c '/tmp/scripts/{{ script }} post' -{% endfor -%} -{% endif %} - -{% if containerfiles and containerfiles.post %} - {% for containerfile in containerfiles.post %} -{{ print_containerfile(containerfile = containerfile) }} - {% endfor %} -{% endif %} - -RUN rm -rf /tmp/* /var/* && ostree container commit diff --git a/templates/Containerfile.modules b/templates/Containerfile.tera similarity index 100% rename from templates/Containerfile.modules rename to templates/Containerfile.tera