Put init and build behind feature flags

This commit is contained in:
Gerald Pinder 2023-10-14 14:54:44 -04:00
parent 90bab6c9ff
commit 073ad4ca4a
4 changed files with 66 additions and 3 deletions

View file

@ -2,7 +2,7 @@ use std::path::PathBuf;
use anyhow::Result;
use clap::Parser;
use ublue_rs::{initialize_directory, setup_tera, CommandArgs, UblueArgs};
use ublue_rs::{self, CommandArgs, UblueArgs};
fn main() -> Result<()> {
let args = UblueArgs::parse();
@ -13,7 +13,7 @@ fn main() -> Result<()> {
containerfile,
output,
} => {
let (tera, context) = setup_tera(recipe, containerfile)?;
let (tera, context) = ublue_rs::setup_tera(recipe, containerfile)?;
let output_str = tera.render("Containerfile", &context)?;
if let Some(output) = output {
std::fs::write(output, output_str)?;
@ -21,14 +21,16 @@ fn main() -> Result<()> {
println!("{output_str}");
}
}
#[cfg(init)]
CommandArgs::Init { dir } => {
let base_dir = match dir {
Some(dir) => dir,
None => PathBuf::from("./"),
};
initialize_directory(base_dir);
ublue_rs::initialize_directory(base_dir);
}
#[cfg(build)]
CommandArgs::Build { containerfile: _ } => {
println!("Not yet implemented!");
todo!();

3
src/init.rs Normal file
View file

@ -0,0 +1,3 @@
const GITLAB_CI_FILE: &'static str = include_str!("../templates/init/gitlab-ci.yml");
const RECIPE_FILE: &'static str = include_str!("../templates/init/recipe.yml");
const LICENSE_FILE: &'static str = include_str!("../LICENSE");

View file

@ -12,6 +12,8 @@ use tera::{from_value, Context, Tera};
pub const DEFAULT_CONTAINERFILE: &'static str =
include_str!("../templates/starting_point.template");
#[cfg(init)]
pub mod init;
pub mod recipe;
#[derive(Parser, Debug)]
@ -39,6 +41,7 @@ pub enum CommandArgs {
},
/// Initialize a new Ublue Starting Point repo
#[cfg(init)]
Init {
/// The directory to extract the files into. Defaults to the current directory
#[arg()]
@ -46,6 +49,7 @@ pub enum CommandArgs {
},
/// Build an image from a Containerfile
#[cfg(build)]
Build {
#[arg()]
containerfile: String,
@ -115,6 +119,7 @@ pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Ter
Ok((tera, context))
}
#[cfg(init)]
pub fn initialize_directory(base_dir: PathBuf) {
let recipe_path = base_dir.join("recipe.yml");

53
templates/init/recipe.yml Normal file
View file

@ -0,0 +1,53 @@
# image will be published to ghcr.io/<user>/<name>
name: startingpoint
# description will be included in the image's metadata
description: A starting point for further customization of uBlue images. Make your own! https://ublue.it/making-your-own/
# the base image to build on top of (FROM) and the version tag to use
base-image: ghcr.io/ublue-os/silverblue-main
image-version: 38 # latest is also supported if you want new updates ASAP
# module configuration, executed in order
# you can include multiple instances of the same module
modules:
- type: files
files:
- usr: /usr # copy static configurations
#
# copies config/files/usr into your image's /usr
#
# configuration you wish to end up in /etc/ on the booted system
# should be added into /usr/etc/ as that is the proper "distro"
# config directory on ostree. Read more in the files module's README
- type: rpm-ostree
repos:
# - https://copr.fedorainfracloud.org/coprs/atim/starship/repo/fedora-%OS_VERSION%/atim-starship-fedora-%OS_VERSION%.repo
install:
# - micro
# - starship
remove:
- firefox # default firefox removed in favor of flatpak
- firefox-langpacks # langpacks needs to also be removed to prevent dependency problems
- type: bling # configure what to pull in from ublue-os/bling
install:
- justfiles # add "!include /usr/share/ublue-os/just/bling.just"
# in your custom.just (added by default) or local justfile
- nix-installer # shell shortcuts for determinate system's nix installers
- ublue-os-wallpapers
# - ublue-update # https://github.com/ublue-os/ublue-update
# - dconf-update-service # a service unit that updates the dconf db on boot
# - devpod # https://devpod.sh/ as an rpm
- type: yafti # if included, yafti and it's dependencies (pip & libadwaita)
# will be installed and set up
custom-flatpaks: # this section is optional
# - Celluloid: io.github.celluloid_player.Celluloid
# - Krita: org.kde.krita
- type: script
scripts:
# this sets up the proper policy & signing files for signed images to work
- signing.sh