feat: Use COPY syntax for files module (#38)

This commit is contained in:
Gerald Pinder 2024-02-03 14:42:42 -05:00 committed by GitHub
parent 933d25054a
commit 7f38fb04e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 3 deletions

View file

@ -118,7 +118,7 @@ fn running_gitlab_actions() -> bool {
}
#[must_use]
pub fn get_containerfile_list(module: &Module) -> Option<Vec<String>> {
fn get_containerfile_list(module: &Module) -> Option<Vec<String>> {
if module.module_type.as_ref()? == "containerfile" {
Some(
module
@ -135,7 +135,7 @@ pub fn get_containerfile_list(module: &Module) -> Option<Vec<String>> {
}
#[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<Vec<(String, String)>> {
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(),
)
}

View file

@ -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 %}