fix: criar container com usuário, logs json e criar network

This commit is contained in:
tkinaba
2026-05-20 16:09:58 -03:00
parent 0fc3c65259
commit dedbae0c07
3 changed files with 34 additions and 3 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ func GenerateConfigTOML(cv ConfigValues) (string, error) {
// [log] — hardcoded defaults // [log] — hardcoded defaults
sb.WriteString("[log]\n") sb.WriteString("[log]\n")
sb.WriteString("level = \"debug\"\n") sb.WriteString("level = \"debug\"\n")
sb.WriteString("format = \"text\" # Options: \"json\" or \"text\"\n") sb.WriteString("format = \"json\" # Options: \"json\" or \"text\"\n")
return sb.String(), nil return sb.String(), nil
} }
+32 -1
View File
@@ -3,11 +3,14 @@ package tui
import ( import (
"fmt" "fmt"
"os/exec" "os/exec"
"os/user"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
) )
const networkName = "app-dono_app"
func RunContainer(image string, name string, port int) error { func RunContainer(image string, name string, port int) error {
cmd := exec.Command( cmd := exec.Command(
@@ -45,11 +48,28 @@ func PushFileToContainer(container, filePath, destinationPath string) bool {
return err == nil return err == nil
} }
func EnsureNetwork(name string) error {
cmd := exec.Command("docker", "network", "inspect", name)
if err := cmd.Run(); err == nil {
return nil
}
cmd = exec.Command("docker", "network", "create", name)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("erro ao criar network %s: %w\noutput", name, err, string(out))
}
return nil
}
func RunWireguardDockerContainer(envFilePath string, cv ConfigValues) error { func RunWireguardDockerContainer(envFilePath string, cv ConfigValues) error {
containerName := "vproxy" containerName := "vproxy"
removeExistingContainer(containerName) removeExistingContainer(containerName)
if err := EnsureNetwork(networkName); err != nil {
return err
}
absPath, err := filepath.Abs(envFilePath) absPath, err := filepath.Abs(envFilePath)
if err != nil { if err != nil {
return fmt.Errorf("erro ao resolver caminho absoluto: %w", err) return fmt.Errorf("erro ao resolver caminho absoluto: %w", err)
@@ -58,7 +78,7 @@ func RunWireguardDockerContainer(envFilePath string, cv ConfigValues) error {
cmd := exec.Command( cmd := exec.Command(
"docker", "run", "-it", "-d", "docker", "run", "-it", "-d",
"--name", containerName, "--name", containerName,
"--network", "app-dono_app", "--network", networkName,
"--restart", "unless-stopped", "--restart", "unless-stopped",
"--cap-add=NET_ADMIN", "--cap-add=NET_ADMIN",
"--device", "/dev/net/tun:/dev/net/tun", "--device", "/dev/net/tun:/dev/net/tun",
@@ -81,13 +101,24 @@ func RunWireguardDockerContainer(envFilePath string, cv ConfigValues) error {
func RunAppClienteContainer(image, containerName, configPath, configDestinationPath string, cv ConfigValues) error { func RunAppClienteContainer(image, containerName, configPath, configDestinationPath string, cv ConfigValues) error {
removeExistingContainer(containerName) removeExistingContainer(containerName)
if err := EnsureNetwork(networkName); err != nil {
return err
}
absPath, err := filepath.Abs(configPath) absPath, err := filepath.Abs(configPath)
if err != nil { if err != nil {
return fmt.Errorf("erro ao resolver caminho absoluto: %w", err) return fmt.Errorf("erro ao resolver caminho absoluto: %w", err)
} }
currentUser, err := user.Current()
if err != nil {
return err
}
uidGid := fmt.Sprintf("%s:%s", currentUser.Uid, currentUser.Gid)
cmd := exec.Command( cmd := exec.Command(
"docker", "run", "-d", "docker", "run", "-d",
"-u", uidGid,
"-p", fmt.Sprintf("%s:8080", cv.Server["port"]), "-p", fmt.Sprintf("%s:8080", cv.Server["port"]),
"--name", containerName, "--name", containerName,
"--network", "app-dono_app", "--network", "app-dono_app",
+1 -1
View File
@@ -228,7 +228,7 @@ func InitialModel() Model {
{ {
Id: "central_server_url", Id: "central_server_url",
Label: "URL do Servidor Central", Label: "URL do Servidor Central",
Placeholder: "https://servidor:8443", Placeholder: "https://app-dono-api.vitruvio.com.br:8443",
Default: cfg.Application.CentralServerURL, Default: cfg.Application.CentralServerURL,
Type: FieldTypeText, Type: FieldTypeText,
}, },