Serve postgres's consumers the port its server is published on, not the container's 5432 (issue 957)
mesh/merge-gate head deb2020bd47d merged into trunk 5652a1494493 — pass: builds postgres, sent nowhere; no bus step; 2 wait(s) for a person; every machine …
mesh/repo-check head deb2020bd47d merged into trunk 5652a1494493 — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-…
mesh/delivery delivered
mesh/merge-gate head deb2020bd47d merged into trunk 5652a1494493 — pass: builds postgres, sent nowhere; no bus step; 2 wait(s) for a person; every machine …
mesh/repo-check head deb2020bd47d merged into trunk 5652a1494493 — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-…
mesh/delivery delivered
On novox postgres is published 6852:5432; handed 5432, gitea and keycloak reached nothing once their files were filled from postgres's entry.
This commit is contained in:
@@ -122,6 +122,38 @@ func NewClient(conn Conn, dial Dialer) *Client {
|
||||
|
||||
var unfilled = regexp.MustCompile(`^\$\{[^}]*\}$`)
|
||||
|
||||
// portFromEnv is the port postgres's server is published on, on its machine: MESH_POSTGRES_PORT, else
|
||||
// MESH_PROVISION_POSTGRES_PORT, the seat's twin (mesh-controller's internal/envfile.Placed pattern: which port
|
||||
// this machine actually put mesh-store at, when that differs from the connection string's; empty, or a
|
||||
// placeholder the mesh never filled, adds nothing), else the connection string's port, else 5432. It is both
|
||||
// the port this code reaches the server on and the port its consumers are served (issue 957).
|
||||
func portFromEnv(env func(string) string, u *url.URL) int {
|
||||
seatPort := strings.TrimSpace(env("MESH_PROVISION_POSTGRES_PORT"))
|
||||
if unfilled.MatchString(seatPort) {
|
||||
seatPort = ""
|
||||
}
|
||||
portSource := firstOf(env("MESH_POSTGRES_PORT"), seatPort)
|
||||
if portSource == "" && u != nil {
|
||||
portSource = u.Port()
|
||||
}
|
||||
port, err := strconv.Atoi(portSource)
|
||||
if err != nil || port == 0 {
|
||||
return 5432
|
||||
}
|
||||
return port
|
||||
}
|
||||
|
||||
// publishedPort is portFromEnv read from the environment alone, its connection string parsed here.
|
||||
func publishedPort(env func(string) string) int {
|
||||
var u *url.URL
|
||||
if raw := env("MESH_PROVISION_POSTGRES"); raw != "" {
|
||||
if parsed, err := url.Parse(raw); err == nil {
|
||||
u = parsed
|
||||
}
|
||||
}
|
||||
return portFromEnv(env, u)
|
||||
}
|
||||
|
||||
// ClientFromEnv builds the client from the module's words. MESH_POSTGRES_* first (the documented
|
||||
// names), then the MESH_PROVISION_* keys the manifest sets. Fails without a host and an admin password.
|
||||
func ClientFromEnv(env func(string) string) (*Client, error) {
|
||||
@@ -135,21 +167,7 @@ func ClientFromEnv(env func(string) string) (*Client, error) {
|
||||
if host == "" && u != nil {
|
||||
host = u.Hostname()
|
||||
}
|
||||
// MESH_PROVISION_POSTGRES_PORT is the seat's twin (mesh-controller's internal/envfile.Placed
|
||||
// pattern): which port this machine actually put mesh-store at, when that differs from the
|
||||
// connection string's. Empty, or a placeholder the mesh never filled, adds nothing.
|
||||
seatPort := strings.TrimSpace(env("MESH_PROVISION_POSTGRES_PORT"))
|
||||
if unfilled.MatchString(seatPort) {
|
||||
seatPort = ""
|
||||
}
|
||||
portSource := firstOf(env("MESH_POSTGRES_PORT"), seatPort)
|
||||
if portSource == "" && u != nil {
|
||||
portSource = u.Port()
|
||||
}
|
||||
port, err := strconv.Atoi(portSource)
|
||||
if err != nil || port == 0 {
|
||||
port = 5432
|
||||
}
|
||||
port := portFromEnv(env, u)
|
||||
user := env("MESH_POSTGRES_USER")
|
||||
if user == "" && u != nil && u.User != nil {
|
||||
user = u.User.Username()
|
||||
|
||||
Reference in New Issue
Block a user