-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.go
42 lines (37 loc) · 1008 Bytes
/
ci.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"context"
"dagger.io/dagger"
"fmt"
"os"
)
func main() {
ctx := context.Background()
// create a Dagger client
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
if err != nil {
panic(err)
}
defer client.Close()
src := client.Host().Directory("./src")
// run test code
test := client.Container().From("golang:1.20-alpine"). // Build an gradle image with gradle and bash installed
WithDirectory("/src", src).WithWorkdir("/src"). // mount source directory to /src
WithExec([]string{"go", "test"})
out, err := test.Stdout(ctx)
if err != nil {
fmt.Printf("Error test: %s", err)
os.Exit(1)
}
fmt.Println(out)
// execute code
execute := client.Container().From("golang:1.20-alpine").
WithDirectory("/src", src).WithWorkdir("/src"). // mount source directory to /src
WithExec([]string{"go", "run", "main.go"})
out, err = execute.Stdout(ctx)
if err != nil {
fmt.Printf("Error running code: %s", err)
os.Exit(1)
}
fmt.Println(out)
}