with further
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kasper Juul Hermansen 2022-10-29 00:11:22 +02:00
parent 4f65765b65
commit 96f639c056
Signed by: kjuulh
GPG Key ID: 0F95C140730F2F23

20
main.go
View File

@ -27,11 +27,27 @@ func build(repoUrl string) error {
// 1. Get a context // 1. Get a context
ctx := context.Background() ctx := context.Background()
// 2. Initialize dagger client // 2. Initialize dagger client
client, err := dagger.Connect(ctx) client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
if err != nil { if err != nil {
return err return err
} }
defer client.Close() 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 return nil
} }