90693fb32f
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>
40 lines
1.6 KiB
Markdown
40 lines
1.6 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]
|
|
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.
|