From 5631982001409d812175e7aaa3f0d69718d19b24 Mon Sep 17 00:00:00 2001 From: Guillaume de Rouville <31691250+grouville@users.noreply.github.com> Date: Tue, 29 Nov 2022 21:04:42 +0100 Subject: [PATCH] ci: Test Engine provisioning on MacOS (#3774) - First: setup Docker - Then: checkout repository - Next: setup Go & run Go SDK tests - Last: setup Python & run Python SDK tests Signed-off-by: Guillaume de Rouville For the time being, let's keep this one simple, remove the matrix, and stick to macOS only. Windows container support on hosted GitHub Actions runners is unlikely: https://github.com/actions/runner/issues/904 Linux we get for free via our existing tests. Signed-off-by: Gerhard Lazu Co-authored-by: Erik Sipsma Co-authored-by: Gerhard Lazu --- internal/engineconn/dockerprovision/image.go | 10 +++++----- provision_test.go | 13 +++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/internal/engineconn/dockerprovision/image.go b/internal/engineconn/dockerprovision/image.go index d0c90914a..514ac3c24 100644 --- a/internal/engineconn/dockerprovision/image.go +++ b/internal/engineconn/dockerprovision/image.go @@ -62,7 +62,7 @@ func (c *DockerImage) Connect(ctx context.Context, cfg *engineconn.Config) (*htt if _, err := os.Stat(engineSessionBinPath); os.IsNotExist(err) { tmpbin, err := os.CreateTemp(cacheDir, "temp-"+engineSessionBinName) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to create temp file: %w", err) } defer tmpbin.Close() defer os.Remove(tmpbin.Name()) @@ -89,16 +89,16 @@ func (c *DockerImage) Connect(ctx context.Context, cfg *engineconn.Config) (*htt } if err := tmpbin.Close(); err != nil { - return nil, err + return nil, fmt.Errorf("failed to close temporary file: %w", err) } // TODO: verify checksum? // Cache the bin for future runs. if err := os.Rename(tmpbin.Name(), engineSessionBinPath); err != nil { - return nil, err + return nil, fmt.Errorf("failed to rename %q to %q: %w", tmpbin.Name(), engineSessionBinPath, err) } } else if err != nil { - return nil, err + return nil, fmt.Errorf("failed to stat %q: %w", engineSessionBinPath, err) } entries, err := os.ReadDir(cacheDir) @@ -132,7 +132,7 @@ func (c *DockerImage) Connect(ctx context.Context, cfg *engineconn.Config) (*htt defaultDaggerRunnerHost := "docker-image://" + c.imageRef addr, childStdin, err := bin.StartEngineSession(ctx, cfg.LogOutput, defaultDaggerRunnerHost, engineSessionBinPath, args...) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to start engine session bin: %w", err) } c.childStdin = childStdin diff --git a/provision_test.go b/provision_test.go index 0b8905289..4e97d97ac 100644 --- a/provision_test.go +++ b/provision_test.go @@ -2,9 +2,11 @@ package dagger import ( "context" + "fmt" "os" "os/exec" "path/filepath" + "runtime" "strconv" "strings" "testing" @@ -52,20 +54,23 @@ func TestImageProvision(t *testing.T) { t.Fatalf("failed to create container: %s", output) } - parallelism := 30 + parallelism := runtime.NumCPU() start := make(chan struct{}) var eg errgroup.Group for i := 0; i < parallelism; i++ { eg.Go(func() error { <-start - c, err := Connect(ctx) + c, err := Connect(ctx, WithLogOutput(os.Stderr)) if err != nil { - return err + return fmt.Errorf("failed to connect: %w", err) } defer c.Close() // do a trivial query to ensure the engine is actually there _, err = c.Container().From("alpine:3.16").ID(ctx) - return err + if err != nil { + return fmt.Errorf("failed to query: %w", err) + } + return nil }) } close(start)