From 6bc0b070036fe9cf6f472c3c6e5a6213695d408e Mon Sep 17 00:00:00 2001 From: Paul Payne Date: Sat, 7 Jun 2025 12:08:11 -0700 Subject: [PATCH] Add wild-init script. --- .env.example | 36 ------ bin/wild-init | 118 ++++++++++++++++++ my-scaffold/.env.example | 2 + .../.wildcloud/.gitignore | 0 .../.wildcloud/config.example.yaml | 5 +- my-scaffold/.wildcloud/secrets.example.yaml | 4 + {my-templates => my-scaffold}/README.md | 0 {my-templates => my-scaffold}/apps/README.md | 0 my-templates/.wildcloud/secrets.example.yaml | 1 - 9 files changed, 127 insertions(+), 39 deletions(-) delete mode 100644 .env.example create mode 100755 bin/wild-init create mode 100644 my-scaffold/.env.example rename {my-templates => my-scaffold}/.wildcloud/.gitignore (100%) rename my-templates/.wildcloud/config.yaml => my-scaffold/.wildcloud/config.example.yaml (91%) create mode 100644 my-scaffold/.wildcloud/secrets.example.yaml rename {my-templates => my-scaffold}/README.md (100%) rename {my-templates => my-scaffold}/apps/README.md (100%) delete mode 100644 my-templates/.wildcloud/secrets.example.yaml diff --git a/.env.example b/.env.example deleted file mode 100644 index 10a909e..0000000 --- a/.env.example +++ /dev/null @@ -1,36 +0,0 @@ -# Basic configuration -DOMAIN=example.com -EMAIL=your.email@example.com -USE_HOSTNAME=your-hostname -KUBECONFIG=/etc/rancher/k3s/k3s.yaml -ENVIRONMENT=prod - -# Dynamic DNS configuration for external access -DYNAMIC_DNS=your-dynamic-dns.example.com - -# Dashboard access -ADMIN_USERNAME=admin - -# PostgreSQL configuration -POSTGRES_NAMESPACE=postgres -POSTGRES_RELEASE_NAME=postgresql -POSTGRES_DB=postgres -POSTGRES_USER=postgres -POSTGRES_PASSWORD=your-secure-password -POSTGRES_STORAGE=10Gi - -# MariaDB configuration -MARIADB_NAMESPACE=mariadb -MARIADB_RELEASE_NAME=mariadb -MARIADB_ROOT_PASSWORD=your-root-password -MARIADB_USER=app -MARIADB_PASSWORD=your-secure-password -MARIADB_DATABASE=app_database -MARIADB_STORAGE=8Gi -MARIADB_TAG=11.4.5 - -# Cert Manager configuration -CERT_MANAGER_NAMESPACE=cert-manager -CERT_MANAGER_RELEASE_NAME=cert-manager -CERT_ISSUERS_RELEASE_NAME=cert-issuers -CLOUDFLARE_API_TOKEN=your-cloudflare-api-token-here # Required for wildcard certificates \ No newline at end of file diff --git a/bin/wild-init b/bin/wild-init new file mode 100755 index 0000000..76e79d3 --- /dev/null +++ b/bin/wild-init @@ -0,0 +1,118 @@ +#!/bin/bash + +set -e +set -o pipefail + +# Source environment variables +source "${BASH_SOURCE%/*}/../load-env.sh" 2>/dev/null || true + +UPDATE=false + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --update) + UPDATE=true + shift + ;; + -h|--help) + echo "Usage: $0 [--update]" + echo "" + echo "Initialize a new Wild-Cloud project by copying scaffold files." + echo "" + echo "Options:" + echo " --update Update existing files with scaffold files (overwrite)" + echo " -h, --help Show this help message" + echo "" + echo "By default, this script will only run in an empty directory." + echo "Use --update to overwrite existing scaffold files while preserving other files." + exit 0 + ;; + -*) + echo "Unknown option $1" + echo "Usage: $0 [--update]" + exit 1 + ;; + *) + echo "Unexpected argument: $1" + echo "Usage: $0 [--update]" + exit 1 + ;; + esac +done + +# Get the path to the Wild-Cloud repository (where this script is located) +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +WILDCLOUD_REPO="$(dirname "${SCRIPT_DIR}")" +SCAFFOLD_DIR="${WILDCLOUD_REPO}/my-scaffold" + +if [ ! -d "${SCAFFOLD_DIR}" ]; then + echo "Error: Scaffold directory not found at ${SCAFFOLD_DIR}" + exit 1 +fi + +# Check if current directory is empty (unless --update is used) +if [ "${UPDATE}" = false ]; then + # Check if directory has any files (including hidden files, excluding . and ..) + if [ -n "$(find . -maxdepth 1 -name ".*" -o -name "*" | grep -v "^\.$" | head -1)" ]; then + echo "Error: Current directory is not empty" + echo "Use --update flag to overwrite existing scaffold files while preserving other files" + exit 1 + fi +fi + +echo "Initializing Wild-Cloud project in $(pwd)" + +if [ "${UPDATE}" = true ]; then + echo "Updating scaffold files (preserving existing non-scaffold files)" +else + echo "Copying scaffold files to empty directory" +fi + +# Function to copy files and directories +copy_scaffold() { + local src_dir="$1" + local dest_dir="$2" + + # Create destination directory if it doesn't exist + mkdir -p "${dest_dir}" + + # Copy directory structure + find "${src_dir}" -type d | while read -r src_subdir; do + rel_path="${src_subdir#${src_dir}}" + rel_path="${rel_path#/}" # Remove leading slash if present + if [ -n "${rel_path}" ]; then + mkdir -p "${dest_dir}/${rel_path}" + fi + done + + # Copy files + find "${src_dir}" -type f | while read -r src_file; do + rel_path="${src_file#${src_dir}}" + rel_path="${rel_path#/}" # Remove leading slash if present + dest_file="${dest_dir}/${rel_path}" + + # Ensure destination directory exists + dest_file_dir=$(dirname "${dest_file}") + mkdir -p "${dest_file_dir}" + + if [ "${UPDATE}" = true ] && [ -f "${dest_file}" ]; then + echo "Updating: ${rel_path}" + else + echo "Creating: ${rel_path}" + fi + + cp "${src_file}" "${dest_file}" + done +} + +# Copy scaffold files to current directory +copy_scaffold "${SCAFFOLD_DIR}" "." + +echo "" +echo "Wild-Cloud project initialized successfully!" +echo "" +echo "Next steps:" +echo "1. Review and customize the configuration files" +echo "2. Set up your .wildcloud/config.yaml with your Wild-Cloud repository path" +echo "3. Start using wild-app-* commands to manage your applications" \ No newline at end of file diff --git a/my-scaffold/.env.example b/my-scaffold/.env.example new file mode 100644 index 0000000..a6d4887 --- /dev/null +++ b/my-scaffold/.env.example @@ -0,0 +1,2 @@ +KUBECONFIG=~/.kube/config +export KUBECONFIG diff --git a/my-templates/.wildcloud/.gitignore b/my-scaffold/.wildcloud/.gitignore similarity index 100% rename from my-templates/.wildcloud/.gitignore rename to my-scaffold/.wildcloud/.gitignore diff --git a/my-templates/.wildcloud/config.yaml b/my-scaffold/.wildcloud/config.example.yaml similarity index 91% rename from my-templates/.wildcloud/config.yaml rename to my-scaffold/.wildcloud/config.example.yaml index b27504b..6ec7b83 100644 --- a/my-templates/.wildcloud/config.yaml +++ b/my-scaffold/.wildcloud/config.example.yaml @@ -22,13 +22,14 @@ cloud: cluster: endpoint: computer-01 endpointIp: 192.168.8.241 - kubeConfig: /home/adam/.kube/config + kubernetes: + config: /home/adam/.kube/config + context: default loadBalancerRange: 192.168.8.240-192.168.8.250 dashboard: adminUsername: admin certManager: namespace: cert-manager cloudflare: - apiToken: domain: adam.tld ownerId: cloud-adam-cluster diff --git a/my-scaffold/.wildcloud/secrets.example.yaml b/my-scaffold/.wildcloud/secrets.example.yaml new file mode 100644 index 0000000..dd9cd95 --- /dev/null +++ b/my-scaffold/.wildcloud/secrets.example.yaml @@ -0,0 +1,4 @@ +cluster: + certManager: + cloudflare: + apiToken: diff --git a/my-templates/README.md b/my-scaffold/README.md similarity index 100% rename from my-templates/README.md rename to my-scaffold/README.md diff --git a/my-templates/apps/README.md b/my-scaffold/apps/README.md similarity index 100% rename from my-templates/apps/README.md rename to my-scaffold/apps/README.md diff --git a/my-templates/.wildcloud/secrets.example.yaml b/my-templates/.wildcloud/secrets.example.yaml deleted file mode 100644 index 523a2fe..0000000 --- a/my-templates/.wildcloud/secrets.example.yaml +++ /dev/null @@ -1 +0,0 @@ -cloudflareApiToken: