Making some progress

This commit is contained in:
Gerald Pinder 2023-09-25 23:14:15 -04:00
parent 783c53ebb8
commit 5361b36238
3 changed files with 22 additions and 11 deletions

View file

@ -2,7 +2,8 @@ use std::{fs, io, path::PathBuf};
use anyhow::Result; use anyhow::Result;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use ublue_rs::Recipe; use tera::{Context, Tera};
use ublue_rs::{Recipe, DEFAULT_CONTAINERFILE};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(name = "Ublue Builder", author, version, about, long_about = None)] #[command(name = "Ublue Builder", author, version, about, long_about = None)]
@ -40,7 +41,11 @@ fn main() -> Result<()> {
containerfile, containerfile,
} => { } => {
let recipe: Recipe = serde_yaml::from_str(fs::read_to_string(recipe)?.as_str())?; let recipe: Recipe = serde_yaml::from_str(fs::read_to_string(recipe)?.as_str())?;
println!("{:#?}", recipe); println!("{:#?}", &recipe);
let context = Context::from_serialize(recipe)?;
dbg!(&context);
let output = Tera::one_off(DEFAULT_CONTAINERFILE, &context, true)?;
println!("{output}");
} }
CommandArgs::Build { containerfile } => { CommandArgs::Build { containerfile } => {
println!("Not yet implemented!"); println!("Not yet implemented!");

View file

@ -18,9 +18,9 @@ pub struct Recipe {
pub rpm: Rpm, pub rpm: Rpm,
#[serde(rename = "usr-dir-overlays")] #[serde(rename = "usr-dir-overlays")]
pub usr_dir_overlays: Vec<String>, pub usr_dir_overlays: Option<Vec<String>>,
pub containerfiles: Containerfiles, pub containerfiles: Option<Containerfiles>,
pub firstboot: FirstBoot, pub firstboot: FirstBoot,
} }

View file

@ -4,9 +4,11 @@ ARG RECIPE={{ recipe }}
COPY usr/ /usr COPY usr/ /usr
{% if usr_dir_overlays %}
{% for usr_dir in usr_dir_overlays %} {% for usr_dir in usr_dir_overlays %}
COPY {{ usr_dir }}/ /usr COPY {{ usr_dir }}/ /usr
{% endfor %} {% endfor %}
{% endif %}
COPY ${RECIPE} /usr/share/ublue-os/recipe.yml COPY ${RECIPE} /usr/share/ublue-os/recipe.yml
@ -22,16 +24,18 @@ COPY --from=gcr.io/projectsigstore/cosign /ko-app/cosign /usr/bin/cosign
COPY scripts /tmp/scripts COPY scripts /tmp/scripts
{% if continerfiles %}
{% for containerfile in containerfiles.pre %} {% for containerfile in containerfiles.pre %}
{{ print_containerfile(containerfile) }} {{ print_containerfile(containerfile = containerfile) }}
{% endfor %} {% endfor %}
{% endif %}
{% for script in scripts.pre %} {% for script in scripts.pre %}
RUN chmod +x /tmp/scripts/{{ script }} && /tmp/scripts/{{ script }} RUN chmod +x /tmp/scripts/{{ script }} && /tmp/scripts/{{ script }}
{% endfor %} {% endfor %}
{% for repo in rpm.repo %} {% for repo in rpm.repo %}
RUN wget "${{{ repo }}//%FEDORA_VERSION%/{{ fedora_verison }}}" -P "/etc/yum.repos.d/" RUN wget {% raw %}"${{% endraw %}{{ repo }}//%FEDORA_VERSION%/{{ fedora_verison }}{% raw %}}"{% endraw %} -P "/etc/yum.repos.d/"
{% endfor %} {% endfor %}
RUN rpm-ostree uninstall {% for app in rpm.remove %}{{ app }}{% endfor %} RUN rpm-ostree uninstall {% for app in rpm.remove %}{{ app }}{% endfor %}
@ -42,8 +46,10 @@ RUN rpm-ostree install {% for app in rpm.install %}{{ app }}{% endfor %}
RUN chmod +x /tmp/scripts/{{ script }} && /tmp/scripts/{{ script }} RUN chmod +x /tmp/scripts/{{ script }} && /tmp/scripts/{{ script }}
{% endfor %} {% endfor %}
{% if continerfiles %}
{% for containerfile in containerfiles.post %} {% for containerfile in containerfiles.post %}
{{ print_containerfile(containerfile) }} {{ print_containerfile(containerfile = containerfile) }}
{% endfor %} {% endfor %}
{% endif %}
RUN rm -rf /tmp/* /var/* && ostree container commit RUN rm -rf /tmp/* /var/* && ostree container commit