55 lines
1.3 KiB
Bash
Executable File
55 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# Find repo root
|
|
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || true)
|
|
|
|
if [ -z "$REPO_ROOT" ]; then
|
|
echo "❗ Could not detect Git repo root. Are you inside a Git repo?"
|
|
exit 2
|
|
fi
|
|
|
|
# Go up three directories from the current folder
|
|
pushd ../../../
|
|
INSTANCE_DIR=$(pwd)
|
|
INSTANCE_NAME="$(basename $(pwd))"
|
|
popd
|
|
|
|
echo "🔎 Detected instance: $INSTANCE_NAME"
|
|
|
|
# Find the real terragrunt.hcl location
|
|
TERRAGRUNT_HCL="${INSTANCE_DIR}/terragrunt.hcl"
|
|
|
|
if [ ! -f "$TERRAGRUNT_HCL" ]; then
|
|
echo "❗ terragrunt.hcl not found at expected location: $TERRAGRUNT_HCL"
|
|
exit 3
|
|
fi
|
|
|
|
# Extract node_name from terragrunt.hcl
|
|
NODE_NAME=$(grep 'node_name *= *' "$TERRAGRUNT_HCL" | sed -E 's/.*=\s*"([^"]+)".*/\1/')
|
|
|
|
if [ -z "$NODE_NAME" ]; then
|
|
echo "❗ node_name not found in $TERRAGRUNT_HCL"
|
|
exit 4
|
|
fi
|
|
|
|
# Set config file path
|
|
YAML_FILE="${REPO_ROOT}/config/nodes/${NODE_NAME}/config.yaml"
|
|
|
|
if [ ! -f "$YAML_FILE" ]; then
|
|
echo "❗ Config file $YAML_FILE not found!"
|
|
exit 5
|
|
fi
|
|
|
|
echo "✔️ Exporting environment variables from $YAML_FILE"
|
|
|
|
# Export vars
|
|
export NODE_ADDR=$(yq eval '.node_addr' "$YAML_FILE")
|
|
export NODE_PORT=$(yq eval '.node_port' "$YAML_FILE")
|
|
export NODE_NAME="${NODE_NAME}"
|
|
|
|
# Echo for debugging
|
|
echo "NODE_ADDR=$NODE_ADDR"
|
|
echo "NODE_PORT=$NODE_PORT"
|
|
echo "NODE_NAME=$NODE_NAME"
|