44
examples/config.example.yaml
Archivo normal
44
examples/config.example.yaml
Archivo normal
@@ -0,0 +1,44 @@
|
||||
# Example Buque Configuration
|
||||
|
||||
# List of managed environments
|
||||
environments:
|
||||
- name: webapp
|
||||
path: /path/to/webapp
|
||||
compose_file: docker-compose.yml
|
||||
enabled: true
|
||||
labels:
|
||||
team: frontend
|
||||
environment: production
|
||||
created_at: 2024-01-01T00:00:00Z
|
||||
updated_at: 2024-01-01T00:00:00Z
|
||||
|
||||
- name: api
|
||||
path: /path/to/api
|
||||
compose_file: docker-compose.yml
|
||||
enabled: true
|
||||
labels:
|
||||
team: backend
|
||||
environment: production
|
||||
created_at: 2024-01-01T00:00:00Z
|
||||
updated_at: 2024-01-01T00:00:00Z
|
||||
|
||||
# Nginx-proxy configuration
|
||||
nginx_proxy:
|
||||
enabled: true
|
||||
network_name: nginx-proxy
|
||||
container_name: nginx-proxy
|
||||
path: /home/user/.buque/nginx-proxy
|
||||
http_port: 80
|
||||
https_port: 443
|
||||
ssl_enabled: true
|
||||
labels:
|
||||
managed_by: buque
|
||||
|
||||
# Docker configuration
|
||||
docker:
|
||||
host: "" # Leave empty to use default
|
||||
api_version: "" # Leave empty to auto-negotiate
|
||||
compose_version: "v2" # or "v1" for docker-compose
|
||||
|
||||
# Optional: Update schedule (cron format)
|
||||
# update_schedule: "0 2 * * 0" # Every Sunday at 2 AM
|
||||
28
examples/docker-compose.example.yml
Archivo normal
28
examples/docker-compose.example.yml
Archivo normal
@@ -0,0 +1,28 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
web:
|
||||
image: nginx:alpine
|
||||
container_name: example-web
|
||||
restart: unless-stopped
|
||||
expose:
|
||||
- "80"
|
||||
environment:
|
||||
# Required for nginx-proxy
|
||||
- VIRTUAL_HOST=example.com
|
||||
- VIRTUAL_PORT=80
|
||||
# Optional: Let's Encrypt SSL
|
||||
- LETSENCRYPT_HOST=example.com
|
||||
- LETSENCRYPT_EMAIL=admin@example.com
|
||||
volumes:
|
||||
- ./html:/usr/share/nginx/html:ro
|
||||
networks:
|
||||
- nginx-proxy
|
||||
labels:
|
||||
# Buque labels for tracking
|
||||
- "buque.environment=example"
|
||||
- "buque.managed=true"
|
||||
|
||||
networks:
|
||||
nginx-proxy:
|
||||
external: true
|
||||
59
examples/docker-compose.multi-service.yml
Archivo normal
59
examples/docker-compose.multi-service.yml
Archivo normal
@@ -0,0 +1,59 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
image: myapp:latest
|
||||
container_name: myapp
|
||||
restart: unless-stopped
|
||||
expose:
|
||||
- "3000"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- VIRTUAL_HOST=myapp.example.com
|
||||
- VIRTUAL_PORT=3000
|
||||
- LETSENCRYPT_HOST=myapp.example.com
|
||||
- LETSENCRYPT_EMAIL=admin@example.com
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
networks:
|
||||
- nginx-proxy
|
||||
- internal
|
||||
labels:
|
||||
- "buque.environment=myapp"
|
||||
- "buque.managed=true"
|
||||
|
||||
database:
|
||||
image: postgres:15-alpine
|
||||
container_name: myapp-db
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- POSTGRES_DB=myapp
|
||||
- POSTGRES_USER=myapp
|
||||
- POSTGRES_PASSWORD=changeme
|
||||
volumes:
|
||||
- db-data:/var/lib/postgresql/data
|
||||
networks:
|
||||
- internal
|
||||
labels:
|
||||
- "buque.environment=myapp"
|
||||
- "buque.managed=true"
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: myapp-redis
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- internal
|
||||
labels:
|
||||
- "buque.environment=myapp"
|
||||
- "buque.managed=true"
|
||||
|
||||
networks:
|
||||
nginx-proxy:
|
||||
external: true
|
||||
internal:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
db-data:
|
||||
134
examples/example_usage.go
Archivo normal
134
examples/example_usage.go
Archivo normal
@@ -0,0 +1,134 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/yourusername/buque/internal/config"
|
||||
"github.com/yourusername/buque/internal/docker"
|
||||
"github.com/yourusername/buque/internal/models"
|
||||
"github.com/yourusername/buque/internal/stats"
|
||||
)
|
||||
|
||||
// This is an example of using Buque as a library in your own Go code
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Initialize configuration manager
|
||||
configMgr := config.NewManager("")
|
||||
cfg, err := configMgr.Load()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load config: %v", err)
|
||||
}
|
||||
|
||||
// Create Docker Compose manager
|
||||
compose, err := docker.NewComposeManager()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create compose manager: %v", err)
|
||||
}
|
||||
|
||||
// Create stats collector
|
||||
collector, err := stats.NewCollector()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create stats collector: %v", err)
|
||||
}
|
||||
defer collector.Close()
|
||||
|
||||
// Example 1: Start all enabled environments
|
||||
fmt.Println("Starting all enabled environments...")
|
||||
for _, env := range cfg.Environments {
|
||||
if !env.Enabled {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("Starting %s...\n", env.Name)
|
||||
if err := compose.Up(ctx, env, true); err != nil {
|
||||
log.Printf("Failed to start %s: %v", env.Name, err)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("✓ %s started\n", env.Name)
|
||||
}
|
||||
|
||||
// Wait a bit for containers to start
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
// Example 2: Collect and display statistics
|
||||
fmt.Println("\nCollecting container statistics...")
|
||||
containerStats, err := collector.CollectAll(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to collect stats: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("\nRunning containers: %d\n", len(containerStats))
|
||||
for _, stat := range containerStats {
|
||||
fmt.Printf(" %s: CPU=%.2f%% Memory=%s\n",
|
||||
stat.Name,
|
||||
stat.CPUPercentage,
|
||||
stats.FormatBytes(stat.MemoryUsage))
|
||||
}
|
||||
|
||||
// Example 3: Get aggregated statistics
|
||||
aggStats, err := collector.GetAggregatedStats(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get aggregated stats: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("\nAggregated Statistics:\n")
|
||||
fmt.Printf(" Total Containers: %d\n", aggStats.TotalContainers)
|
||||
fmt.Printf(" Total CPU: %.2f%%\n", aggStats.TotalCPUPercent)
|
||||
fmt.Printf(" Total Memory: %s\n", stats.FormatBytes(aggStats.TotalMemoryUsage))
|
||||
|
||||
// Example 4: Add a new environment programmatically
|
||||
newEnv := models.Environment{
|
||||
Name: "test-app",
|
||||
Path: "/path/to/test-app",
|
||||
ComposeFile: "docker-compose.yml",
|
||||
Enabled: true,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
|
||||
if err := configMgr.AddEnvironment(newEnv); err != nil {
|
||||
log.Printf("Failed to add environment: %v", err)
|
||||
} else {
|
||||
fmt.Printf("\n✓ Added new environment: %s\n", newEnv.Name)
|
||||
}
|
||||
|
||||
// Example 5: Pull images for an environment
|
||||
if len(cfg.Environments) > 0 {
|
||||
env := cfg.Environments[0]
|
||||
fmt.Printf("\nPulling images for %s...\n", env.Name)
|
||||
if err := compose.Pull(ctx, env); err != nil {
|
||||
log.Printf("Failed to pull images: %v", err)
|
||||
} else {
|
||||
fmt.Printf("✓ Images pulled successfully\n")
|
||||
}
|
||||
}
|
||||
|
||||
// Example 6: Continuous monitoring (runs for 30 seconds)
|
||||
fmt.Println("\nStarting continuous monitoring for 30 seconds...")
|
||||
monitorCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
err = collector.MonitorContinuously(monitorCtx, 5*time.Second, func(stats []models.ContainerStats) {
|
||||
fmt.Printf("\n[%s] Active containers: %d\n",
|
||||
time.Now().Format("15:04:05"),
|
||||
len(stats))
|
||||
|
||||
for _, stat := range stats {
|
||||
fmt.Printf(" %s: CPU=%.1f%% Mem=%.1f%%\n",
|
||||
stat.Name,
|
||||
stat.CPUPercentage,
|
||||
stat.MemoryPercent)
|
||||
}
|
||||
})
|
||||
|
||||
if err != nil && err != context.DeadlineExceeded {
|
||||
log.Printf("Monitoring error: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("\nExample completed!")
|
||||
}
|
||||
Referencia en una nueva incidencia
Block a user