Create templates, serialization structs, and cli arg parsing
This commit is contained in:
parent
6a7cadd2f6
commit
783c53ebb8
3 changed files with 134 additions and 3 deletions
|
|
@ -1,5 +1,8 @@
|
|||
use std::{fs, io, path::PathBuf};
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::{Parser, Subcommand};
|
||||
use ublue_rs::Recipe;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "Ublue Builder", author, version, about, long_about = None)]
|
||||
|
|
@ -10,11 +13,39 @@ struct UblueArgs {
|
|||
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum CommandArgs {
|
||||
Template,
|
||||
Build,
|
||||
/// Generate a Containerfile from a recipe
|
||||
Template {
|
||||
/// The recipe file to create a template from
|
||||
#[arg()]
|
||||
recipe: PathBuf,
|
||||
|
||||
/// Optional Containerfile to use as a template
|
||||
#[arg(short, long)]
|
||||
containerfile: Option<PathBuf>,
|
||||
},
|
||||
|
||||
/// Build an image from a Containerfile
|
||||
Build {
|
||||
#[arg()]
|
||||
containerfile: PathBuf,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
UblueArgs::parse();
|
||||
let args = UblueArgs::parse();
|
||||
|
||||
match args.command {
|
||||
CommandArgs::Template {
|
||||
recipe,
|
||||
containerfile,
|
||||
} => {
|
||||
let recipe: Recipe = serde_yaml::from_str(fs::read_to_string(recipe)?.as_str())?;
|
||||
println!("{:#?}", recipe);
|
||||
}
|
||||
CommandArgs::Build { containerfile } => {
|
||||
println!("Not yet implemented!");
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
51
src/lib.rs
51
src/lib.rs
|
|
@ -0,0 +1,51 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const DEFAULT_CONTAINERFILE: &'static str =
|
||||
include_str!("../templates/starting_point.template");
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Recipe {
|
||||
pub name: String,
|
||||
|
||||
#[serde(rename = "base-image")]
|
||||
pub base_image: String,
|
||||
|
||||
#[serde(rename = "fedora-version")]
|
||||
pub fedora_version: u16,
|
||||
|
||||
pub scripts: Scripts,
|
||||
|
||||
pub rpm: Rpm,
|
||||
|
||||
#[serde(rename = "usr-dir-overlays")]
|
||||
pub usr_dir_overlays: Vec<String>,
|
||||
|
||||
pub containerfiles: Containerfiles,
|
||||
|
||||
pub firstboot: FirstBoot,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Scripts {
|
||||
pub pre: Vec<String>,
|
||||
pub post: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Rpm {
|
||||
pub repos: Vec<String>,
|
||||
pub install: Vec<String>,
|
||||
pub remove: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct FirstBoot {
|
||||
pub yafti: bool,
|
||||
pub flatpaks: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Containerfiles {
|
||||
pub pre: Vec<String>,
|
||||
pub post: Vec<String>,
|
||||
}
|
||||
49
templates/starting_point.template
Normal file
49
templates/starting_point.template
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
FROM {{ base_image }}:{{ fedora_version }}
|
||||
|
||||
ARG RECIPE={{ recipe }}
|
||||
|
||||
COPY usr/ /usr
|
||||
|
||||
{% for usr_dir in usr_dir_overlays %}
|
||||
COPY {{ usr_dir }}/ /usr
|
||||
{% endfor %}
|
||||
|
||||
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
|
||||
|
||||
{% for containerfile in containerfiles.pre %}
|
||||
{{ print_containerfile(containerfile) }}
|
||||
{% endfor %}
|
||||
|
||||
{% 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/"
|
||||
{% endfor %}
|
||||
|
||||
RUN rpm-ostree uninstall {% for app in rpm.remove %}{{ app }}{% endfor %}
|
||||
|
||||
RUN rpm-ostree install {% for app in rpm.install %}{{ app }}{% endfor %}
|
||||
|
||||
{% for script in scripts.post %}
|
||||
RUN chmod +x /tmp/scripts/{{ script }} && /tmp/scripts/{{ script }}
|
||||
{% endfor %}
|
||||
|
||||
{% for containerfile in containerfiles.post %}
|
||||
{{ print_containerfile(containerfile) }}
|
||||
{% endfor %}
|
||||
|
||||
RUN rm -rf /tmp/* /var/* && ostree container commit
|
||||
Loading…
Add table
Add a link
Reference in a new issue