@@ -9,6 +9,7 @@ package fsc
99import (
1010 "bytes"
1111 "cmp"
12+ "context"
1213 "fmt"
1314 "io"
1415 "net"
@@ -138,6 +139,27 @@ func (p *Platform) GenerateArtifacts() {
138139
139140 p .GenerateResolverMap ()
140141
142+ // update postgres config
143+ dbPorts := make (map [string ]uint16 )
144+ for _ , peer := range p .Peers {
145+ for n , pp := range peer .Options .GetPostgresPersistences () {
146+ cfg , err := postgres2 .ConfigFromDataSource (pp .DataSource )
147+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
148+
149+ // find all databases and reserve a free port
150+ port , ok := dbPorts [cfg .DBName ]
151+ if ! ok {
152+ port = p .Context .ReservePort ()
153+ dbPorts [cfg .DBName ] = port
154+ }
155+
156+ // update the port in the node options, so we store it below in the core.yaml
157+ cfg .Port = strconv .Itoa (int (port ))
158+ pp .DataSource = cfg .DataSource ()
159+ peer .Options .PutPostgresPersistence (n , * pp )
160+ }
161+ }
162+
141163 // Generate core.yaml for all fsc nodes by including all the additional configurations coming
142164 // from other platforms
143165 for _ , peer := range p .Peers {
@@ -213,19 +235,20 @@ func (p *Platform) Members() []grouper.Member {
213235
214236func (p * Platform ) PreRun () {
215237 // Start DBs
216- configs := map [string ]* postgres2.ContainerConfig {}
238+ configs := make (map [string ]* postgres2.ContainerConfig )
239+ // update data sources
217240 for _ , node := range p .Peers {
218241 for _ , sqlOpts := range node .Options .GetPostgresPersistences () {
219242 if _ , ok := configs [sqlOpts .DataSource ]; ! ok {
220- c , err := postgres2 .ReadDataSource (sqlOpts .DataSource )
243+ c , err := postgres2 .ConfigFromDataSource (sqlOpts .DataSource )
221244 gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
222245 configs [sqlOpts .DataSource ] = c
223246 }
224247
225248 }
226249 }
227250 logger .Infof ("Starting DBs for following data sources: [%s]..." , logging .Keys (configs ))
228- closeF , err := postgres2 .StartPostgresWithFmt ( collections .Values (configs ))
251+ closeF , err := postgres2 .StartMultiplePostgres ( context . TODO (), collections .Values (configs ))
229252 gomega .Expect (err ).ToNot (gomega .HaveOccurred (), "failed to start dbs" )
230253 p .cleanDB = closeF
231254}
0 commit comments