cli/dockercompose/configserver.go
Rama main · réplica de lectura del repositorio original.
package dockercompose
import (
"net/url"
"path/filepath"
"slices"
)
func configserver( //nolint: funlen
dockerURL *url.URL,
image,
rootPath,
nhostPath,
projectName,
appID string,
useTLS bool,
runServices ...*RunService,
) *Service {
bindings := make([]Volume, 0, len(runServices))
extraArgs := make([]string, len(runServices))
mountedVolumes := make([]string, 0, len(runServices))
for i, runService := range runServices {
source := filepath.Dir(runService.Path)
target := filepath.Join("/tmp", source)
targetFile := filepath.Join(target, filepath.Base(runService.Path))
extraArgs[i] = "--storage-local-run-services-path=" + targetFile
if slices.Contains(mountedVolumes, source) {
continue
}
mountedVolumes = append(mountedVolumes, source)
bindings = append(bindings, Volume{
Type: "bind",
Source: source,
Target: target,
ReadOnly: new(bool),
})
}
volumes := append(
[]Volume{
{
Type: "bind",
Source: nhostPath,
Target: "/tmp/root/nhost",
ReadOnly: new(false),
},
{
Type: "bind",
Source: rootPath,
Target: "/tmp/root",
ReadOnly: new(false),
},
},
bindings...,
)
containerDockerEndpoint := dockerURL.String()
if dockerURL.Scheme == "unix" {
volumes = append(volumes, Volume{
Type: "bind",
Source: dockerURL.Path,
Target: "/var/run/docker.sock",
ReadOnly: new(true),
// Relabel the socket with a shared SELinux label so the config
// server can reach the docker daemon on SELinux/Podman hosts.
Bind: &BindOptions{SELinux: "z"},
})
containerDockerEndpoint = defaultDockerEndpoint
}
return &Service{
Image: image,
DependsOn: map[string]DependsOn{},
EntryPoint: []string{},
Command: append([]string{
"configserver",
"--enable-playground",
"--debug",
}, extraArgs...),
Environment: map[string]string{
"DOCKER_HOST": containerDockerEndpoint,
"DOCKER_COMPOSE_PROJECT": projectName,
"NHOST_APP_ID": appID,
},
ExtraHosts: []string{},
HealthCheck: nil,
Labels: Ingresses{
{
Name: "configserver",
TLS: useTLS,
Rule: traefikHostMatch("dashboard") + "&& PathPrefix(`/v1/configserver`)",
Port: configserverPort,
Rewrite: nil,
},
{
Name: "logs",
TLS: useTLS,
Rule: traefikHostMatch("dashboard") + "&& PathPrefix(`/v1/logs`)",
Port: configserverPort,
Rewrite: nil,
},
}.Labels(),
Networks: nil,
Ports: []Port{},
Restart: "always",
User: nil,
Volumes: volumes,
WorkingDir: nil,
}
}