forked from ungleich-public/cdist
implement dependency handling at the object level
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
cd1a1347c9
commit
4ee5d74c9f
5 changed files with 93 additions and 84 deletions
|
@ -32,31 +32,16 @@ if [ ! -d "$(__cdist_object_dir "$object")" ]; then
|
||||||
__cdist_exit_err "Object $object is missing."
|
__cdist_exit_err "Object $object is missing."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
finished="$(__cdist_object_code_finished "$object")"
|
|
||||||
require="$(__cdist_object_require "$object")"
|
|
||||||
|
|
||||||
code="$(__cdist_object_code "$object")-${__cdist_gencode_type}"
|
code="$(__cdist_object_code "$object")-${__cdist_gencode_type}"
|
||||||
|
|
||||||
# Do nothing if our work has been done
|
|
||||||
if [ -f "$finished" ]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Checking code-${__cdist_gencode_type} for $object ..."
|
echo "Checking code-${__cdist_gencode_type} for $object ..."
|
||||||
|
|
||||||
if [ -f "$require" ]; then
|
|
||||||
while read requirement; do
|
|
||||||
echo "Requiring dependency $requirement for $object ..."
|
|
||||||
cdist-code-run "$requirement" "$__cdist_gencode_type"
|
|
||||||
done < "$require"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -e "$code" ]; then
|
if [ -e "$code" ]; then
|
||||||
if [ -f "$code" ]; then
|
if [ -f "$code" ]; then
|
||||||
if [ -x "$code" ]; then
|
if [ -x "$code" ]; then
|
||||||
echo "Executing code-${__cdist_gencode_type} for $object ..."
|
echo "Executing code-${__cdist_gencode_type} for $object ..."
|
||||||
"$code"
|
"$code"
|
||||||
touch "$finished"
|
|
||||||
else
|
else
|
||||||
__cdist_exit_err "$code exists, but is not executable."
|
__cdist_exit_err "$code exists, but is not executable."
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -42,7 +42,6 @@ __cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname"
|
||||||
|
|
||||||
: ${__cdist_name_bin:=bin}
|
: ${__cdist_name_bin:=bin}
|
||||||
: ${__cdist_name_code:=code}
|
: ${__cdist_name_code:=code}
|
||||||
: ${__cdist_name_code_finished:=codedone}
|
|
||||||
: ${__cdist_name_conf_dir:=conf}
|
: ${__cdist_name_conf_dir:=conf}
|
||||||
: ${__cdist_name_dot_cdist:=.cdist}
|
: ${__cdist_name_dot_cdist:=.cdist}
|
||||||
: ${__cdist_name_explorer:=explorer}
|
: ${__cdist_name_explorer:=explorer}
|
||||||
|
@ -68,6 +67,7 @@ __cdist_abs_myname="$__cdist_abs_mydir/$__cdist_myname"
|
||||||
: ${__cdist_name_type:=type}
|
: ${__cdist_name_type:=type}
|
||||||
: ${__cdist_name_type_bin:=type_bin}
|
: ${__cdist_name_type_bin:=type_bin}
|
||||||
: ${__cdist_name_type_explorer:=type_explorer}
|
: ${__cdist_name_type_explorer:=type_explorer}
|
||||||
|
: ${__cdist_name_objects_created:=objects_created}
|
||||||
|
|
||||||
# Used for IDs: Allow everything not starting with - and .
|
# Used for IDs: Allow everything not starting with - and .
|
||||||
: ${__cdist_sane_regexp:=[^-\.].*}
|
: ${__cdist_sane_regexp:=[^-\.].*}
|
||||||
|
@ -107,6 +107,7 @@ __cdist_tmp_file=$(mktemp "$__cdist_tmp_dir/cdist.XXXXXXXXXXXX")
|
||||||
: ${__cdist_manifest_dir:=$__cdist_conf_dir/$__cdist_name_manifest}
|
: ${__cdist_manifest_dir:=$__cdist_conf_dir/$__cdist_name_manifest}
|
||||||
: ${__cdist_manifest_init:=$__cdist_manifest_dir/$__cdist_name_init}
|
: ${__cdist_manifest_init:=$__cdist_manifest_dir/$__cdist_name_init}
|
||||||
: ${__cdist_type_dir:=$__cdist_conf_dir/$__cdist_name_type}
|
: ${__cdist_type_dir:=$__cdist_conf_dir/$__cdist_name_type}
|
||||||
|
: ${__cdist_new_objects_created:=$__cdist_local_base_dir/$__cdist_name_objects_created}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Local output
|
# Local output
|
||||||
|
@ -176,6 +177,14 @@ __cdist_init_deploy()
|
||||||
ln -sf "$__cdist_conf_dir" "$__cdist_local_base_dir/$__cdist_name_conf_dir"
|
ln -sf "$__cdist_conf_dir" "$__cdist_local_base_dir/$__cdist_name_conf_dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__cdist_new_objects_created() {
|
||||||
|
touch "$__cdist_tmp_dir/object_created"
|
||||||
|
}
|
||||||
|
|
||||||
|
__cdist_has_new_objects() {
|
||||||
|
touch "$__cdist_tmp_dir/object_created"
|
||||||
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Object
|
# Object
|
||||||
#
|
#
|
||||||
|
@ -185,9 +194,9 @@ __cdist_object_code()
|
||||||
echo "$(__cdist_object_dir "$1")/${__cdist_name_code}"
|
echo "$(__cdist_object_dir "$1")/${__cdist_name_code}"
|
||||||
}
|
}
|
||||||
|
|
||||||
__cdist_object_code_finished()
|
__cdist_object_finished()
|
||||||
{
|
{
|
||||||
echo "$(__cdist_object_dir "$1")/${__cdist_name_code_finished}"
|
echo "$(__cdist_object_dir "$1")/${__cdist_name_object_finished}"
|
||||||
}
|
}
|
||||||
|
|
||||||
__cdist_object_dir()
|
__cdist_object_dir()
|
||||||
|
@ -250,6 +259,7 @@ __cdist_object_type_explorer_dir()
|
||||||
echo "$(__cdist_object_dir "$1")/${__cdist_name_explorer}"
|
echo "$(__cdist_object_dir "$1")/${__cdist_name_explorer}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Remote
|
# Remote
|
||||||
#
|
#
|
||||||
|
|
|
@ -35,7 +35,6 @@ __cdist_cur_object_dir="$(__cdist_object_dir "$__cdist_object")"
|
||||||
# Only the id
|
# Only the id
|
||||||
__cdist_object_id="$(__cdist_object_id_from_object "$__cdist_object")"
|
__cdist_object_id="$(__cdist_object_id_from_object "$__cdist_object")"
|
||||||
|
|
||||||
if [ ! -f "${__cdist_cur_object_dir}/$__cdist_name_object_finished" ]; then
|
|
||||||
echo "Checking manifest for $__cdist_object ..."
|
echo "Checking manifest for $__cdist_object ..."
|
||||||
|
|
||||||
__cdist_type="$(__cdist_type_from_object "$__cdist_object")"
|
__cdist_type="$(__cdist_type_from_object "$__cdist_object")"
|
||||||
|
@ -53,12 +52,10 @@ if [ ! -f "${__cdist_cur_object_dir}/$__cdist_name_object_finished" ]; then
|
||||||
export $__cdist_name_var_type="$(__cdist_type_dir "$__cdist_type")"
|
export $__cdist_name_var_type="$(__cdist_type_dir "$__cdist_type")"
|
||||||
|
|
||||||
cdist-manifest-run "$__cdist_target_host" "$__cdist_manifest"
|
cdist-manifest-run "$__cdist_target_host" "$__cdist_manifest"
|
||||||
|
# Tell cdist that there may be new objects
|
||||||
|
touch "$__cdist_new_objects_created"
|
||||||
else
|
else
|
||||||
__cdist_exit_err "${__cdist_manifest} needs to be executable."
|
__cdist_exit_err "${__cdist_manifest} needs to be executable."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# done with this object
|
|
||||||
touch "$__cdist_cur_object_dir/$__cdist_name_object_finished"
|
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#
|
#
|
||||||
# For the given object:
|
# For the given object:
|
||||||
# - run type explorers
|
# - run type explorers
|
||||||
|
# - run type manifest
|
||||||
# - generate code
|
# - generate code
|
||||||
# - copy object to target
|
# - copy object to target
|
||||||
# - execute code on target
|
# - execute code on target
|
||||||
|
@ -35,12 +36,25 @@ __cdist_object="$1"; shift
|
||||||
|
|
||||||
|
|
||||||
__cdist_type="$(__cdist_type_from_object "$__cdist_object")"
|
__cdist_type="$(__cdist_type_from_object "$__cdist_object")"
|
||||||
|
__cdist_types_pushed="$__cdist_tmp_dir/types_pushed"
|
||||||
|
touch "$__cdist_types_pushed"
|
||||||
|
|
||||||
|
__cdist_object_finished="$(__cdist_object_finished "$__cdist_object")"
|
||||||
|
if [ ! -f "$__cdist_object_finished" ]; then
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Running object $__cdist_object"
|
||||||
|
|
||||||
# Check if type of object has >= 1 explorer
|
# Check if type of object has >= 1 explorer
|
||||||
__cdist_has_explorer="$(__cdist_type_has_explorer "$__cdist_type")"
|
__cdist_has_explorer="$(__cdist_type_has_explorer "$__cdist_type")"
|
||||||
|
|
||||||
# Run the type explorers for the current object if any
|
# Run the type explorers for the current object if any
|
||||||
if [ "$__cdist_has_explorer" ]; then
|
if [ "$__cdist_has_explorer" ]; then
|
||||||
|
if ! grep -q "$__cdist_type" "$__cdist_types_pushed"; then
|
||||||
|
cdist-type-explorer-push "$__cdist_target_host" "$__cdist_type"
|
||||||
|
echo "$__cdist_type" >> "$__cdist_types_pushed"
|
||||||
|
fi
|
||||||
|
|
||||||
cdist-object-explorer-run "$__cdist_target_host" "$__cdist_object"
|
cdist-object-explorer-run "$__cdist_target_host" "$__cdist_object"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -56,3 +70,7 @@ cdist-object-push "$__cdist_target_host" "$__cdist_object"
|
||||||
# Run the code for the current object
|
# Run the code for the current object
|
||||||
cdist-object-code-run "$__cdist_target_host" "$__cdist_object"
|
cdist-object-code-run "$__cdist_target_host" "$__cdist_object"
|
||||||
|
|
||||||
|
# Mark this object as done
|
||||||
|
touch "$__cdist_object_finished"
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
|
@ -29,9 +29,13 @@ set -eu
|
||||||
__cdist_target_host="$1"; shift
|
__cdist_target_host="$1"; shift
|
||||||
|
|
||||||
__cdist_objects="$__cdist_tmp_dir/objects"
|
__cdist_objects="$__cdist_tmp_dir/objects"
|
||||||
__cdist_types_pushed="$__cdist_tmp_dir/types_pushed"
|
|
||||||
touch "$__cdist_types_pushed"
|
|
||||||
|
|
||||||
|
# Loop until we do not create new objects anymore
|
||||||
|
# which is equal to all objects have been run
|
||||||
|
touch "$__cdist_new_objects_created"
|
||||||
|
while [ -f "$__cdist_new_objects_created" ]; do
|
||||||
|
# Assume we're done after this run
|
||||||
|
rm "$__cdist_new_objects_created"
|
||||||
|
|
||||||
# Get listing of objects
|
# Get listing of objects
|
||||||
__cdist_object_list "$__cdist_out_object_dir" > "$__cdist_objects"
|
__cdist_object_list "$__cdist_out_object_dir" > "$__cdist_objects"
|
||||||
|
@ -44,24 +48,19 @@ done < "$__cdist_objects"
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
__cdist_object="$1"; shift
|
__cdist_object="$1"; shift
|
||||||
|
|
||||||
|
__cdist_object_require="$(__cdist_object_require "$__cdist_object")"
|
||||||
|
if [ -f "$__cdist_object_require" ]; then
|
||||||
echo
|
echo
|
||||||
echo "Running object $__cdist_object"
|
while read __cdist_requirement; do
|
||||||
|
echo "Resolving dependency $__cdist_object -> $__cdist_requirement ..."
|
||||||
__cdist_type="$(__cdist_type_from_object "$__cdist_object")"
|
cdist-object-run "$__cdist_target_host" "$__cdist_requirement"
|
||||||
|
done < "$__cdist_object_require"
|
||||||
# Check if type of object has >= 1 explorer
|
|
||||||
__cdist_has_explorer="$(__cdist_type_has_explorer "$__cdist_type")"
|
|
||||||
|
|
||||||
# Transfer the type explorers if any
|
|
||||||
if [ "$__cdist_has_explorer" ]; then
|
|
||||||
if ! grep -q "$__cdist_type" "$__cdist_types_pushed"; then
|
|
||||||
cdist-type-explorer-push "$__cdist_target_host" "$__cdist_type"
|
|
||||||
echo "$__cdist_type" >> "$__cdist_types_pushed"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Process the given object
|
# Process the object
|
||||||
cdist-object-run "$__cdist_target_host" "$__cdist_object"
|
cdist-object-run "$__cdist_target_host" "$__cdist_object"
|
||||||
|
|
||||||
done
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue