Skip to content

Commit

Permalink
ci: Test Engine provisioning on MacOS (#3774)
Browse files Browse the repository at this point in the history
- 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 <[email protected]>

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: actions/runner#904

Linux we get for free via our existing tests.

Signed-off-by: Gerhard Lazu <[email protected]>

Co-authored-by: Erik Sipsma <[email protected]>
Co-authored-by: Gerhard Lazu <[email protected]>
  • Loading branch information
3 people authored Nov 29, 2022
1 parent 7d301ac commit 5631982
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 5 additions & 5 deletions internal/engineconn/dockerprovision/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down
13 changes: 9 additions & 4 deletions provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package dagger

import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5631982

Please sign in to comment.