Fix recipe and templates

This commit is contained in:
Gerald Pinder 2023-10-06 23:59:10 -04:00
parent c415f6a90a
commit 8668a7a442
2 changed files with 29 additions and 17 deletions

View file

@ -10,47 +10,53 @@ pub struct Recipe {
#[serde(alias = "fedora-version")] #[serde(alias = "fedora-version")]
pub fedora_version: u16, pub fedora_version: u16,
pub scripts: Scripts, pub scripts: Option<Scripts>,
pub rpm: Rpm, pub rpm: Option<Rpm>,
#[serde(alias = "usr-dir-overlays")] #[serde(alias = "usr-dir-overlays")]
pub usr_dir_overlays: Option<Vec<String>>, pub usr_dir_overlays: Option<Vec<String>>,
pub containerfiles: Option<Containerfiles>, pub containerfiles: Option<Containerfiles>,
pub firstboot: FirstBoot, pub firstboot: Option<FirstBoot>,
} }
impl Recipe { impl Recipe {
pub fn process_repos(mut self) -> Self { pub fn process_repos(mut self) -> Self {
self.rpm.repos = self if let Some(rpm) = &mut self.rpm {
.rpm if let Some(repos) = &rpm.repos {
.repos rpm.repos = Some(
.iter() repos
.map(|s| s.replace("%FEDORA_VERSION%", self.fedora_version.to_string().as_str())) .iter()
.collect(); .map(|s| {
s.replace("%FEDORA_VERSION%", self.fedora_version.to_string().as_str())
})
.collect(),
);
}
}
self self
} }
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct Scripts { pub struct Scripts {
pub pre: Vec<String>, pub pre: Option<Vec<String>>,
pub post: Vec<String>, pub post: Option<Vec<String>>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct Rpm { pub struct Rpm {
pub repos: Vec<String>, pub repos: Option<Vec<String>>,
pub install: Vec<String>, pub install: Option<Vec<String>>,
pub remove: Vec<String>, pub remove: Option<Vec<String>>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct FirstBoot { pub struct FirstBoot {
pub yafti: bool, pub yafti: bool,
pub flatpaks: Vec<String>, pub flatpaks: Option<Vec<String>>,
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]

View file

@ -34,15 +34,19 @@ RUN find /tmp/scripts -type f -exec chmod +x {} \;
{{ print_autorun_scripts(mode = "pre") }} {{ print_autorun_scripts(mode = "pre") }}
{% if scripts and scripts.pre %}
{% for script in scripts.pre %} {% for script in scripts.pre %}
RUN /bin/bash -c '/tmp/scripts/{{ script }} pre' RUN /bin/bash -c '/tmp/scripts/{{ script }} pre'
{% endfor %} {% endfor %}
{% endif %}
{% if rpm and rpm.repos %}
{% for repo in rpm.repos %} {% for repo in rpm.repos %}
RUN wget "{{ repo }}" -P "/etc/yum.repos.d/" RUN wget "{{ repo }}" -P "/etc/yum.repos.d/"
{% endfor %} {% endfor %}
{% endif %}
{% if rpm.remove %} {% if rpm and rpm.remove %}
RUN rpm-ostree override remove {% for app in rpm.remove %}{{ app }} {% endfor %} RUN rpm-ostree override remove {% for app in rpm.remove %}{{ app }} {% endfor %}
{% endif %} {% endif %}
@ -68,15 +72,17 @@ RUN echo "-- firstboot: Removing all \"firstboot\" components --"; \
rm -rf "${FIRSTBOOT_DATA}" rm -rf "${FIRSTBOOT_DATA}"
{% endif %} {% endif %}
{% if rpm.install %} {% if rpm and rpm.install %}
RUN rpm-ostree install {% for app in rpm.install %}{{ app }} {% endfor %} RUN rpm-ostree install {% for app in rpm.install %}{{ app }} {% endfor %}
{% endif %} {% endif %}
{{ print_autorun_scripts(mode = "post") }} {{ print_autorun_scripts(mode = "post") }}
{% if scripts and scripts.pre %}
{% for script in scripts.post -%} {% for script in scripts.post -%}
RUN /bin/bash -c '/tmp/scripts/{{ script }} post' RUN /bin/bash -c '/tmp/scripts/{{ script }} post'
{% endfor -%} {% endfor -%}
{% endif %}
{% if containerfiles and containerfiles.post %} {% if containerfiles and containerfiles.post %}
{% for containerfile in containerfiles.post %} {% for containerfile in containerfiles.post %}