@@ -38,9 +38,8 @@ type Node struct {
3838 ID string `json:"id"`
3939 Name string `json:"name"`
4040
41- privateIP string `json:"-"`
42- sshEndpoint string `json:"-"`
43- adminConsoleURL string `json:"-"`
41+ privateIP string `json:"-"`
42+ sshEndpoint string `json:"-"`
4443}
4544
4645type Network struct {
@@ -154,21 +153,16 @@ func NewNode(in *ClusterInput, index int, networkID string) (*Node, error) {
154153 }
155154 node .privateIP = privateIP
156155
157- if err := ensureAssetsDir (node ); err != nil {
156+ if err := ensureTestDirs (node ); err != nil {
158157 return nil , fmt .Errorf ("ensure assets dir on node %s: %v" , node .Name , err )
159158 }
160159
161160 if err := copyScriptsToNode (node ); err != nil {
162161 return nil , fmt .Errorf ("copy scripts to node %s: %v" , node .Name , err )
163162 }
164163
165- if index == 0 {
166- in .T .Logf ("exposing port 30003 on node %s" , node .Name )
167- hostname , err := exposePort (node , "30003" )
168- if err != nil {
169- return nil , fmt .Errorf ("expose port: %v" , err )
170- }
171- node .adminConsoleURL = fmt .Sprintf ("http://%s" , hostname )
164+ if err := copyPlaywrightToNode (node ); err != nil {
165+ return nil , fmt .Errorf ("copy playwright to node %s: %v" , node .Name , err )
172166 }
173167
174168 return & node , nil
@@ -189,8 +183,8 @@ func discoverPrivateIP(node Node) (string, error) {
189183 return "" , fmt .Errorf ("find private ip starting with 10." )
190184}
191185
192- func ensureAssetsDir (node Node ) error {
193- stdout , stderr , err := runCommandOnNode (node , []string {"mkdir" , "-p" , "/assets" })
186+ func ensureTestDirs (node Node ) error {
187+ stdout , stderr , err := runCommandOnNode (node , []string {"mkdir" , "-p" , "/assets" , "/automation/playwright" })
194188 if err != nil {
195189 return fmt .Errorf ("create directory: %v: %s: %s" , err , stdout , stderr )
196190 }
@@ -232,6 +226,47 @@ func copyScriptsToNode(node Node) error {
232226 return nil
233227}
234228
229+ func copyPlaywrightToNode (node Node ) error {
230+ // Create a temporary directory for the archive
231+ tempDir , err := os .MkdirTemp ("" , "playwright-archive" )
232+ if err != nil {
233+ return fmt .Errorf ("create temp directory: %v" , err )
234+ }
235+ defer os .RemoveAll (tempDir )
236+
237+ // Create the archive, excluding node_modules, test-results, and playwright-report
238+ archivePath := filepath .Join (tempDir , "playwright.tgz" )
239+ output , err := exec .Command ("tar" ,
240+ "--exclude=node_modules" ,
241+ "--exclude=test-results" ,
242+ "--exclude=playwright-report" ,
243+ "-czf" , archivePath ,
244+ "-C" , "playwright" , "." ,
245+ ).CombinedOutput ()
246+ if err != nil {
247+ return fmt .Errorf ("create playwright archive: %v: %s" , err , string (output ))
248+ }
249+
250+ // Copy the archive to the node
251+ if err := copyFileToNode (node , archivePath , "/tmp/playwright.tgz" ); err != nil {
252+ return fmt .Errorf ("copy playwright archive to node: %v" , err )
253+ }
254+
255+ // Extract the archive in /automation
256+ _ , stderr , err := runCommandOnNode (node , []string {"tar" , "-xzf" , "/tmp/playwright.tgz" , "-C" , "/automation/playwright" })
257+ if err != nil {
258+ return fmt .Errorf ("extract playwright archive: %v: %s" , err , stderr )
259+ }
260+
261+ // Clean up the archive on the node
262+ _ , stderr , err = runCommandOnNode (node , []string {"rm" , "-f" , "/tmp/playwright.tgz" })
263+ if err != nil {
264+ return fmt .Errorf ("clean up playwright archive: %v: %s" , err , stderr )
265+ }
266+
267+ return nil
268+ }
269+
235270func getSSHEndpoint (nodeID string ) (string , error ) {
236271 output , err := exec .Command ("replicated" , "vm" , "ssh-endpoint" , nodeID ).CombinedOutput ()
237272 if err != nil {
@@ -353,43 +388,35 @@ func runCommandOnNode(node Node, line []string, envs ...map[string]string) (stri
353388 return stdout .String (), stderr .String (), err
354389}
355390
356- func (c * Cluster ) SetupPlaywrightAndRunTest (testName string , args ... string ) (string , string , error ) {
357- if err := c .SetupPlaywright (); err != nil {
358- return "" , "" , fmt .Errorf ("setup playwright: %w" , err )
359- }
360- return c .RunPlaywrightTest (testName , args ... )
361- }
362-
363- func (c * Cluster ) SetupPlaywright (envs ... map [string ]string ) error {
391+ func (c * Cluster ) BypassKurlProxy (envs ... map [string ]string ) error {
364392 c .t .Logf ("%s: bypassing kurl-proxy" , time .Now ().Format (time .RFC3339 ))
365393 _ , stderr , err := c .RunCommandOnNode (0 , []string {"bypass-kurl-proxy.sh" }, envs ... )
366394 if err != nil {
367395 return fmt .Errorf ("bypass kurl-proxy: %v: %s" , err , string (stderr ))
368396 }
369- c .t .Logf ("%s: installing playwright" , time .Now ().Format (time .RFC3339 ))
370- output , err := exec .Command ("sh" , "-c" , "cd playwright && npm ci && npx playwright install --with-deps" ).CombinedOutput ()
371- if err != nil {
372- return fmt .Errorf ("install playwright: %v: %s" , err , string (output ))
397+ return nil
398+ }
399+
400+ func (c * Cluster ) SetupPlaywright (envs ... map [string ]string ) error {
401+ c .t .Logf ("%s: installing playwright on node 0" , time .Now ().Format (time .RFC3339 ))
402+ if _ , stderr , err := c .RunCommandOnNode (0 , []string {"install-playwright.sh" }); err != nil {
403+ return fmt .Errorf ("install playwright on node 0: %v: %s" , err , string (stderr ))
373404 }
374405 return nil
375406}
376407
377408func (c * Cluster ) RunPlaywrightTest (testName string , args ... string ) (string , string , error ) {
378409 c .t .Logf ("%s: running playwright test %s" , time .Now ().Format (time .RFC3339 ), testName )
379- cmdArgs := []string {testName }
380- cmdArgs = append (cmdArgs , args ... )
381- cmd := exec .Command ("scripts/playwright.sh" , cmdArgs ... )
382- cmd .Env = os .Environ ()
383- cmd .Env = append (cmd .Env , fmt .Sprintf ("BASE_URL=%s" , c .Nodes [0 ].adminConsoleURL ))
384- cmd .Env = append (cmd .Env , "PLAYWRIGHT_DIR=./playwright" )
385- var stdout , stderr bytes.Buffer
386- cmd .Stdout = & stdout
387- cmd .Stderr = & stderr
388- err := cmd .Run ()
410+ envs := map [string ]string {
411+ "BASE_URL" : "http://localhost:30003" ,
412+ "PLAYWRIGHT_DIR" : "/automation/playwright" ,
413+ }
414+ line := append ([]string {"playwright.sh" , testName }, args ... )
415+ stdout , stderr , err := c .RunCommandOnNode (0 , line , envs )
389416 if err != nil {
390- return stdout . String () , stderr . String () , fmt .Errorf ("run playwright test %s: %v" , testName , err )
417+ return stdout , stderr , fmt .Errorf ("run playwright test %s: %v" , testName , err )
391418 }
392- return stdout . String () , stderr . String () , nil
419+ return stdout , stderr , nil
393420}
394421
395422func (c * Cluster ) generateSupportBundle (envs ... map [string ]string ) {
@@ -442,33 +469,6 @@ func (c *Cluster) copyPlaywrightReport() {
442469 }
443470}
444471
445- func exposePort (node Node , port string ) (string , error ) {
446- output , err := exec .Command ("replicated" , "vm" , "port" , "expose" , node .ID , "--port" , port ).CombinedOutput ()
447- if err != nil {
448- return "" , fmt .Errorf ("expose port: %v: %s" , err , string (output ))
449- }
450-
451- output , err = exec .Command ("replicated" , "vm" , "port" , "ls" , node .ID , "-ojson" ).Output () // stderr can break json parsing
452- if err != nil {
453- if exitErr , ok := err .(* exec.ExitError ); ok {
454- return "" , fmt .Errorf ("get port info: %w: stderr: %s: stdout: %s" , err , string (exitErr .Stderr ), string (output ))
455- }
456- return "" , fmt .Errorf ("get port info: %w: stdout: %s" , err , string (output ))
457- }
458-
459- var ports []struct {
460- Hostname string `json:"hostname"`
461- }
462- if err := json .Unmarshal (output , & ports ); err != nil {
463- return "" , fmt .Errorf ("unmarshal port info: %v" , err )
464- }
465-
466- if len (ports ) == 0 {
467- return "" , fmt .Errorf ("no ports found for node %s" , node .ID )
468- }
469- return ports [0 ].Hostname , nil
470- }
471-
472472func copyFileToNode (node Node , src , dst string ) error {
473473 scpEndpoint := strings .Replace (node .sshEndpoint , "ssh://" , "scp://" , 1 )
474474
0 commit comments