diff --git a/src/bin/ublue.rs b/src/bin/ublue.rs index 4750138..0d3344b 100644 --- a/src/bin/ublue.rs +++ b/src/bin/ublue.rs @@ -2,7 +2,8 @@ use std::{fs, io, path::PathBuf}; use anyhow::Result; use clap::{Parser, Subcommand}; -use ublue_rs::Recipe; +use tera::{Context, Tera}; +use ublue_rs::{Recipe, DEFAULT_CONTAINERFILE}; #[derive(Parser, Debug)] #[command(name = "Ublue Builder", author, version, about, long_about = None)] @@ -40,7 +41,11 @@ fn main() -> Result<()> { containerfile, } => { 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 } => { println!("Not yet implemented!"); diff --git a/src/lib.rs b/src/lib.rs index 72faea0..e0a0e1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,9 +18,9 @@ pub struct Recipe { pub rpm: Rpm, #[serde(rename = "usr-dir-overlays")] - pub usr_dir_overlays: Vec, + pub usr_dir_overlays: Option>, - pub containerfiles: Containerfiles, + pub containerfiles: Option, pub firstboot: FirstBoot, } diff --git a/templates/starting_point.template b/templates/starting_point.template index 2b3520b..407f52f 100644 --- a/templates/starting_point.template +++ b/templates/starting_point.template @@ -4,9 +4,11 @@ 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 @@ -22,16 +24,18 @@ COPY --from=gcr.io/projectsigstore/cosign /ko-app/cosign /usr/bin/cosign COPY scripts /tmp/scripts -{% for containerfile in containerfiles.pre %} -{{ print_containerfile(containerfile) }} -{% endfor %} +{% if continerfiles %} + {% for containerfile in containerfiles.pre %} +{{ print_containerfile(containerfile = containerfile) }} + {% endfor %} +{% endif %} {% for script in scripts.pre %} RUN chmod +x /tmp/scripts/{{ script }} && /tmp/scripts/{{ script }} {% endfor %} {% 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 %} 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 }} {% endfor %} -{% for containerfile in containerfiles.post %} -{{ print_containerfile(containerfile) }} -{% endfor %} +{% if continerfiles %} + {% for containerfile in containerfiles.post %} +{{ print_containerfile(containerfile = containerfile) }} + {% endfor %} +{% endif %} RUN rm -rf /tmp/* /var/* && ostree container commit