ddb3fe78cb
Nuevas dependencias para ClickHouse, DuckDB, Postgres drivers. Actualizar sources.yaml con funciones extraídas. Ajustes menores en write_jupyter_launcher, write_mcp_jupyter_config y docker_run_container. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package infra
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
// DockerRunOpts opciones para ejecutar un contenedor Docker.
|
|
type DockerRunOpts struct {
|
|
Name string // Nombre del contenedor (opcional)
|
|
Ports []string // Mapeo de puertos, ej: ["8080:80", "443:443"]
|
|
Env map[string]string // Variables de entorno
|
|
Volumes []string // Bind mounts, ej: ["/host/path:/container/path"]
|
|
Detach bool // Ejecutar en background
|
|
Remove bool // Eliminar al terminar (--rm)
|
|
Network string // Red Docker (opcional)
|
|
CapAdd []string // Linux capabilities, ej: ["NET_ADMIN", "SYS_MODULE"]
|
|
Cmd []string // Comando a ejecutar en el contenedor (opcional)
|
|
}
|
|
|
|
// DockerRunContainer ejecuta un contenedor Docker nuevo con la imagen y opciones dadas.
|
|
// Devuelve el ID del contenedor creado.
|
|
func DockerRunContainer(image string, opts DockerRunOpts) (string, error) {
|
|
args := []string{"run"}
|
|
|
|
if opts.Detach {
|
|
args = append(args, "-d")
|
|
}
|
|
if opts.Remove {
|
|
args = append(args, "--rm")
|
|
}
|
|
if opts.Name != "" {
|
|
args = append(args, "--name", opts.Name)
|
|
}
|
|
if opts.Network != "" {
|
|
args = append(args, "--network", opts.Network)
|
|
}
|
|
for _, p := range opts.Ports {
|
|
args = append(args, "-p", p)
|
|
}
|
|
for k, v := range opts.Env {
|
|
args = append(args, "-e", k+"="+v)
|
|
}
|
|
for _, vol := range opts.Volumes {
|
|
args = append(args, "-v", vol)
|
|
}
|
|
for _, cap := range opts.CapAdd {
|
|
args = append(args, "--cap-add", cap)
|
|
}
|
|
|
|
args = append(args, image)
|
|
args = append(args, opts.Cmd...)
|
|
|
|
out, err := exec.Command("docker", args...).CombinedOutput()
|
|
if err != nil {
|
|
return "", fmt.Errorf("docker run %s: %s", image, strings.TrimSpace(string(out)))
|
|
}
|
|
|
|
return strings.TrimSpace(string(out)), nil
|
|
}
|