feat: docker_create_network y docker_remove_network en infra
Funciones para crear y eliminar redes Docker. DockerCreateNetwork usa bridge como driver por defecto. Necesarias para pipelines que orquestan múltiples contenedores en red compartida. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DockerCreateNetwork crea una red Docker con el nombre y driver dados.
|
||||
// Si el driver está vacío, usa "bridge" por defecto.
|
||||
// Devuelve el ID de la red creada.
|
||||
func DockerCreateNetwork(name, driver string) (string, error) {
|
||||
if name == "" {
|
||||
return "", fmt.Errorf("network name required")
|
||||
}
|
||||
if driver == "" {
|
||||
driver = "bridge"
|
||||
}
|
||||
|
||||
out, err := exec.Command("docker", "network", "create", "--driver", driver, name).CombinedOutput()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("docker network create %s: %s", name, strings.TrimSpace(string(out)))
|
||||
}
|
||||
|
||||
return strings.TrimSpace(string(out)), nil
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: docker_create_network
|
||||
kind: function
|
||||
lang: go
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "func DockerCreateNetwork(name, driver string) (string, error)"
|
||||
description: "Crea una red Docker con el nombre y driver dados. Si driver está vacío usa bridge por defecto. Devuelve el ID de la red creada."
|
||||
tags: [docker, network, create, infra]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: [fmt, os/exec, strings]
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "functions/infra/docker_create_network.go"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```go
|
||||
netID, err := DockerCreateNetwork("my-app-net", "bridge")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println("Network ID:", netID)
|
||||
```
|
||||
@@ -0,0 +1,16 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DockerRemoveNetwork elimina una red Docker por nombre o ID.
|
||||
func DockerRemoveNetwork(nameOrID string) error {
|
||||
out, err := exec.Command("docker", "network", "rm", nameOrID).CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("docker network rm %s: %s", nameOrID, strings.TrimSpace(string(out)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
name: docker_remove_network
|
||||
kind: function
|
||||
lang: go
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "func DockerRemoveNetwork(nameOrID string) error"
|
||||
description: "Elimina una red Docker por nombre o ID."
|
||||
tags: [docker, network, remove, infra]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: [fmt, os/exec, strings]
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "functions/infra/docker_remove_network.go"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```go
|
||||
err := DockerRemoveNetwork("my-app-net")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user