99 "bytes"
1010 "context"
1111 "fmt"
12- "io/ioutil"
1312 "os"
1413 "path"
1514 "strconv"
@@ -31,6 +30,7 @@ import (
3130 "gitlab.com/postgres-ai/database-lab/pkg/retrieval/engine/postgres/tools"
3231 "gitlab.com/postgres-ai/database-lab/pkg/retrieval/engine/postgres/tools/cont"
3332 "gitlab.com/postgres-ai/database-lab/pkg/retrieval/engine/postgres/tools/defaults"
33+ "gitlab.com/postgres-ai/database-lab/pkg/retrieval/engine/postgres/tools/fs"
3434 "gitlab.com/postgres-ai/database-lab/pkg/retrieval/engine/postgres/tools/health"
3535 "gitlab.com/postgres-ai/database-lab/pkg/retrieval/options"
3636 "gitlab.com/postgres-ai/database-lab/pkg/services/provision/databases/postgres/configuration"
@@ -80,6 +80,7 @@ type PhysicalOptions struct {
8080 PreprocessingScript string `yaml:"preprocessingScript"`
8181 Configs map [string ]string `yaml:"configs"`
8282 Sysctls map [string ]string `yaml:"sysctls"`
83+ Envs map [string ]string `yaml:"envs"`
8384 Scheduler * Scheduler `yaml:"scheduler"`
8485}
8586
@@ -529,11 +530,9 @@ func (p *PhysicalInitial) adjustRecoveryConfiguration(pgVersion, clonePGDataDir
529530 replicationFilename = "recovery.conf"
530531
531532 buffer .WriteString ("standby_mode = 'on'\n " )
532- buffer .WriteString ("primary_conninfo = ''\n " )
533- buffer .WriteString ("restore_command = ''\n " )
534533 }
535534
536- if err := ioutil . WriteFile (path .Join (clonePGDataDir , replicationFilename ), buffer .Bytes (), 0666 ); err != nil {
535+ if err := fs . AppendFile (path .Join (clonePGDataDir , replicationFilename ), buffer .Bytes ()); err != nil {
537536 return err
538537 }
539538
@@ -557,10 +556,7 @@ func (p *PhysicalInitial) buildContainerConfig(clonePath, promoteImage, password
557556 cont .DBLabControlLabel : cont .DBLabPromoteLabel ,
558557 cont .DBLabInstanceIDLabel : p .globalCfg .InstanceID ,
559558 },
560- Env : []string {
561- "PGDATA=" + clonePath ,
562- "POSTGRES_PASSWORD=" + password ,
563- },
559+ Env : p .getEnvironmentVariables (clonePath , password ),
564560 Image : promoteImage ,
565561 Healthcheck : health .GetConfig (
566562 p .globalCfg .Database .User (),
@@ -571,6 +567,20 @@ func (p *PhysicalInitial) buildContainerConfig(clonePath, promoteImage, password
571567 }
572568}
573569
570+ func (p * PhysicalInitial ) getEnvironmentVariables (clonePath , password string ) []string {
571+ envVariables := []string {
572+ "PGDATA=" + clonePath ,
573+ "POSTGRES_PASSWORD=" + password ,
574+ }
575+
576+ // Add user-defined environment variables.
577+ for env , value := range p .options .Envs {
578+ envVariables = append (envVariables , fmt .Sprintf ("%s=%s" , env , value ))
579+ }
580+
581+ return envVariables
582+ }
583+
574584func (p * PhysicalInitial ) buildHostConfig (ctx context.Context , clonePath string ) (* container.HostConfig , error ) {
575585 hostConfig := & container.HostConfig {
576586 Sysctls : p .options .Sysctls ,
@@ -621,6 +631,9 @@ func (p *PhysicalInitial) runPromoteCommand(ctx context.Context, containerID, cl
621631 output , err := tools .ExecCommandWithOutput (ctx , p .dockerClient , containerID , types.ExecConfig {
622632 User : defaults .Username ,
623633 Cmd : promoteCommand ,
634+ Env : []string {
635+ fmt .Sprintf ("PGCTLTIMEOUT=%d" , p .options .Promotion .HealthCheck .MaxRetries * int (p .options .Promotion .HealthCheck .Interval )),
636+ },
624637 })
625638 if err != nil {
626639 return errors .Wrap (err , "failed to promote instance" )
0 commit comments