fix: print module context as json

This commit is contained in:
Gerald Pinder 2023-10-27 22:30:10 -04:00
parent 9564ca0af3
commit c6f2e5b18d
4 changed files with 5 additions and 3 deletions

1
Cargo.lock generated
View file

@ -790,6 +790,7 @@ dependencies = [
"cfg-if",
"clap",
"serde",
"serde_json",
"serde_yaml",
"tera",
]

View file

@ -15,6 +15,7 @@ anyhow = "1.0.75"
cfg-if = "1.0.0"
clap = { version = "4.4.4", features = ["derive"] }
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
serde_yaml = "0.9.25"
tera = "1.19.1"

View file

@ -128,8 +128,8 @@ pub fn setup_tera(recipe: String, containerfile: Option<PathBuf>) -> Result<(Ter
"print_module_context",
|args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
match args.get("module") {
Some(v) => Ok(match serde_yaml::to_string(v) {
Ok(s) => s.escape_default().collect::<String>(),
Some(v) => Ok(match serde_json::to_string(v) {
Ok(s) => s,
Err(_) => "Unable to serialize".into(),
}
.into()),

View file

@ -35,7 +35,7 @@ ARG BASE_IMAGE="{{ base_image }}"
{% endfor %}
{% else %}
RUN chmod +x /tmp/modules/{{ module.type }}/{{ module.type }}.sh
RUN source /tmp/exports.sh && OS_VERSION="$(grep -Po '(?<=VERSION_ID=)\d+' /usr/lib/os-release)" /tmp/modules/{{ module.type }}/{{ module.type }}.sh "$(echo -e "{{ print_module_context(module = module) }}")"
RUN source /tmp/exports.sh && OS_VERSION="$(grep -Po '(?<=VERSION_ID=)\d+' /usr/lib/os-release)" /tmp/modules/{{ module.type }}/{{ module.type }}.sh '{{ print_module_context(module = module) }}'
{% endif %}
{% elif module["from-file"] %}
{% set extra_module = get_module_from_file(file = module["from-file"]) %}