From 96f639c0563ccf959dd89e946db33cf6f3c599c4 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 29 Oct 2022 00:11:22 +0200 Subject: [PATCH] with further --- main.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 2dfcff3..f33d348 100644 --- a/main.go +++ b/main.go @@ -27,11 +27,27 @@ func build(repoUrl string) error { // 1. Get a context ctx := context.Background() // 2. Initialize dagger client - client, err := dagger.Connect(ctx) + client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout)) if err != nil { return err } defer client.Close() - + // 3. Clone the repo using Dagger + repo := client.Git(repoUrl) + src, err := repo.Branch("main").Tree().ID(ctx) + if err != nil { + return err + } + // 4. Load the golang image + golang := client.Container().From("golang:latest") + // 5. Mount the cloned repo to the golang image + golang = golang.WithMountedDirectory("/src", src).WithWorkdir("/src") + // 6. Do the go build + _, err = golang.Exec(dagger.ContainerExecOpts{ + Args: []string{"go", "build", "-o", "build/"}, + }).ExitCode(ctx) + if err != nil { + return err + } return nil }