Skip to content

Commit

Permalink
Share the same client when running multiple targets via All
Browse files Browse the repository at this point in the history
Signed-off-by: Gerhard Lazu <[email protected]>
  • Loading branch information
gerhard committed Aug 15, 2023
1 parent 2d39080 commit 27fdff0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions magefiles/dagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,26 @@ func deploy(ctx context.Context, c *dagger.Client, imageRef string) {

// [lints, tests], builds, publishes & deploys a new version of the app
func All(ctx context.Context) {
mg.CtxDeps(ctx, Lint, Test, Build)

c := daggerClient(ctx)
defer c.Close()
ctx = context.WithValue(ctx, "daggerClient", c)

mg.CtxDeps(ctx, Lint, Test, Build)

imageRef := publish(ctx, c)
deploy(ctx, c, imageRef)
}

func daggerClient(ctx context.Context) *dagger.Client {
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
panic(err)
client, ok := ctx.Value("daggerClient").(*dagger.Client)
if !ok {
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
panic(err)
}
return client
}

return client
}

Expand Down

0 comments on commit 27fdff0

Please sign in to comment.