/
gomod.go
46 lines (37 loc) · 936 Bytes
/
gomod.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
43
44
45
46
package daggers
import (
"context"
"dagger.io/dagger"
"github.com/eunomie/dague"
)
var goModDefaulFiles = []string{"go.mod", "go.sum"}
func GoMod(c *Client) *dagger.Container {
return Sources(c).
WithWorkdir(c.Config.Go.AppDir).
WithExec(goModTidy())
}
func ExportGoMod(ctx context.Context, c *Client) error {
return dague.ExportFilePattern(
ctx,
GoMod(c),
"go.*",
"./",
)
}
// GoModFiles creates a directory containing the default go mod files.
func goModFiles(c *Client) *dagger.Directory {
src := c.Dagger.Host().Directory(".")
goMods := c.Dagger.Directory()
for _, f := range goModDefaulFiles {
goMods = goMods.WithFile(f, src.File(f))
}
return goMods
}
// GoModDownload runs the go mod download command.
func goModDownload() []string {
return []string{"go", "mod", "download"}
}
// GoModTidy runs the go mod tidy command.
func goModTidy() []string {
return []string{"go", "mod", "tidy", "-v"}
}