feat: funciones infra — Docker, deploy, build y health check
Funciones impuras para gestión de contenedores: docker_build_image, docker_compose_up/down, docker_volume_create/list/remove, generate_dockerfile, write_dockerfile, go_build_binary, health_check_http, deploy_app y stop_app. Todas con tests unitarios donde aplica. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// WriteDockerfile escribe content en dir/Dockerfile.
|
||||
// Crea el directorio si no existe. Retorna el path absoluto del archivo escrito.
|
||||
func WriteDockerfile(dir, content string) (string, error) {
|
||||
absDir, err := filepath.Abs(dir)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("write_dockerfile: resolver path %s: %w", dir, err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(absDir, 0o755); err != nil {
|
||||
return "", fmt.Errorf("write_dockerfile: crear directorio %s: %w", absDir, err)
|
||||
}
|
||||
|
||||
dockerfilePath := filepath.Join(absDir, "Dockerfile")
|
||||
if err := os.WriteFile(dockerfilePath, []byte(content), 0o644); err != nil {
|
||||
return "", fmt.Errorf("write_dockerfile: escribir %s: %w", dockerfilePath, err)
|
||||
}
|
||||
|
||||
return dockerfilePath, nil
|
||||
}
|
||||
Reference in New Issue
Block a user