Files
fn_registry/functions/infra/generate_dockerfile.md
egutierrez 988e901066 docs: params/output semántico en 506 funciones para composabilidad
Añade campos params y output al frontmatter YAML de las 506 funciones del registry.
Cada parámetro tiene descripción semántica (qué representa, unidades, rango típico)
y cada función describe qué produce su output. Permite a agentes razonar sobre
cadenas de composición (ej: prices → log_return → sharpe_ratio) sin leer código.
2026-04-05 18:45:16 +02:00

48 lines
1.9 KiB
Markdown

---
name: generate_dockerfile
kind: function
lang: go
domain: infra
version: "1.0.0"
purity: pure
signature: "func GenerateDockerfile(binaryName string, port int, envVars map[string]string) string"
description: "Genera el texto de un Dockerfile multi-stage para una app Go. Stage build con golang:1.23-alpine, stage final con alpine:latest. Incluye ENV vars del map con orden determinista. Funcion pura sin I/O."
tags: [docker, dockerfile, go, build, deploy, infra, pure]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: [fmt, sort, strings]
params:
- name: binaryName
desc: "nombre del binario Go a ejecutar en el contenedor"
- name: port
desc: "puerto a exponer en el Dockerfile (0 omite la instruccion EXPOSE)"
- name: envVars
desc: "mapa de variables de entorno a incluir en el Dockerfile"
output: "string con el contenido del Dockerfile multi-stage"
tested: true
tests: ["contiene stage builder con golang:1.23-alpine", "contiene stage final con alpine:latest", "incluye EXPOSE cuando port mayor a cero", "no incluye EXPOSE cuando port es cero", "env vars aparecen ordenadas alfabeticamente", "binaryName aparece en ENTRYPOINT", "env vars vacias no generan instrucciones ENV"]
test_file_path: "functions/infra/generate_dockerfile_test.go"
file_path: "functions/infra/generate_dockerfile.go"
---
## Ejemplo
```go
content := GenerateDockerfile("myapp", 8080, map[string]string{
"DB_HOST": "localhost",
"PORT": "8080",
})
fmt.Println(content)
// FROM golang:1.23-alpine AS builder
// ...
// EXPOSE 8080
// ENTRYPOINT ["./myapp"]
```
## Notas
Funcion pura — no toca el sistema de archivos. Componer con WriteDockerfile para persistir el resultado. Las ENV vars se ordenan alfabeticamente para garantizar Dockerfiles deterministas (mismo input => mismo output exacto). El stage build usa CGO_ENABLED=0 para binarios estáticos compatibles con alpine. Si port <= 0, omite la instruccion EXPOSE.