Skip to content

BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr

Optimize host working directory fetching

lotk110c71e0e693
diff --git a/core/internal/cmd/cmd.go b/core/internal/cmd/cmd.go
index a31c0d8d..b2826123 100644
--- a/core/internal/cmd/cmd.go
+++ b/core/internal/cmd/cmd.go
@@ -94,6 +94,19 @@ var (
defer dk.Close()
+ containerName := "billionmail-core-billionmail-1"
+ container, err := dk.GetContainerByName(ctx, containerName)
+ if err == nil {
+ if container.Labels != nil {
+ workingDir, exists := container.Labels["com.docker.compose.project.working_dir"]
+ if exists {
+ if workingDir != "" {
+ public.HostWorkDir = workingDir
+ }
+ }
+ }
+ }
+
// Init Rspamd worker-controller
err = rspamd.InitWorkerController()
diff --git a/core/internal/controller/settings/settings.go b/core/internal/controller/settings/settings.go
index 877efcb4..11c23487 100644
--- a/core/internal/controller/settings/settings.go
+++ b/core/internal/controller/settings/settings.go
@@ -145,8 +145,9 @@ func convertEnvToConfig(envMap map[string]string) *v1.SystemConfig {
if port := envMap["HTTPS_PORT"]; port != "" {
config.ManagePorts.HTTPS = parseInt(port, 443)
}
- HostWorkDir, err := public.GetHostWorkDir()
- if err != nil {
+
+ HostWorkDir := public.HostWorkDir
+ if HostWorkDir == "" {
HostWorkDir = projectPath
}
config.ManagePorts.Command1 = fmt.Sprintf("cd %s && echo \"PORT\" | bash bm.sh change-port", HostWorkDir)
@@ -236,34 +237,3 @@ func validateConfigValue(key, value string) error {
return nil
}
-
-//func getHostWorkDir() (string, error) {
-// public.DockerApiFromCtx()
-// dockerapi, err := docker.NewDockerAPI()
-// if err != nil {
-// return "", fmt.Errorf("failed to initialize docker client: %w", err)
-// }
-//
-// containerName := "billionmail-core-billionmail-1"
-// ctx := context.Background()
-//
-// container, err := dockerapi.GetContainerByName(ctx, containerName)
-// if err != nil {
-// return "", fmt.Errorf("failed to get container '%s': %w", containerName, err)
-// }
-//
-// if container.Labels == nil {
-// return "", fmt.Errorf("container '%s' has no labels", containerName)
-// }
-//
-// workingDir, exists := container.Labels["com.docker.compose.project.working_dir"]
-// if !exists {
-// return "", fmt.Errorf("container '%s' missing working directory label", containerName)
-// }
-//
-// if workingDir == "" {
-// return "", fmt.Errorf("working directory label is empty for container '%s'", containerName)
-// }
-//
-// return workingDir, nil
-//}
diff --git a/core/internal/service/public/common.go b/core/internal/service/public/common.go
index 1669f409..c9c6befc 100644
--- a/core/internal/service/public/common.go
+++ b/core/internal/service/public/common.go
@@ -149,6 +149,8 @@ var CodeMap = map[int]api_v1.StandardRes{
},
}
+var HostWorkDir string //Host working directory
+
// Convert string to integer
func IpToLong(ip string) int64 {
if IsIpv4(ip) {
@@ -2641,33 +2643,3 @@ func LoadEnvFile() (map[string]string, error) {
return envMap, nil
}
-
-func GetHostWorkDir() (string, error) {
- dockerapi, err := docker.NewDockerAPI()
- if err != nil {
- return "", fmt.Errorf("failed to initialize docker client: %w", err)
- }
-
- containerName := "billionmail-core-billionmail-1"
- ctx := context.Background()
-
- container, err := dockerapi.GetContainerByName(ctx, containerName)
- if err != nil {
- return "", fmt.Errorf("failed to get container '%s': %w", containerName, err)
- }
-
- if container.Labels == nil {
- return "", fmt.Errorf("container '%s' has no labels", containerName)
- }
-
- workingDir, exists := container.Labels["com.docker.compose.project.working_dir"]
- if !exists {
- return "", fmt.Errorf("container '%s' missing working directory label", containerName)
- }
-
- if workingDir == "" {
- return "", fmt.Errorf("working directory label is empty for container '%s'", containerName)
- }
-
- return workingDir, nil
-}