diff --git a/Cargo.lock b/Cargo.lock index 0531e36..c03829a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1028,6 +1028,26 @@ dependencies = [ "serde", ] +[[package]] +name = "typed-builder" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e47c0496149861b7c95198088cbf36645016b1a0734cf350c50e2a38e070f38a" +dependencies = [ + "typed-builder-macro", +] + +[[package]] +name = "typed-builder-macro" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "982ee4197351b5c9782847ef5ec1fdcaf50503fb19d68f9771adae314e72b492" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.37", +] + [[package]] name = "typenum" version = "1.17.0" @@ -1051,6 +1071,7 @@ dependencies = [ "serde_json", "serde_yaml", "tera", + "typed-builder", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 62a9440..26a29cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.107" serde_yaml = "0.9.25" tera = "1.19.1" +typed-builder = "0.18.0" [features] default = ["build"] diff --git a/src/build.rs b/src/build.rs index dcab29c..c979e8a 100644 --- a/src/build.rs +++ b/src/build.rs @@ -7,12 +7,12 @@ use std::{ use anyhow::{anyhow, bail, Result}; use chrono::Local; use clap::Args; -use derive_builder::Builder; use log::{debug, error, info, trace, warn}; +use typed_builder::TypedBuilder; use crate::{module_recipe::Recipe, ops, template::TemplateCommand}; -#[derive(Debug, Clone, Args, Builder)] +#[derive(Debug, Clone, Args, TypedBuilder)] pub struct BuildCommand { /// The recipe file to build an image #[arg()] @@ -63,8 +63,8 @@ impl BuildCommand { if let Err(e) = TemplateCommand::builder() .recipe(self.recipe.clone()) .containerfile(self.containerfile.clone()) - .output(Some(PathBuf::from("Containerfile"))) - .build()? + .output(PathBuf::from("Containerfile")) + .build() .run() { error!("Failed to template file: {e}"); @@ -105,10 +105,6 @@ impl BuildCommand { Ok(()) } - pub fn builder() -> BuildCommandBuilder { - BuildCommandBuilder::default() - } - fn generate_tags(&self, recipe: &Recipe) -> Vec { debug!("Generating image tags for {}", &recipe.name); trace!("BuildCommand::generate_tags({recipe:#?})"); diff --git a/src/init.rs b/src/init.rs index aca2d37..d50c5c4 100644 --- a/src/init.rs +++ b/src/init.rs @@ -2,13 +2,13 @@ use std::path::{Path, PathBuf}; use anyhow::Result; use clap::Args; -use derive_builder::Builder; +use typed_builder::TypedBuilder; const GITLAB_CI_FILE: &'static str = include_str!("../templates/init/gitlab-ci.yml.tera"); const RECIPE_FILE: &'static str = include_str!("../templates/init/recipe.yml.tera"); const LICENSE_FILE: &'static str = include_str!("../LICENSE"); -#[derive(Debug, Clone, Args, Builder)] +#[derive(Debug, Clone, Args, TypedBuilder)] pub struct InitCommand { /// The directory to extract the files into. Defaults to the current directory #[arg()] diff --git a/src/template.rs b/src/template.rs index 985bbc8..66858b5 100644 --- a/src/template.rs +++ b/src/template.rs @@ -7,15 +7,15 @@ use std::{ use anyhow::Result; use clap::Args; -use derive_builder::Builder; use log::{debug, error, info, trace}; use tera::{Context, Tera}; +use typed_builder::TypedBuilder; use crate::module_recipe::Recipe; pub const DEFAULT_CONTAINERFILE: &str = include_str!("../templates/Containerfile.tera"); -#[derive(Debug, Clone, Args, Builder)] +#[derive(Debug, Clone, Args, TypedBuilder)] pub struct TemplateCommand { /// The recipe file to create a template from #[arg()] @@ -23,12 +23,12 @@ pub struct TemplateCommand { /// Optional Containerfile to use as a template #[arg(short, long)] - #[builder(default)] + #[builder(default, setter(into))] containerfile: Option, /// File to output to instead of STDOUT #[arg(short, long)] - #[builder(default)] + #[builder(default, setter(into))] output: Option, } @@ -72,10 +72,6 @@ impl TemplateCommand { Ok(()) } - pub fn builder() -> TemplateCommandBuilder { - TemplateCommandBuilder::default() - } - fn setup_tera(&self) -> Result<(Tera, Context)> { trace!("TemplateCommand::setup_tera()"); diff --git a/templates/init/gitlab-ci.yml.tera b/templates/init/gitlab-ci.yml.tera index c1a6a6a..ee7d9ab 100644 --- a/templates/init/gitlab-ci.yml.tera +++ b/templates/init/gitlab-ci.yml.tera @@ -1,5 +1,12 @@ workflow: rules: + - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push" + when: never + - if: "$CI_COMMIT_TAG" + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS" + when: never + - if: "$CI_COMMIT_BRANCH" stages: - build @@ -19,7 +26,6 @@ build-image: - if: $ACTION == "build-image" parallel: matrix: - # As you create more recipes to build, add them below - RECIPE: - recipe.yml id_tokens: