fix: Allow both files or config directory to not exist (#185)

This commit is contained in:
Gerald Pinder 2024-05-18 10:34:54 -04:00 committed by GitHub
parent ab87f6548d
commit 5dfae14c32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 10 deletions

View file

@ -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}");
}

View file

@ -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"

View file

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

View file

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