Files
fn_registry/functions/infra/generate_dockerfile.md
T
egutierrez 1d45f232c6 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>
2026-03-30 14:24:12 +02:00

1.6 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports tested tests test_file_path file_path
generate_dockerfile function go infra 1.0.0 pure func GenerateDockerfile(binaryName string, port int, envVars map[string]string) string 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.
docker
dockerfile
go
build
deploy
infra
pure
false
fmt
sort
strings
true
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
functions/infra/generate_dockerfile_test.go functions/infra/generate_dockerfile.go

Ejemplo

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.