From 5dfae14c3250382a8358dbeb7523428a905789b9 Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Sat, 18 May 2024 10:34:54 -0400 Subject: [PATCH] fix: Allow both files or config directory to not exist (#185) --- template/src/lib.rs | 7 ++++++- template/templates/Containerfile.j2 | 5 ++--- template/templates/modules/modules.j2 | 8 ++++---- template/templates/stages.j2 | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/template/src/lib.rs b/template/src/lib.rs index 29f4c0e..5958b88 100644 --- a/template/src/lib.rs +++ b/template/src/lib.rs @@ -149,9 +149,14 @@ fn modules_exists() -> bool { fn files_dir_exists() -> bool { let path = Path::new(FILES_PATH); + path.exists() && path.is_dir() +} + +fn config_dir_exists() -> bool { + let path = Path::new(CONFIG_PATH); let exists = path.exists() && path.is_dir(); - if !exists { + if exists { warn!("Use of the {CONFIG_PATH} directory is deprecated. Please move your non-recipe files into {FILES_PATH}"); } diff --git a/template/templates/Containerfile.j2 b/template/templates/Containerfile.j2 index 10b7210..91403e5 100644 --- a/template/templates/Containerfile.j2 +++ b/template/templates/Containerfile.j2 @@ -1,5 +1,4 @@ {%- import "modules/modules.j2" as modules -%} -{%- set files_dir_exists = self::files_dir_exists() %} {%- include "stages.j2" %} # Main image @@ -8,9 +7,9 @@ FROM {{ recipe.base_image }}:{{ recipe.image_version }} as {{ recipe.name|replac ARG RECIPE={{ recipe_path.display() }} ARG IMAGE_REGISTRY={{ registry }} -{%- if files_dir_exists %} +{%- if self::files_dir_exists() %} ARG CONFIG_DIRECTORY="/tmp/files" -{%- else %} +{%- else if self::config_dir_exists() %} ARG CONFIG_DIRECTORY="/tmp/config" {%- endif %} ARG MODULE_DIRECTORY="/tmp/modules" diff --git a/template/templates/modules/modules.j2 b/template/templates/modules/modules.j2 index 5663a3d..c223665 100644 --- a/template/templates/modules/modules.j2 +++ b/template/templates/modules/modules.j2 @@ -12,9 +12,9 @@ ARG CACHEBUST="{{ build_id }}" {%- include "modules/copy/copy.j2" %} {%- else %} RUN \ - {%- if files_dir_exists %} + {%- if self::files_dir_exists() %} --mount=type=bind,from=stage-files,src=/files,dst=/tmp/files,rw \ - {%- else %} + {%- else if self::config_dir_exists() %} --mount=type=bind,from=stage-config,src=/config,dst=/tmp/config,rw \ {%- endif %} {%- if let Some(source) = module.source %} @@ -48,9 +48,9 @@ ARG CACHEBUST="{{ build_id }}" {%- include "modules/copy/copy.j2" %} {%- else %} RUN \ - {%- if files_dir_exists %} + {%- if self::files_dir_exists() %} --mount=type=bind,from=stage-files,src=/files,dst=/tmp/files,rw \ - {%- else %} + {%- else if self::config_dir_exists() %} --mount=type=bind,from=stage-config,src=/config,dst=/tmp/config,rw \ {%- endif %} {%- if let Some(source) = module.source %} diff --git a/template/templates/stages.j2 b/template/templates/stages.j2 index 24e87f3..c1a689a 100644 --- a/template/templates/stages.j2 +++ b/template/templates/stages.j2 @@ -1,10 +1,10 @@ # This stage is responsible for holding onto # your config without copying it directly into # the final image -{%- if files_dir_exists %} +{%- if self::files_dir_exists() %} FROM scratch AS stage-files COPY ./files /files -{% else %} +{% else if self::config_dir_exists() %} FROM scratch AS stage-config COPY ./config /config {% endif %}