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,15 @@ 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
6059}
6160
6261func commonContainer (
@@ -70,7 +69,6 @@ func commonContainer(
7069 command []string ,
7170 network string ,
7271 alias string ,
73- endpointModifier func (m map [string ]* network.EndpointSettings ),
7472) (testcontainers.Container , error ) {
7573 req := testcontainers.ContainerRequest {
7674 Name : name ,
@@ -83,9 +81,8 @@ func commonContainer(
8381 NetworkAliases : map [string ][]string {
8482 network : {alias },
8583 },
86- WaitingFor : waitStrategy ,
87- EndpointSettingsModifier : endpointModifier ,
88- Cmd : command ,
84+ WaitingFor : waitStrategy ,
85+ Cmd : command ,
8986 }
9087 return testcontainers .GenericContainer (ctx , testcontainers.GenericContainerRequest {
9188 ContainerRequest : req ,
@@ -105,24 +102,15 @@ func newTon(in *Input) (*Output, error) {
105102 ctx := context .Background ()
106103
107104 networkName := "ton"
108- lightClientIP := "172.28.1.1"
109105 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- })
123- if err != nil {
124- return nil , err
125- }
106+ //nolint:gosec
107+ _ = exec .Command ("docker" , "network" , "create" ,
108+ "--driver=bridge" ,
109+ "--attachable" ,
110+ fmt .Sprintf ("--subnet=%s" , lightCLientSubNet ),
111+ "--label=framework=ctf" ,
112+ networkName ,
113+ )
126114
127115 tonServices := []containerTemplate {
128116 {
@@ -139,11 +127,6 @@ func newTon(in *Input) (*Output, error) {
139127 }).WithStartupTimeout (2 * time .Minute ),
140128 Network : networkName ,
141129 Alias : "genesis" ,
142- EndpointSettingsModifier : func (m map [string ]* network.EndpointSettings ) {
143- m [networkName ].IPAMConfig = & network.EndpointIPAMConfig {
144- IPv4Address : lightClientIP ,
145- }
146- },
147130 Mounts : testcontainers.ContainerMounts {
148131 {
149132 Source : testcontainers.GenericVolumeMountSource {Name : "shared-data" },
@@ -206,22 +189,6 @@ func newTon(in *Input) (*Output, error) {
206189 Network : networkName ,
207190 Alias : "tonhttpapi" ,
208191 },
209- {
210- Name : "explorer" ,
211- Image : "ghcr.io/neodix42/mylocalton-docker-explorer:latest" ,
212- Env : map [string ]string {
213- "SERVER_PORT" : "8080" ,
214- },
215- Mounts : testcontainers.ContainerMounts {
216- {
217- Source : testcontainers.GenericVolumeMountSource {Name : "shared-data" },
218- Target : "/usr/share/data" ,
219- },
220- },
221- Ports : []string {"8080:8080/tcp" },
222- Network : networkName ,
223- Alias : "explorer" ,
224- },
225192 {
226193 Name : "faucet" ,
227194 Image : "ghcr.io/neodix42/mylocalton-docker-faucet:latest" ,
@@ -245,6 +212,22 @@ func newTon(in *Input) (*Output, error) {
245212 }
246213
247214 tonIndexingAndObservability := []containerTemplate {
215+ {
216+ Name : "explorer" ,
217+ Image : "ghcr.io/neodix42/mylocalton-docker-explorer:latest" ,
218+ Env : map [string ]string {
219+ "SERVER_PORT" : "8080" ,
220+ },
221+ Mounts : testcontainers.ContainerMounts {
222+ {
223+ Source : testcontainers.GenericVolumeMountSource {Name : "shared-data" },
224+ Target : "/usr/share/data" ,
225+ },
226+ },
227+ Ports : []string {"8080:8080/tcp" },
228+ Network : networkName ,
229+ Alias : "explorer" ,
230+ },
248231 {
249232 Name : "index-worker" ,
250233 Image : "toncenter/ton-indexer-worker:v1.2.0-test" ,
@@ -289,7 +272,7 @@ func newTon(in *Input) (*Output, error) {
289272
290273 containers := make ([]testcontainers.Container , 0 )
291274 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 )
275+ c , err := commonContainer (ctx , s .Name , s .Image , s .Env , s .Mounts , s .Ports , s .WaitFor , s .Command , s .Network , s .Alias )
293276 if err != nil {
294277 return nil , fmt .Errorf ("failed to start %s: %v" , s .Name , err )
295278 }
@@ -298,7 +281,7 @@ func newTon(in *Input) (*Output, error) {
298281 // no need for indexers and block explorers in CI
299282 if os .Getenv ("CI" ) != "" {
300283 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 )
284+ c , err := commonContainer (ctx , s .Name , s .Image , s .Env , s .Mounts , s .Ports , s .WaitFor , s .Command , s .Network , s .Alias )
302285 if err != nil {
303286 return nil , fmt .Errorf ("failed to start %s: %v" , s .Name , err )
304287 }
0 commit comments