package infra import ( "fmt" ) // DeployApp orquesta el deploy completo de una app Go en Docker. // Pasos: genera Dockerfile → lo escribe → build image → run container (detach, port mapping). // Retorna el container ID del contenedor lanzado. func DeployApp(appDir string, imageName string, port int, envVars map[string]string) (string, error) { // 1. Generar Dockerfile (puro) content := GenerateDockerfile(imageName, port, envVars) // 2. Escribir Dockerfile a disco _, err := WriteDockerfile(appDir, content) if err != nil { return "", fmt.Errorf("deploy_app: escribir Dockerfile: %w", err) } // 3. Build de la imagen Docker tag := imageName + ":latest" _, err = DockerBuildImage(appDir, tag, nil) if err != nil { return "", fmt.Errorf("deploy_app: build imagen %s: %w", tag, err) } // 4. Ejecutar el contenedor en modo detach con port mapping portMapping := fmt.Sprintf("%d:%d", port, port) opts := DockerRunOpts{ Name: imageName, Ports: []string{portMapping}, Env: envVars, Detach: true, } containerID, err := DockerRunContainer(tag, opts) if err != nil { return "", fmt.Errorf("deploy_app: run contenedor %s: %w", imageName, err) } return containerID, nil }