Update wild-app-add
to copy all template files. Clean up script output.
This commit is contained in:
@@ -56,7 +56,7 @@ fi
|
|||||||
|
|
||||||
CONFIG_FILE="${WC_HOME}/config.yaml"
|
CONFIG_FILE="${WC_HOME}/config.yaml"
|
||||||
if [ ! -f "${CONFIG_FILE}" ]; then
|
if [ ! -f "${CONFIG_FILE}" ]; then
|
||||||
echo "Creating config file at ${CONFIG_FILE}"
|
echo "Creating config file at '${CONFIG_FILE}'."
|
||||||
echo "# Wild Cloud Configuration" > "${CONFIG_FILE}"
|
echo "# Wild Cloud Configuration" > "${CONFIG_FILE}"
|
||||||
echo "# This file contains app configurations and should be committed to git" >> "${CONFIG_FILE}"
|
echo "# This file contains app configurations and should be committed to git" >> "${CONFIG_FILE}"
|
||||||
echo "" >> "${CONFIG_FILE}"
|
echo "" >> "${CONFIG_FILE}"
|
||||||
@@ -64,7 +64,7 @@ fi
|
|||||||
|
|
||||||
SECRETS_FILE="${WC_HOME}/secrets.yaml"
|
SECRETS_FILE="${WC_HOME}/secrets.yaml"
|
||||||
if [ ! -f "${SECRETS_FILE}" ]; then
|
if [ ! -f "${SECRETS_FILE}" ]; then
|
||||||
echo "Creating secrets file at ${SECRETS_FILE}"
|
echo "Creating secrets file at '${SECRETS_FILE}'."
|
||||||
echo "# Wild Cloud Secrets Configuration" > "${SECRETS_FILE}"
|
echo "# Wild Cloud Secrets Configuration" > "${SECRETS_FILE}"
|
||||||
echo "# This file contains sensitive data and should NOT be committed to git" >> "${SECRETS_FILE}"
|
echo "# This file contains sensitive data and should NOT be committed to git" >> "${SECRETS_FILE}"
|
||||||
echo "# Add this file to your .gitignore" >> "${SECRETS_FILE}"
|
echo "# Add this file to your .gitignore" >> "${SECRETS_FILE}"
|
||||||
@@ -74,8 +74,8 @@ fi
|
|||||||
# Check if app is cached, if not fetch it first
|
# Check if app is cached, if not fetch it first
|
||||||
CACHE_APP_DIR="${WC_HOME}/.wildcloud/cache/apps/${APP_NAME}"
|
CACHE_APP_DIR="${WC_HOME}/.wildcloud/cache/apps/${APP_NAME}"
|
||||||
if [ ! -d "${CACHE_APP_DIR}" ]; then
|
if [ ! -d "${CACHE_APP_DIR}" ]; then
|
||||||
echo "Cache directory for app '${APP_NAME}' not found at ${CACHE_APP_DIR}"
|
echo "Cache directory for app '${APP_NAME}' not found at '${CACHE_APP_DIR}'."
|
||||||
echo "Please fetch the app first using 'wild-app-fetch ${APP_NAME}'"
|
echo "Please fetch the app first using 'wild-app-fetch ${APP_NAME}'."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ ! -d "${CACHE_APP_DIR}" ]; then
|
if [ ! -d "${CACHE_APP_DIR}" ]; then
|
||||||
@@ -89,36 +89,36 @@ fi
|
|||||||
|
|
||||||
APPS_DIR="${WC_HOME}/apps"
|
APPS_DIR="${WC_HOME}/apps"
|
||||||
if [ ! -d "${APPS_DIR}" ]; then
|
if [ ! -d "${APPS_DIR}" ]; then
|
||||||
echo "Creating apps directory at ${APPS_DIR}"
|
echo "Creating apps directory at '${APPS_DIR}'."
|
||||||
mkdir -p "${APPS_DIR}"
|
mkdir -p "${APPS_DIR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DEST_APP_DIR="${WC_HOME}/apps/${APP_NAME}"
|
DEST_APP_DIR="${WC_HOME}/apps/${APP_NAME}"
|
||||||
if [ -d "${DEST_APP_DIR}" ]; then
|
if [ -d "${DEST_APP_DIR}" ]; then
|
||||||
if [ "${UPDATE}" = true ]; then
|
if [ "${UPDATE}" = true ]; then
|
||||||
echo "Updating app '${APP_NAME}'"
|
echo "Updating app '${APP_NAME}'."
|
||||||
rm -rf "${DEST_APP_DIR}"
|
rm -rf "${DEST_APP_DIR}"
|
||||||
else
|
else
|
||||||
echo "Warning: Destination directory ${DEST_APP_DIR} already exists"
|
echo "Warning: Destination directory ${DEST_APP_DIR} already exists."
|
||||||
read -p "Do you want to overwrite it? (y/N): " -n 1 -r
|
read -p "Do you want to overwrite it? (y/N): " -n 1 -r
|
||||||
echo
|
echo
|
||||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||||
echo "Configuration cancelled"
|
echo "Configuration cancelled."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
rm -rf "${DEST_APP_DIR}"
|
rm -rf "${DEST_APP_DIR}"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo "Adding app '${APP_NAME}' to '${DEST_APP_DIR}'."
|
||||||
fi
|
fi
|
||||||
mkdir -p "${DEST_APP_DIR}"
|
mkdir -p "${DEST_APP_DIR}"
|
||||||
|
|
||||||
echo "Adding app '${APP_NAME}' from cache to ${DEST_APP_DIR}"
|
|
||||||
|
|
||||||
# Step 1: Copy only manifest.yaml from cache first
|
# Step 1: Copy only manifest.yaml from cache first
|
||||||
MANIFEST_FILE="${CACHE_APP_DIR}/manifest.yaml"
|
MANIFEST_FILE="${CACHE_APP_DIR}/manifest.yaml"
|
||||||
if [ -f "${MANIFEST_FILE}" ]; then
|
if [ -f "${MANIFEST_FILE}" ]; then
|
||||||
# manifest.yaml is allowed to have gomplate variables in the defaultConfig and requiredSecrets sections.
|
# manifest.yaml is allowed to have gomplate variables in the defaultConfig and requiredSecrets sections.
|
||||||
# We need to use gomplate to process these variables before using yq.
|
# We need to use gomplate to process these variables before using yq.
|
||||||
echo "Copying manifest.yaml from cache"
|
echo "Copying app manifest from cache."
|
||||||
DEST_MANIFEST="${DEST_APP_DIR}/manifest.yaml"
|
DEST_MANIFEST="${DEST_APP_DIR}/manifest.yaml"
|
||||||
if [ -f "${SECRETS_FILE}" ]; then
|
if [ -f "${SECRETS_FILE}" ]; then
|
||||||
gomplate_cmd="gomplate -c .=${CONFIG_FILE} -c secrets=${SECRETS_FILE} -f ${MANIFEST_FILE} -o ${DEST_MANIFEST}"
|
gomplate_cmd="gomplate -c .=${CONFIG_FILE} -c secrets=${SECRETS_FILE} -f ${MANIFEST_FILE} -o ${DEST_MANIFEST}"
|
||||||
@@ -130,7 +130,7 @@ if [ -f "${MANIFEST_FILE}" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Warning: manifest.yaml not found in cache for app '${APP_NAME}'"
|
echo "Warning: App manifest not found in cache."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -147,7 +147,6 @@ fi
|
|||||||
# Merge processed defaultConfig into the app config, preserving existing values
|
# Merge processed defaultConfig into the app config, preserving existing values
|
||||||
# This preserves existing configuration values while adding missing defaults
|
# This preserves existing configuration values while adding missing defaults
|
||||||
if yq eval '.defaultConfig' "${DEST_MANIFEST}" | grep -q -v '^null$'; then
|
if yq eval '.defaultConfig' "${DEST_MANIFEST}" | grep -q -v '^null$'; then
|
||||||
echo "Merging defaultConfig from manifest.yaml into .wildcloud/config.yaml"
|
|
||||||
|
|
||||||
# Extract defaultConfig from the processed manifest and merge with existing app config
|
# Extract defaultConfig from the processed manifest and merge with existing app config
|
||||||
# The * operator merges objects, with the right side taking precedence for conflicting keys
|
# The * operator merges objects, with the right side taking precedence for conflicting keys
|
||||||
@@ -157,17 +156,17 @@ if yq eval '.defaultConfig' "${DEST_MANIFEST}" | grep -q -v '^null$'; then
|
|||||||
yq eval ".apps.${APP_NAME} = load(\"$temp_default_config\") * (.apps.${APP_NAME} // {})" -i "${CONFIG_FILE}"
|
yq eval ".apps.${APP_NAME} = load(\"$temp_default_config\") * (.apps.${APP_NAME} // {})" -i "${CONFIG_FILE}"
|
||||||
rm "$temp_default_config"
|
rm "$temp_default_config"
|
||||||
|
|
||||||
echo "Merged defaultConfig for app '${APP_NAME}'"
|
echo "Merged default configuration from app manifest into '${CONFIG_FILE}'."
|
||||||
# Remove defaultConfig from the copied manifest since it's now in config.yaml.
|
# Remove defaultConfig from the copied manifest since it's now in config.yaml.
|
||||||
yq eval 'del(.defaultConfig)' -i "${DEST_MANIFEST}"
|
yq eval 'del(.defaultConfig)' -i "${DEST_MANIFEST}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Scaffold required secrets into .wildcloud/secrets.yaml if they don't exist
|
# Scaffold required secrets into .wildcloud/secrets.yaml if they don't exist
|
||||||
if yq eval '.requiredSecrets' "${DEST_MANIFEST}" | grep -q -v '^null$'; then
|
if yq eval '.requiredSecrets' "${DEST_MANIFEST}" | grep -q -v '^null$'; then
|
||||||
echo "Scaffolding required secrets for app '${APP_NAME}'"
|
|
||||||
|
|
||||||
# Ensure .wildcloud/secrets.yaml exists
|
# Ensure .wildcloud/secrets.yaml exists
|
||||||
if [ ! -f "${SECRETS_FILE}" ]; then
|
if [ ! -f "${SECRETS_FILE}" ]; then
|
||||||
|
echo "Creating secrets file at '${SECRETS_FILE}'"
|
||||||
echo "# Wild Cloud Secrets Configuration" > "${SECRETS_FILE}"
|
echo "# Wild Cloud Secrets Configuration" > "${SECRETS_FILE}"
|
||||||
echo "# This file contains sensitive data and should NOT be committed to git" >> "${SECRETS_FILE}"
|
echo "# This file contains sensitive data and should NOT be committed to git" >> "${SECRETS_FILE}"
|
||||||
echo "# Add this file to your .gitignore" >> "${SECRETS_FILE}"
|
echo "# Add this file to your .gitignore" >> "${SECRETS_FILE}"
|
||||||
@@ -179,61 +178,27 @@ if yq eval '.requiredSecrets' "${DEST_MANIFEST}" | grep -q -v '^null$'; then
|
|||||||
current_value=$(yq eval ".${secret_path} // \"null\"" "${SECRETS_FILE}")
|
current_value=$(yq eval ".${secret_path} // \"null\"" "${SECRETS_FILE}")
|
||||||
|
|
||||||
if [ "${current_value}" = "null" ]; then
|
if [ "${current_value}" = "null" ]; then
|
||||||
echo "Adding random secret: ${secret_path}"
|
|
||||||
random_secret=$(openssl rand -base64 32 | tr -d "=+/" | cut -c1-32)
|
random_secret=$(openssl rand -base64 32 | tr -d "=+/" | cut -c1-32)
|
||||||
yq eval ".${secret_path} = \"${random_secret}\"" -i "${SECRETS_FILE}"
|
yq eval ".${secret_path} = \"${random_secret}\"" -i "${SECRETS_FILE}"
|
||||||
fi
|
fi
|
||||||
done < <(yq eval '.requiredSecrets[]' "${DEST_MANIFEST}")
|
done < <(yq eval '.requiredSecrets[]' "${DEST_MANIFEST}")
|
||||||
echo "Required secrets scaffolded for app '${APP_NAME}'"
|
echo "Required secrets declared in app manifest added to '${SECRETS_FILE}'."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 3: Copy and compile all other files from cache to app directory
|
# Step 3: Copy and compile all other files from cache to app directory
|
||||||
echo "Copying and compiling remaining files from cache"
|
echo "Copying and compiling remaining files from cache."
|
||||||
|
|
||||||
# Function to process a file with gomplate if it's a YAML file
|
cp -r "${CACHE_APP_DIR}/." "${DEST_APP_DIR}/"
|
||||||
process_file() {
|
find "${DEST_APP_DIR}" -type f | while read -r dest_file; do
|
||||||
local src_file="$1"
|
rel_path="${dest_file#${DEST_APP_DIR}/}"
|
||||||
local dest_file="$2"
|
|
||||||
|
|
||||||
echo "Processing file: ${dest_file}"
|
|
||||||
|
|
||||||
# Build gomplate command with config context (enables .config shorthand)
|
|
||||||
gomplate_cmd="gomplate -c .=${CONFIG_FILE}"
|
|
||||||
|
|
||||||
# Add secrets context if secrets.yaml exists (enables .secrets shorthand)
|
|
||||||
if [ -f "${SECRETS_FILE}" ]; then
|
|
||||||
gomplate_cmd="${gomplate_cmd} -c secrets=${SECRETS_FILE}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Execute gomplate with the file
|
|
||||||
${gomplate_cmd} -f "${src_file}" > "${dest_file}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Copy directory structure and process files (excluding manifest.yaml which was already copied)
|
|
||||||
find "${CACHE_APP_DIR}" -type d | while read -r src_dir; do
|
|
||||||
rel_path="${src_dir#${CACHE_APP_DIR}}"
|
|
||||||
rel_path="${rel_path#/}" # Remove leading slash if present
|
|
||||||
if [ -n "${rel_path}" ]; then
|
|
||||||
mkdir -p "${DEST_APP_DIR}/${rel_path}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
find "${CACHE_APP_DIR}" -type f | while read -r src_file; do
|
|
||||||
rel_path="${src_file#${CACHE_APP_DIR}}"
|
|
||||||
rel_path="${rel_path#/}" # Remove leading slash if present
|
|
||||||
|
|
||||||
# Skip manifest.yaml since it was already copied in step 1
|
|
||||||
if [ "${rel_path}" = "manifest.yaml" ]; then
|
if [ "${rel_path}" = "manifest.yaml" ]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dest_file="${DEST_APP_DIR}/${rel_path}"
|
temp_file=$(mktemp)
|
||||||
|
gomplate -c .=${CONFIG_FILE} -c secrets=${SECRETS_FILE} -f "${dest_file}" > "${temp_file}"
|
||||||
# Ensure destination directory exists
|
mv "${temp_file}" "${dest_file}"
|
||||||
dest_dir=$(dirname "${dest_file}")
|
|
||||||
mkdir -p "${dest_dir}"
|
|
||||||
|
|
||||||
process_file "${src_file}" "${dest_file}"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Successfully added app '${APP_NAME}' with template processing"
|
echo "Added '${APP_NAME}'."
|
||||||
|
@@ -19,10 +19,4 @@ echo
|
|||||||
./nfs/install.sh
|
./nfs/install.sh
|
||||||
./docker-registry/install.sh
|
./docker-registry/install.sh
|
||||||
|
|
||||||
echo "Infrastructure setup complete!"
|
echo "Service setup complete!"
|
||||||
echo
|
|
||||||
echo "To verify components, run:"
|
|
||||||
echo "- kubectl get pods -n cert-manager"
|
|
||||||
echo "- kubectl get pods -n externaldns"
|
|
||||||
echo "- kubectl get pods -n kubernetes-dashboard"
|
|
||||||
echo "- kubectl get clusterissuers"
|
|
||||||
|
Reference in New Issue
Block a user