191 lines
4.9 KiB
Go
191 lines
4.9 KiB
Go
package setup
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/wild-cloud/wild-cli/internal/output"
|
|
)
|
|
|
|
func newScaffoldCommand() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "scaffold",
|
|
Short: "Initialize a new Wild Cloud project",
|
|
Long: `Initialize a new Wild Cloud project directory with configuration templates.`,
|
|
RunE: runScaffold,
|
|
}
|
|
}
|
|
|
|
func runScaffold(cmd *cobra.Command, args []string) error {
|
|
output.Header("Wild Cloud Project Initialization")
|
|
|
|
// Get current directory
|
|
cwd, err := os.Getwd()
|
|
if err != nil {
|
|
return fmt.Errorf("getting current directory: %w", err)
|
|
}
|
|
|
|
// Check if already a Wild Cloud project
|
|
if _, err := os.Stat(filepath.Join(cwd, ".wildcloud")); err == nil {
|
|
return fmt.Errorf("current directory is already a Wild Cloud project")
|
|
}
|
|
|
|
output.Info("Initializing Wild Cloud project in: " + cwd)
|
|
|
|
// Create .wildcloud directory
|
|
wildcloudDir := filepath.Join(cwd, ".wildcloud")
|
|
if err := os.MkdirAll(wildcloudDir, 0755); err != nil {
|
|
return fmt.Errorf("creating .wildcloud directory: %w", err)
|
|
}
|
|
|
|
// Create cache directory
|
|
cacheDir := filepath.Join(wildcloudDir, "cache")
|
|
if err := os.MkdirAll(cacheDir, 0755); err != nil {
|
|
return fmt.Errorf("creating cache directory: %w", err)
|
|
}
|
|
|
|
// Create apps directory
|
|
appsDir := filepath.Join(cwd, "apps")
|
|
if err := os.MkdirAll(appsDir, 0755); err != nil {
|
|
return fmt.Errorf("creating apps directory: %w", err)
|
|
}
|
|
|
|
// Create config.yaml with basic structure
|
|
configPath := filepath.Join(cwd, "config.yaml")
|
|
configContent := `# Wild Cloud Configuration
|
|
cluster:
|
|
name: ""
|
|
domain: ""
|
|
vip: ""
|
|
nodes: []
|
|
|
|
apps: {}
|
|
|
|
services: {}
|
|
`
|
|
|
|
if err := os.WriteFile(configPath, []byte(configContent), 0644); err != nil {
|
|
return fmt.Errorf("creating config.yaml: %w", err)
|
|
}
|
|
|
|
// Create secrets.yaml with basic structure
|
|
secretsPath := filepath.Join(cwd, "secrets.yaml")
|
|
secretsContent := `# Wild Cloud Secrets
|
|
# This file contains sensitive information and should not be committed to version control
|
|
|
|
cluster:
|
|
secrets: {}
|
|
|
|
apps: {}
|
|
`
|
|
|
|
if err := os.WriteFile(secretsPath, []byte(secretsContent), 0600); err != nil {
|
|
return fmt.Errorf("creating secrets.yaml: %w", err)
|
|
}
|
|
|
|
// Create .gitignore to exclude secrets
|
|
gitignorePath := filepath.Join(cwd, ".gitignore")
|
|
gitignoreContent := `# Wild Cloud secrets and sensitive data
|
|
secrets.yaml
|
|
*.key
|
|
*.crt
|
|
*.pem
|
|
|
|
# Talos configuration files
|
|
*.talosconfig
|
|
controlplane.yaml
|
|
worker.yaml
|
|
|
|
# Kubernetes config
|
|
kubeconfig
|
|
|
|
# Backup files
|
|
*.bak
|
|
*.backup
|
|
|
|
# Cache and temporary files
|
|
.wildcloud/cache/
|
|
*.tmp
|
|
*.temp
|
|
`
|
|
|
|
if err := os.WriteFile(gitignorePath, []byte(gitignoreContent), 0644); err != nil {
|
|
output.Warning("Failed to create .gitignore: " + err.Error())
|
|
}
|
|
|
|
// Create README.md with basic information
|
|
readmePath := filepath.Join(cwd, "README.md")
|
|
readmeContent := `# Wild Cloud Project
|
|
|
|
This is a Wild Cloud personal infrastructure project.
|
|
|
|
## Getting Started
|
|
|
|
1. Configure your cluster settings:
|
|
` + "```bash" + `
|
|
wild config set cluster.name my-cluster
|
|
wild config set cluster.domain example.com
|
|
wild config set cluster.vip 192.168.1.100
|
|
` + "```" + `
|
|
|
|
2. Set up your cluster:
|
|
` + "```bash" + `
|
|
wild setup cluster
|
|
` + "```" + `
|
|
|
|
3. Install cluster services:
|
|
` + "```bash" + `
|
|
wild setup services
|
|
` + "```" + `
|
|
|
|
4. Deploy applications:
|
|
` + "```bash" + `
|
|
wild app list
|
|
wild app fetch nextcloud
|
|
wild app add nextcloud
|
|
wild app deploy nextcloud
|
|
` + "```" + `
|
|
|
|
## Directory Structure
|
|
|
|
- ` + "`config.yaml`" + ` - Cluster and application configuration
|
|
- ` + "`secrets.yaml`" + ` - Sensitive data (not committed to git)
|
|
- ` + "`apps/`" + ` - Application configurations
|
|
- ` + "`.wildcloud/`" + ` - Wild Cloud metadata and cache
|
|
|
|
## Commands
|
|
|
|
- ` + "`wild config`" + ` - Manage configuration
|
|
- ` + "`wild secret`" + ` - Manage secrets
|
|
- ` + "`wild setup`" + ` - Set up infrastructure
|
|
- ` + "`wild app`" + ` - Manage applications
|
|
- ` + "`wild cluster`" + ` - Manage cluster
|
|
- ` + "`wild backup`" + ` - Backup system
|
|
|
|
For more information, run ` + "`wild --help`" + `
|
|
`
|
|
|
|
if err := os.WriteFile(readmePath, []byte(readmeContent), 0644); err != nil {
|
|
output.Warning("Failed to create README.md: " + err.Error())
|
|
}
|
|
|
|
output.Success("Wild Cloud project initialized successfully!")
|
|
output.Info("")
|
|
output.Info("Next steps:")
|
|
output.Info(" 1. Configure your cluster: wild config set cluster.name my-cluster")
|
|
output.Info(" 2. Set up your cluster: wild setup cluster")
|
|
output.Info(" 3. Deploy services: wild setup services")
|
|
output.Info("")
|
|
output.Info("Project structure created:")
|
|
output.Info(" ├── .wildcloud/ # Project metadata")
|
|
output.Info(" ├── apps/ # Application configurations")
|
|
output.Info(" ├── config.yaml # Cluster configuration")
|
|
output.Info(" ├── secrets.yaml # Sensitive data")
|
|
output.Info(" ├── .gitignore # Git ignore rules")
|
|
output.Info(" └── README.md # Project documentation")
|
|
|
|
return nil
|
|
}
|