feat!: Remove legacy code"
This commit is contained in:
parent
006966bb35
commit
785fc2f762
4 changed files with 3 additions and 157 deletions
|
|
@ -20,9 +20,7 @@ serde_yaml = "0.9.25"
|
||||||
tera = "1.19.1"
|
tera = "1.19.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["modules"]
|
default = []
|
||||||
nightly = ["init", "build"]
|
nightly = ["init", "build"]
|
||||||
init = []
|
init = []
|
||||||
build = []
|
build = []
|
||||||
modules = []
|
|
||||||
legacy = []
|
|
||||||
|
|
|
||||||
63
src/lib.rs
63
src/lib.rs
|
|
@ -8,16 +8,9 @@
|
||||||
//! to use both features at the same time. For now the 'legacy' feature
|
//! 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.
|
//! 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")]
|
#[cfg(feature = "init")]
|
||||||
pub mod init;
|
pub mod init;
|
||||||
|
|
||||||
#[cfg(feature = "legacy")]
|
|
||||||
pub mod recipe;
|
|
||||||
|
|
||||||
#[cfg(feature = "modules")]
|
|
||||||
pub mod module_recipe;
|
pub mod module_recipe;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
|
@ -27,27 +20,15 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use cfg_if;
|
use module_recipe::Recipe;
|
||||||
use tera::{Context, Tera};
|
use tera::{Context, Tera};
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
pub const DEFAULT_CONTAINERFILE: &str = include_str!("../templates/Containerfile.tera");
|
||||||
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 fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Tera, Context)> {
|
pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Tera, Context)> {
|
||||||
let recipe_de =
|
let recipe_de =
|
||||||
serde_yaml::from_str::<Recipe>(fs::read_to_string(PathBuf::from(&recipe))?.as_str())?;
|
serde_yaml::from_str::<Recipe>(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)?;
|
let mut context = Context::from_serialize(recipe_de)?;
|
||||||
context.insert("recipe", &recipe);
|
context.insert("recipe", &recipe);
|
||||||
|
|
||||||
|
|
@ -65,12 +46,6 @@ pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Ter
|
||||||
|args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
|
|args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
|
||||||
match args.get("containerfile") {
|
match args.get("containerfile") {
|
||||||
Some(v) => match v.as_str() {
|
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!(
|
Some(containerfile) => Ok(read_to_string(format!(
|
||||||
"config/containerfiles/{containerfile}/Containerfile"
|
"config/containerfiles/{containerfile}/Containerfile"
|
||||||
))?
|
))?
|
||||||
|
|
@ -82,7 +57,6 @@ pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Ter
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "modules")]
|
|
||||||
tera.register_function(
|
tera.register_function(
|
||||||
"print_module_context",
|
"print_module_context",
|
||||||
|args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
|
|args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
|
||||||
|
|
@ -97,7 +71,6 @@ pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Ter
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "modules")]
|
|
||||||
tera.register_function(
|
tera.register_function(
|
||||||
"get_module_from_file",
|
"get_module_from_file",
|
||||||
|args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
|
|args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
|
||||||
|
|
@ -119,37 +92,5 @@ pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Ter
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "legacy")]
|
|
||||||
tera.register_function(
|
|
||||||
"print_autorun_scripts",
|
|
||||||
|args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
|
|
||||||
match args.get("mode") {
|
|
||||||
Some(v) => match from_value::<String>(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))
|
Ok((tera, context))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue