44 "context"
55 "fmt"
66 "os"
7+ "os/exec"
78 "time"
89
9- "github.com/docker/docker/api/types/network"
1010 "github.com/testcontainers/testcontainers-go"
1111 "github.com/testcontainers/testcontainers-go/wait"
1212
@@ -47,16 +47,16 @@ var (
4747)
4848
4949type containerTemplate struct {
50- Name string
51- Image string
52- Env map [string ]string
53- Mounts []testcontainers.ContainerMount
54- Ports []string
55- WaitFor wait.Strategy
56- Command []string
57- Network string
58- Alias string
59- EndpointSettingsModifier func (m map [string ]* network.EndpointSettings )
50+ Name string
51+ Image string
52+ Env map [string ]string
53+ Mounts []testcontainers.ContainerMount
54+ Ports []string
55+ WaitFor wait.Strategy
56+ Command []string
57+ Network string
58+ Alias string
59+ // EndpointSettingsModifier func(m map[string]*network.EndpointSettings)
6060}
6161
6262func commonContainer (
@@ -70,7 +70,6 @@ func commonContainer(
7070 command []string ,
7171 network string ,
7272 alias string ,
73- endpointModifier func (m map [string ]* network.EndpointSettings ),
7473) (testcontainers.Container , error ) {
7574 req := testcontainers.ContainerRequest {
7675 Name : name ,
@@ -83,9 +82,8 @@ func commonContainer(
8382 NetworkAliases : map [string ][]string {
8483 network : {alias },
8584 },
86- WaitingFor : waitStrategy ,
87- EndpointSettingsModifier : endpointModifier ,
88- Cmd : command ,
85+ WaitingFor : waitStrategy ,
86+ Cmd : command ,
8987 }
9088 return testcontainers .GenericContainer (ctx , testcontainers.GenericContainerRequest {
9189 ContainerRequest : req ,
@@ -105,25 +103,24 @@ func newTon(in *Input) (*Output, error) {
105103 ctx := context .Background ()
106104
107105 networkName := "ton"
108- lightClientIP := "172.28.1.1"
109106 lightCLientSubNet := "172.28.0.0/16"
110- _ , err := testcontainers .GenericNetwork (ctx , testcontainers.GenericNetworkRequest {
111- NetworkRequest : testcontainers.NetworkRequest {
112- Name : networkName ,
113- Labels : framework .DefaultTCLabels (),
114- Driver : "bridge" ,
115- Attachable : true ,
116- IPAM : & network.IPAM {
117- Config : []network.IPAMConfig {
118- {Subnet : lightCLientSubNet },
119- },
120- },
121- },
122- })
107+
108+ cmd := exec .Command ("docker" , "network" , "create" ,
109+ "--driver=bridge" ,
110+ "--attachable" ,
111+ fmt .Sprintf ("--subnet=%s" , lightCLientSubNet ),
112+ "--label=framework=ctf" ,
113+ networkName ,
114+ )
115+
116+ output , err := cmd .CombinedOutput ()
123117 if err != nil {
124118 return nil , err
125119 }
126120
121+ fmt .Printf ("Network '%s' created successfully\n " , networkName )
122+ fmt .Println ("Command output:" , string (output ))
123+
127124 tonServices := []containerTemplate {
128125 {
129126 Image : "ghcr.io/neodix42/mylocalton-docker:latest" ,
@@ -139,11 +136,6 @@ func newTon(in *Input) (*Output, error) {
139136 }).WithStartupTimeout (2 * time .Minute ),
140137 Network : networkName ,
141138 Alias : "genesis" ,
142- EndpointSettingsModifier : func (m map [string ]* network.EndpointSettings ) {
143- m [networkName ].IPAMConfig = & network.EndpointIPAMConfig {
144- IPv4Address : lightClientIP ,
145- }
146- },
147139 Mounts : testcontainers.ContainerMounts {
148140 {
149141 Source : testcontainers.GenericVolumeMountSource {Name : "shared-data" },
@@ -289,7 +281,7 @@ func newTon(in *Input) (*Output, error) {
289281
290282 containers := make ([]testcontainers.Container , 0 )
291283 for _ , s := range tonServices {
292- c , err := commonContainer (ctx , s .Name , s .Image , s .Env , s .Mounts , s .Ports , s .WaitFor , s .Command , s .Network , s .Alias , s . EndpointSettingsModifier )
284+ c , err := commonContainer (ctx , s .Name , s .Image , s .Env , s .Mounts , s .Ports , s .WaitFor , s .Command , s .Network , s .Alias )
293285 if err != nil {
294286 return nil , fmt .Errorf ("failed to start %s: %v" , s .Name , err )
295287 }
@@ -298,7 +290,7 @@ func newTon(in *Input) (*Output, error) {
298290 // no need for indexers and block explorers in CI
299291 if os .Getenv ("CI" ) != "" {
300292 for _ , s := range tonIndexingAndObservability {
301- c , err := commonContainer (ctx , s .Name , s .Image , s .Env , s .Mounts , s .Ports , s .WaitFor , s .Command , s .Network , s .Alias , s . EndpointSettingsModifier )
293+ c , err := commonContainer (ctx , s .Name , s .Image , s .Env , s .Mounts , s .Ports , s .WaitFor , s .Command , s .Network , s .Alias )
302294 if err != nil {
303295 return nil , fmt .Errorf ("failed to start %s: %v" , s .Name , err )
304296 }
0 commit comments