MCPcopy Create free account
hub / github.com/nhost/nhost / postgres

Function postgres

cli/dockercompose/postgres.go:12–98  ·  view source on GitHub ↗
( //nolint:funlen
	cfg *model.ConfigConfig,
	subdomain string,
	port uint,
	dataFolder string,
	volumeName string,
)

Source from the content-addressed store, hash-verified

10)
11
12func postgres( //nolint:funlen
13 cfg *model.ConfigConfig,
14 subdomain string,
15 port uint,
16 dataFolder string,
17 volumeName string,
18) (*Service, error) {
19 if err := os.MkdirAll(dataFolder+"/db", 0o755); err != nil { //nolint:mnd
20 return nil, fmt.Errorf("failed to create postgres data folder: %w", err)
21 }
22
23 f, err := os.Create(dataFolder + "/db/pg_hba_local.conf")
24 if err != nil {
25 return nil, fmt.Errorf("failed to create pg_hba_local.conf: %w", err)
26 }
27 defer f.Close()
28
29 if _, err := f.WriteString(
30 "local all all trust\nhost all all all trust\n", //nolint:dupword
31 ); err != nil {
32 return nil, fmt.Errorf("failed to write to pg_hba_local.conf: %w", err)
33 }
34
35 envars, err := appconfig.PostgresEnv(
36 cfg,
37 "local",
38 "postgres",
39 "postgres",
40 )
41 if err != nil {
42 return nil, fmt.Errorf("failed to get postgres env vars: %w", err)
43 }
44
45 env := make(map[string]string, len(envars))
46 for _, v := range envars {
47 env[v.Name] = v.Value
48 }
49
50 env["POSTGRES_DEV_INSECURE"] = "true"
51
52 return &Service{
53 Image: "nhost/postgres:" + *cfg.GetPostgres().GetVersion(),
54 DependsOn: nil,
55 EntryPoint: nil,
56 Command: []string{
57 "postgres",
58 "-c", "config_file=/etc/postgresql.conf",
59 "-c", "hba_file=/etc/pg_hba_local.conf",
60 },
61 Environment: env,
62 ExtraHosts: extraHosts(subdomain),
63 HealthCheck: &HealthCheck{
64 Test: []string{
65 "CMD-SHELL", "pg_isready -U postgres -d postgres -q",
66 },
67 Timeout: "60s",
68 Interval: "5s",
69 StartPeriod: "60s",

Callers 2

getServicesFunction · 0.85
TestPostgresFunction · 0.85

Calls 6

extraHostsFunction · 0.85
networkAliasesFunction · 0.85
ErrorfMethod · 0.80
CloseMethod · 0.65
GetVersionMethod · 0.65
WriteStringMethod · 0.45

Tested by 1

TestPostgresFunction · 0.68