From 7f38fb04e6c6c9fa349f12fad2e982eba0d555b7 Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Sat, 3 Feb 2024 14:42:42 -0500 Subject: [PATCH] feat: Use COPY syntax for files module (#38) --- src/commands/template.rs | 25 ++++++++++++++++++++++--- templates/Containerfile.module | 6 ++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/commands/template.rs b/src/commands/template.rs index c29b0be..44d924b 100644 --- a/src/commands/template.rs +++ b/src/commands/template.rs @@ -118,7 +118,7 @@ fn running_gitlab_actions() -> bool { } #[must_use] -pub fn get_containerfile_list(module: &Module) -> Option> { +fn get_containerfile_list(module: &Module) -> Option> { if module.module_type.as_ref()? == "containerfile" { Some( module @@ -135,7 +135,7 @@ pub fn get_containerfile_list(module: &Module) -> Option> { } #[must_use] -pub fn print_containerfile(containerfile: &str) -> String { +fn print_containerfile(containerfile: &str) -> String { debug!("print_containerfile({containerfile})"); debug!("Loading containerfile contents for {containerfile}"); @@ -152,7 +152,7 @@ pub fn print_containerfile(containerfile: &str) -> String { } #[must_use] -pub fn template_module_from_file(file_name: &str) -> String { +fn template_module_from_file(file_name: &str) -> String { debug!("get_module_from_file({file_name})"); let file_path = PathBuf::from("config").join(file_name); @@ -195,3 +195,22 @@ fn print_module_context(module: &Module) -> String { process::exit(1); }) } + +fn get_files_list(module: &Module) -> Option> { + Some( + module + .config + .get("files")? + .as_sequence()? + .iter() + .filter_map(|entry| entry.as_mapping()) + .flatten() + .filter_map(|(src, dest)| { + Some(( + format!("./config/files/{}", src.as_str()?), + dest.as_str()?.to_string(), + )) + }) + .collect(), + ) +} diff --git a/templates/Containerfile.module b/templates/Containerfile.module index 8f58442..21d46e4 100644 --- a/templates/Containerfile.module +++ b/templates/Containerfile.module @@ -6,6 +6,12 @@ {{ self::print_containerfile(c) }} {%- endfor %} {%- endif %} + {%- else if type == "files" %} + {%- if let Some(files) = self::get_files_list(module) %} + {%- for (src, dest) in files %} +COPY {{ src }} {{ dest }} + {%- endfor %} + {%- endif %} {%- else %} RUN chmod +x /tmp/modules/{{ type }}/{{ type }}.sh && source /tmp/exports.sh && /tmp/modules/{{ type }}/{{ type }}.sh '{{ self::print_module_context(module) }}' {%- endif %}