10
10
import {
11
11
GenericContainer ,
12
12
Network ,
13
- PullPolicy ,
14
13
StartedNetwork ,
15
14
StartedTestContainer ,
16
15
} from "testcontainers" ;
17
16
17
+ export interface EnvironmentSpec {
18
+ restate : {
19
+ image : string ;
20
+ env : Record < string , string > ;
21
+ pull ?: boolean ;
22
+ } ;
23
+
24
+ interpreters : {
25
+ image : string ;
26
+ env : Record < string , string > ;
27
+ pull ?: boolean ;
28
+ } ;
29
+
30
+ service : {
31
+ image : string ;
32
+ env : Record < string , string > ;
33
+ pull ?: boolean ;
34
+ } ;
35
+ }
36
+
18
37
export interface TestEnvironment {
19
38
ingressUrl : string ;
20
39
adminUrl : string ;
@@ -31,82 +50,91 @@ export interface Containers {
31
50
servicesContainer : StartedTestContainer ;
32
51
}
33
52
34
- export async function setupContainers ( ) : Promise < TestEnvironment > {
53
+ export async function setupContainers (
54
+ env : EnvironmentSpec
55
+ ) : Promise < TestEnvironment > {
56
+ console . log ( env ) ;
57
+
35
58
const network = await new Network ( ) . start ( ) ;
36
59
37
- const restate = new GenericContainer ( "ghcr.io/restatedev/ restate:main" )
60
+ const restate = new GenericContainer ( env . restate . image )
38
61
. withExposedPorts ( 8080 , 9070 )
39
62
. withNetwork ( network )
40
63
. withNetworkAliases ( "restate" )
41
- . withPullPolicy ( PullPolicy . alwaysPull ( ) )
64
+ . withPullPolicy ( {
65
+ shouldPull ( ) {
66
+ return env . restate . pull ?? true ;
67
+ } ,
68
+ } )
42
69
. withEnvironment ( {
43
70
RESTATE_LOG_FILTER : "restate=warn" ,
44
71
RESTATE_LOG_FORMAT : "json" ,
72
+ ...( env . restate ?. env ?? { } ) ,
45
73
} )
46
74
. withUlimits ( {
47
75
nproc : { soft : 65535 , hard : 65535 } ,
48
76
nofile : { soft : 65535 , hard : 65535 } ,
49
77
} )
50
78
. start ( ) ;
51
79
52
- const zero = new GenericContainer ( "ghcr.io/restatedev/e2e-node-services:main" )
53
- . withNetwork ( network )
54
- . withNetworkAliases ( "interpreter_zero" )
55
- . withPullPolicy ( PullPolicy . alwaysPull ( ) )
56
- . withEnvironment ( {
57
- PORT : "9000" ,
58
- RESTATE_LOGGING : "ERROR" ,
59
- NODE_ENV : "production" ,
60
- SERVICES : "ObjectInterpreterL0" ,
61
- } )
62
- . start ( ) ;
63
-
64
- const one = new GenericContainer ( "ghcr.io/restatedev/e2e-node-services:main" )
65
- . withNetwork ( network )
66
- . withNetworkAliases ( "interpreter_one" )
67
- . withPullPolicy ( PullPolicy . alwaysPull ( ) )
68
-
69
- . withExposedPorts ( 9001 )
70
- . withEnvironment ( {
71
- PORT : "9001" ,
80
+ const names = [ "interpreter_zero" , "interpreter_one" , "interpreter_two" ] ;
81
+ const interpreters = [ ] ;
82
+ for ( let i = 0 ; i < 3 ; i ++ ) {
83
+ const port = 9000 + i ;
84
+ const auxEnv = {
85
+ PORT : `${ port } ` ,
72
86
RESTATE_LOGGING : "ERROR" ,
73
87
NODE_ENV : "production" ,
74
- SERVICES : "ObjectInterpreterL1" ,
75
- } )
76
- . start ( ) ;
88
+ NODE_OPTIONS : "--max-old-space-size=4096" ,
89
+ SERVICES : `ObjectInterpreterL${ i } ` ,
90
+ ...( env . interpreters ?. env ?? { } ) ,
91
+ } ;
92
+ const interpreter = new GenericContainer ( env . interpreters . image )
93
+ . withNetwork ( network )
94
+ . withNetworkAliases ( names [ i ] )
95
+ . withExposedPorts ( port )
96
+ . withPullPolicy ( {
97
+ shouldPull ( ) {
98
+ return env . interpreters . pull ?? true ;
99
+ } ,
100
+ } )
101
+ . withEnvironment ( auxEnv )
102
+ . withUlimits ( {
103
+ nproc : { soft : 65535 , hard : 65535 } ,
104
+ nofile : { soft : 65535 , hard : 65535 } ,
105
+ } )
106
+ . start ( ) ;
77
107
78
- const two = new GenericContainer ( "ghcr.io/restatedev/e2e-node-services:main" )
79
- . withNetwork ( network )
80
- . withNetworkAliases ( "interpreter_two" )
81
- . withPullPolicy ( PullPolicy . alwaysPull ( ) )
82
- . withExposedPorts ( 9002 )
83
- . withEnvironment ( {
84
- PORT : "9002" ,
85
- RESTATE_LOGGING : "ERROR" ,
86
- NODE_ENV : "production" ,
87
- SERVICES : "ObjectInterpreterL2" ,
88
- } )
89
- . start ( ) ;
108
+ interpreters . push ( interpreter ) ;
109
+ }
90
110
91
- const services = new GenericContainer (
92
- "ghcr.io/restatedev/e2e-node-services:main"
93
- )
111
+ const services = new GenericContainer ( env . service . image )
94
112
. withNetwork ( network )
95
113
. withNetworkAliases ( "services" )
96
- . withPullPolicy ( PullPolicy . alwaysPull ( ) )
114
+ . withPullPolicy ( {
115
+ shouldPull ( ) {
116
+ return env . service . pull ?? true ;
117
+ } ,
118
+ } )
97
119
. withExposedPorts ( 9003 )
98
120
. withEnvironment ( {
99
121
PORT : "9003" ,
100
122
RESTATE_LOGGING : "ERROR" ,
101
123
NODE_ENV : "production" ,
124
+ NODE_OPTIONS : "--max-old-space-size=4096" ,
102
125
SERVICES : "ServiceInterpreterHelper" ,
126
+ ...( env . service ?. env ?? { } ) ,
127
+ } )
128
+ . withUlimits ( {
129
+ nproc : { soft : 65535 , hard : 65535 } ,
130
+ nofile : { soft : 65535 , hard : 65535 } ,
103
131
} )
104
132
. start ( ) ;
105
133
106
134
const restateContainer = await restate ;
107
- const interpreterZeroContainer = await zero ;
108
- const interpreterOneContainer = await one ;
109
- const interpreterTwoContainer = await two ;
135
+ const interpreterZeroContainer = await interpreters [ 0 ] ;
136
+ const interpreterOneContainer = await interpreters [ 1 ] ;
137
+ const interpreterTwoContainer = await interpreters [ 2 ] ;
110
138
const servicesContainer = await services ;
111
139
112
140
const ingressUrl = `http://${ restateContainer . getHost ( ) } :${ restateContainer . getMappedPort (
0 commit comments