-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdatabase.go
43 lines (33 loc) · 1 KB
/
database.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import "fmt"
// Database returns a ready to run Postgres container with all configuration applied.
func (p *Postgres) Database() (*Container, error) {
startOpts := []string{}
ctr := dag.
Container().
From(fmt.Sprintf("postgres:%s", p.Version))
if p.Cache {
ctr = ctr.WithMountedCache("/var/lib/postgresql/data", dag.CacheVolume("pg-data"))
}
ctr = ctr.
WithSecretVariable("POSTGRES_USER", p.User).
WithSecretVariable("POSTGRES_PASSWORD", p.Password)
// Set database name
if p.Name != "" {
ctr = ctr.WithEnvVariable("POSTGRES_DATABASE", p.Name)
}
// Set config files
if p.ConfigFile != nil {
ctr = ctr.WithFile("/etc/postgresql/postgresql.conf", p.ConfigFile)
startOpts = append(startOpts, "-c", "config_file=/etc/postgresql/postgresql.conf")
}
// Set init scripts
if p.InitScripts != nil {
ctr = ctr.WithMountedDirectory("/docker-entrypoint-initdb.d", p.InitScripts)
}
// Apply start opts
ctr = ctr.
WithExposedPort(p.Port).
WithExec(startOpts)
return ctr, nil
}