diff --git a/internal/tui/config.go b/internal/tui/config.go index e6022ed..308a9b5 100644 --- a/internal/tui/config.go +++ b/internal/tui/config.go @@ -46,7 +46,7 @@ func GenerateConfigTOML(cv ConfigValues) (string, error) { // [log] — hardcoded defaults sb.WriteString("[log]\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 } diff --git a/internal/tui/docker.go b/internal/tui/docker.go index 574f2b3..cfc2d31 100644 --- a/internal/tui/docker.go +++ b/internal/tui/docker.go @@ -3,11 +3,14 @@ package tui import ( "fmt" "os/exec" + "os/user" "path/filepath" "strings" "time" ) +const networkName = "app-dono_app" + func RunContainer(image string, name string, port int) error { cmd := exec.Command( @@ -45,11 +48,28 @@ func PushFileToContainer(container, filePath, destinationPath string) bool { 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 { containerName := "vproxy" removeExistingContainer(containerName) + if err := EnsureNetwork(networkName); err != nil { + return err + } + absPath, err := filepath.Abs(envFilePath) if err != nil { return fmt.Errorf("erro ao resolver caminho absoluto: %w", err) @@ -58,7 +78,7 @@ func RunWireguardDockerContainer(envFilePath string, cv ConfigValues) error { cmd := exec.Command( "docker", "run", "-it", "-d", "--name", containerName, - "--network", "app-dono_app", + "--network", networkName, "--restart", "unless-stopped", "--cap-add=NET_ADMIN", "--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 { removeExistingContainer(containerName) + if err := EnsureNetwork(networkName); err != nil { + return err + } + absPath, err := filepath.Abs(configPath) if err != nil { 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( "docker", "run", "-d", + "-u", uidGid, "-p", fmt.Sprintf("%s:8080", cv.Server["port"]), "--name", containerName, "--network", "app-dono_app", diff --git a/internal/tui/model.go b/internal/tui/model.go index e3db2f4..9ee78a0 100644 --- a/internal/tui/model.go +++ b/internal/tui/model.go @@ -228,7 +228,7 @@ func InitialModel() Model { { Id: "central_server_url", Label: "URL do Servidor Central", - Placeholder: "https://servidor:8443", + Placeholder: "https://app-dono-api.vitruvio.com.br:8443", Default: cfg.Application.CentralServerURL, Type: FieldTypeText, },