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.5 KiB
Markdown
40 lines
1.5 KiB
Markdown
---
|
|
name: go_build_binary
|
|
kind: function
|
|
lang: go
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "func GoBuildBinary(projectDir, outputPath string, ldflags string, tags string) error"
|
|
description: "Compila un binario Go desde un directorio de proyecto. Si ldflags está vacío usa -s -w (strip debug). Si outputPath está vacío usa build/{dirname} dentro del projectDir. Ejecuta con CGO_ENABLED=0."
|
|
tags: [go, build, binary, compile, infra, deploy]
|
|
uses_functions: []
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: [fmt, os, os/exec, path/filepath, strings]
|
|
tested: true
|
|
tests: ["compila proyecto valido sin error", "outputPath vacio usa build/dirname por defecto", "ldflags vacio usa -s -w por defecto", "error si projectDir no existe"]
|
|
test_file_path: "functions/infra/go_build_binary_test.go"
|
|
file_path: "functions/infra/go_build_binary.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
// Compilar con opciones por defecto
|
|
err := GoBuildBinary("/home/user/apps/myapp", "", "", "")
|
|
// genera /home/user/apps/myapp/build/myapp
|
|
|
|
// Compilar con output y tags explícitos
|
|
err = GoBuildBinary("/home/user/apps/myapp", "/tmp/myapp-bin", "-s -w -X main.version=1.0", "fts5")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
```
|
|
|
|
## Notas
|
|
|
|
Usa `CGO_ENABLED=0` para binarios estáticos compatibles con imágenes alpine. El flag `-trimpath` elimina rutas absolutas del binario para reproducibilidad. Los flags `-s -w` reducen el tamaño eliminando información de debug y la tabla de símbolos. Compatible con el flujo deploy_app que genera Dockerfile multi-stage.
|