docs: CLAUDE.md actualizado con fn run, tipos Go en functions/, bash functions
Documentación de fn run para todos los lenguajes, nueva ubicación de tipos Go, sección de uso por agentes. Añadidas funciones Bash del registry (shell, infra, core, pipelines). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: assert_docker_container_running
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "assert_docker_container_running(container_name: string) -> void"
|
||||
description: "Verifica que un contenedor Docker está corriendo. Sale con exit code 1 si no está activo, con mensaje a stderr."
|
||||
tags: [assert, docker, container, running, validation, infra, bash]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/assert_docker_container_running.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
source functions/infra/assert_docker_container_running.sh
|
||||
|
||||
assert_docker_container_running metabase
|
||||
echo "Contenedor activo, continuando..."
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Usa `docker ps --format '{{.Names}}'` con grep anclado (`^name$`) para evitar matches parciales (ej: "metabase" no matchea "metabase-test").
|
||||
|
||||
Output limpio: void en éxito. El mensaje de error en stderr no incluye lista de contenedores activos — eso es responsabilidad del pipeline/caller.
|
||||
|
||||
Requiere que `docker` esté en PATH. Combinar con `assert_command_exists` antes de llamar.
|
||||
@@ -0,0 +1,19 @@
|
||||
# assert_docker_container_running
|
||||
# --------------------------------
|
||||
# Verifica que un contenedor Docker está corriendo.
|
||||
# No produce output a stdout en caso de éxito.
|
||||
# Sale con exit code 1 si el contenedor no está corriendo,
|
||||
# con mensaje descriptivo a stderr.
|
||||
#
|
||||
# USO (sourced):
|
||||
# source assert_docker_container_running.sh
|
||||
# assert_docker_container_running metabase
|
||||
|
||||
assert_docker_container_running() {
|
||||
local container_name="$1"
|
||||
|
||||
if ! docker ps --format '{{.Names}}' | grep -q "^${container_name}$"; then
|
||||
echo "assert_docker_container_running: el contenedor '$container_name' no está corriendo" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
---
|
||||
name: docker_cp_file
|
||||
kind: function
|
||||
lang: bash
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "docker_cp_file(local_path: string, container_name: string, dest_path: string) -> string"
|
||||
description: "Copia un archivo local a un contenedor Docker y verifica que el tamaño coincide. Imprime JSON con local_size y remote_size a stdout. Sale con exit code 1 si docker cp falla o los tamaños difieren."
|
||||
tags: [docker, cp, copy, file, container, transfer, infra, bash]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
file_path: "bash/functions/infra/docker_cp_file.sh"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```bash
|
||||
source functions/infra/docker_cp_file.sh
|
||||
|
||||
result=$(docker_cp_file /home/lucas/fn_registry/registry.db metabase /registry.db)
|
||||
echo "$result"
|
||||
# {"local_size":524288,"remote_size":524288}
|
||||
|
||||
local_size=$(echo "$result" | grep -o '"local_size":[0-9]*' | cut -d: -f2)
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
La verificación de tamaño usa `docker exec stat -c%s` sobre el contenedor destino. Si `stat` no está disponible en el contenedor, `remote_size` será -1 y la función fallará.
|
||||
|
||||
Output a stdout: JSON minificado con campos `local_size` y `remote_size` (enteros, bytes).
|
||||
|
||||
Usa `printf` en lugar de `echo` para garantizar que no haya newline extra en el JSON.
|
||||
@@ -0,0 +1,33 @@
|
||||
# docker_cp_file
|
||||
# --------------
|
||||
# Copia un archivo local a un contenedor Docker y verifica que el tamaño coincide.
|
||||
# Imprime JSON con local_size y remote_size a stdout si la copia es exitosa.
|
||||
# Sale con exit code 1 si docker cp falla o si los tamaños no coinciden.
|
||||
#
|
||||
# USO (sourced):
|
||||
# source docker_cp_file.sh
|
||||
# result=$(docker_cp_file /ruta/local.db metabase /dest/path.db)
|
||||
|
||||
docker_cp_file() {
|
||||
local local_path="$1"
|
||||
local container_name="$2"
|
||||
local dest_path="$3"
|
||||
|
||||
if ! docker cp "$local_path" "${container_name}:${dest_path}" 2>/dev/null; then
|
||||
echo "docker_cp_file: fallo al copiar '$local_path' a '${container_name}:${dest_path}'" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local local_size
|
||||
local_size=$(stat -c%s "$local_path")
|
||||
|
||||
local remote_size
|
||||
remote_size=$(docker exec "$container_name" stat -c%s "$dest_path" 2>/dev/null || echo "-1")
|
||||
|
||||
if [ "$local_size" != "$remote_size" ]; then
|
||||
echo "docker_cp_file: tamaños no coinciden (local=${local_size}, remoto=${remote_size})" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
printf '{"local_size":%s,"remote_size":%s}' "$local_size" "$remote_size"
|
||||
}
|
||||
Reference in New Issue
Block a user