Skip to content

Commit

Permalink
feat: Use COPY syntax for files module (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpinder authored Feb 3, 2024
1 parent 933d250 commit 7f38fb0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/commands/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}");

Expand All @@ -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);
Expand Down Expand Up @@ -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(),
)
}
6 changes: 6 additions & 0 deletions templates/Containerfile.module
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down

0 comments on commit 7f38fb0

Please sign in to comment.