@@ -112,6 +112,54 @@ func NewNode(in *Input, pgOut *postgres.Output) (*Output, error) {
112112 return out , nil
113113}
114114
115+ // generatePortBindings generates exposed ports and port bindings
116+ // exposes default CL node port
117+ // exposes custom_ports in format "host:docker" or map 1-to-1 if only "host" port is provided
118+ func generatePortBindings (in * Input ) ([]string , nat.PortMap , error ) {
119+ httpPort := fmt .Sprintf ("%s/tcp" , DefaultHTTPPort )
120+ portBindings := nat.PortMap {
121+ nat .Port (httpPort ): []nat.PortBinding {
122+ {
123+ HostIP : "0.0.0.0" ,
124+ HostPort : fmt .Sprintf ("%d/tcp" , in .Node .HTTPPort ),
125+ },
126+ },
127+ }
128+ customPorts := make ([]string , 0 )
129+ for _ , p := range in .Node .CustomPorts {
130+ if strings .Contains (p , CustomPortSeparator ) {
131+ pp := strings .Split (p , CustomPortSeparator )
132+ if len (pp ) != 2 {
133+ return nil , nil , errors .New ("custom_ports has ':' but you must provide both ports" )
134+ }
135+ customPorts = append (customPorts , fmt .Sprintf ("%s/tcp" , pp [1 ]))
136+
137+ dockerPort := nat .Port (fmt .Sprintf ("%s/tcp" , pp [1 ]))
138+ hostPort := fmt .Sprintf ("%s/tcp" , pp [0 ])
139+ portBindings [dockerPort ] = []nat.PortBinding {
140+ {
141+ HostIP : "0.0.0.0" ,
142+ HostPort : hostPort ,
143+ },
144+ }
145+ } else {
146+ customPorts = append (customPorts , fmt .Sprintf ("%s/tcp" , p ))
147+
148+ dockerPort := nat .Port (fmt .Sprintf ("%s/tcp" , p ))
149+ hostPort := fmt .Sprintf ("%s/tcp" , p )
150+ portBindings [dockerPort ] = []nat.PortBinding {
151+ {
152+ HostIP : "0.0.0.0" ,
153+ HostPort : hostPort ,
154+ },
155+ }
156+ }
157+ }
158+ exposedPorts := []string {httpPort }
159+ exposedPorts = append (exposedPorts , customPorts ... )
160+ return exposedPorts , portBindings , nil
161+ }
162+
115163func newNode (in * Input , pgOut * postgres.Output ) (* NodeOut , error ) {
116164 ctx := context .Background ()
117165
@@ -148,52 +196,17 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
148196 return nil , err
149197 }
150198
151- httpPort := fmt .Sprintf ("%s/tcp" , DefaultHTTPPort )
152199 var containerName string
153200 if in .Node .Name != "" {
154201 containerName = in .Node .Name
155202 } else {
156203 containerName = framework .DefaultTCName ("node" )
157204 }
158205
159- portBindings := nat.PortMap {
160- nat .Port (httpPort ): []nat.PortBinding {
161- {
162- HostIP : "0.0.0.0" ,
163- HostPort : fmt .Sprintf ("%d/tcp" , in .Node .HTTPPort ),
164- },
165- },
166- }
167- customPorts := make ([]string , 0 )
168- for _ , p := range in .Node .CustomPorts {
169- if strings .Contains (p , CustomPortSeparator ) {
170- pp := strings .Split (p , CustomPortSeparator )
171- if len (pp ) != 2 {
172- return nil , errors .New ("custom_ports has ':' but you must provide both ports" )
173- }
174- customPorts = append (customPorts , fmt .Sprintf ("%s/tcp" , pp [1 ]))
175- portBindings [nat .Port (fmt .Sprintf ("%s/tcp" , pp [1 ]))] = []nat.PortBinding {
176- {
177- HostIP : "0.0.0.0" ,
178- HostPort : fmt .Sprintf ("%s/tcp" , pp [0 ]),
179- },
180- }
181- framework .L .Warn ().Str ("PortHost" , pp [0 ]).Str ("PortInternal" , pp [1 ]).Send ()
182- } else {
183- customPorts = append (customPorts , fmt .Sprintf ("%s/tcp" , p ))
184- framework .L .Warn ().Str ("Port" , p ).Send ()
185- portBindings [nat .Port (fmt .Sprintf ("%s/tcp" , p ))] = []nat.PortBinding {
186- {
187- HostIP : "0.0.0.0" ,
188- HostPort : fmt .Sprintf ("%s/tcp" , p ),
189- },
190- }
191- }
206+ exposedPorts , portBindings , err := generatePortBindings (in )
207+ if err != nil {
208+ return nil , err
192209 }
193- exposedPorts := []string {httpPort }
194- exposedPorts = append (exposedPorts , customPorts ... )
195- framework .L .Warn ().Any ("ExposedPorts" , exposedPorts ).Send ()
196-
197210 req := tc.ContainerRequest {
198211 AlwaysPullImage : in .Node .PullImage ,
199212 Image : in .Node .Image ,
0 commit comments