-
Notifications
You must be signed in to change notification settings - Fork 393
/
resolver.go
76 lines (67 loc) · 1.93 KB
/
resolver.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package buildcontext
import (
"context"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/client/llb"
"github.com/vladaionescu/earthly/conslogging"
"github.com/vladaionescu/earthly/domain"
)
// Data represents a resolved target's build context data.
type Data struct {
// EarthfilePath is the local path where the build.earth file can be found.
EarthfilePath string
// BuildContext is the state to use for the build.
BuildContext llb.State
// GitMetadata contains git metadata information.
GitMetadata *GitMetadata
// Target is the earthly target.
Target domain.Target
// LocalDirs is the local dirs map to be passed as part of the buildkit solve.
LocalDirs map[string]string
}
// Resolver is a build context resolver.
type Resolver struct {
gr *gitResolver
lr *localResolver
}
// NewResolver returns a new NewResolver.
func NewResolver(bkClient *client.Client, console conslogging.ConsoleLogger, sessionID string) *Resolver {
return &Resolver{
gr: &gitResolver{
bkClient: bkClient,
console: console,
projectCache: make(map[string]*resolvedGitProject),
},
lr: &localResolver{
gitMetaCache: make(map[string]*GitMetadata),
sessionID: sessionID,
},
}
}
// Resolve returns resolved build context data.
func (r *Resolver) Resolve(ctx context.Context, target domain.Target) (*Data, error) {
localDirs := make(map[string]string)
if target.IsRemote() {
// Remote.
d, err := r.gr.resolveEarthProject(ctx, target)
if err != nil {
return nil, err
}
d.Target = TargetWithGitMeta(target, d.GitMetadata)
d.LocalDirs = localDirs
return d, nil
}
// Local.
localDirs[target.LocalPath] = target.LocalPath
d, err := r.lr.resolveLocal(ctx, target)
if err != nil {
return nil, err
}
d.Target = TargetWithGitMeta(target, d.GitMetadata)
d.LocalDirs = localDirs
return d, nil
}
// Close closes the resolver, freeing up any internal resources.
func (r *Resolver) Close() error {
return r.gr.close()
}