Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: snippets #51

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.vscode/

# Local testing for bluebuild recipe files
/config/
/config/*
Containerfile
File renamed without changes.
18 changes: 14 additions & 4 deletions src/commands/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ fn has_cosign_file() -> bool {
}

#[must_use]
fn get_containerfile_list(module: &Module) -> Option<Vec<String>> {
if module.module_type.as_ref()? == "containerfile" {
fn get_module_type_list(module: &Module, type: &str, list_key: &str) -> Option<Vec<String>> {
if module.module_type.as_ref()? == type {
gmpinder marked this conversation as resolved.
Show resolved Hide resolved
Some(
module
.config
.get("containerfiles")?
.get(list_key)?
.as_sequence()?
.iter()
.filter_map(|t| Some(t.as_str()?.to_owned()))
Expand All @@ -137,6 +137,16 @@ fn get_containerfile_list(module: &Module) -> Option<Vec<String>> {
}
}

#[must_use]
fn get_containerfile_list(module: &Module) -> Option<Vec<String>> {
get_module_type_list(module, "containerfile", "containerfiles")
}

#[must_use]
fn get_containerfile_snippets(module: &Module) -> Option<Vec<String>> {
get_module_type_list(module, "containerfile", "snippets")
}

#[must_use]
fn print_containerfile(containerfile: &str) -> String {
debug!("print_containerfile({containerfile})");
Expand All @@ -156,7 +166,7 @@ fn print_containerfile(containerfile: &str) -> String {

fn print_module_context(module: &Module) -> String {
serde_json::to_string(module).unwrap_or_else(|e| {
error!("Failed to parse module: {e}");
error!("Failed to parse module!!!!!: {e}");
process::exit(1);
})
}
Expand Down
6 changes: 6 additions & 0 deletions src/module_recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ pub struct ModuleExt {
}

impl ModuleExt {
/// # Parse a module file returning a [`ModuleExt`]
///
/// # Errors
/// Can return an `anyhow` Error if the file cannot be read or deserialized
/// into a [`ModuleExt`]
pub fn parse_module_from_file(file_name: &str) -> Result<ModuleExt> {
let file_path = PathBuf::from("config").join(file_name);
let file_path = if file_path.is_absolute() {
Expand Down Expand Up @@ -246,6 +251,7 @@ pub struct Module {
}

impl Module {
#[must_use]
pub fn get_modules(modules: &[Self]) -> Vec<Self> {
modules
.iter()
Expand Down
4 changes: 2 additions & 2 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub fn serde_yaml_err(contents: &str) -> impl Fn(serde_yaml::Error) -> SerdeErro
contents.to_string(),
(
err.into(),
location.map_or(0, |l| l.line()).into(),
location.map_or(0, |l| l.column()).into(),
location.map_or(0, serde_yaml::Location::line).into(),
location.map_or(0, serde_yaml::Location::column).into(),
),
)
}
Expand Down
7 changes: 5 additions & 2 deletions templates/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ COPY cosign.pub /usr/share/ublue-os/cosign.pub
# Feel free to remove these lines if you want to speed up image builds and don't want any bling
COPY --from=ghcr.io/ublue-os/bling:latest /rpms /tmp/bling/rpms
COPY --from=ghcr.io/ublue-os/bling:latest /files /tmp/bling/files

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 --from=ghcr.io/blue-build/cli:
Expand Down Expand Up @@ -57,6 +55,11 @@ ARG BASE_IMAGE="{{ recipe.base_image }}"
{{ self::print_containerfile(c) }}
{%- endfor %}
{%- endif %}
{%- if let Some(snippets) = self::get_containerfile_snippets(module) %}
{%- for s in snippets %}
{{ s }}
{%- endfor %}
{%- endif %}
{%- else if type == "files" %}
{%- if let Some(files) = self::get_files_list(module) %}
{%- for (src, dest) in files %}
Expand Down
Loading