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
+32 -1
View File
@@ -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",