-
Notifications
You must be signed in to change notification settings - Fork 9
/
types.go
112 lines (92 loc) · 2.89 KB
/
types.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package build
import (
"context"
"strings"
"time"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"namespacelabs.dev/foundation/internal/artifacts/oci"
"namespacelabs.dev/foundation/internal/compute"
"namespacelabs.dev/foundation/internal/parsing/platform"
"namespacelabs.dev/foundation/internal/wscontents"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/schema/storage"
"namespacelabs.dev/foundation/std/pkggraph"
)
var (
FixedPoint = time.Unix(1, 1)
platformOverride = []specs.Platform{}
)
type Spec interface {
BuildImage(context.Context, pkggraph.SealedContext, Configuration) (compute.Computable[oci.Image], error)
PlatformIndependent() bool
}
type Plan struct {
SourcePackage schema.PackageName
SourceLabel string
BuildKind storage.Build_Kind
Spec Spec
Workspace Workspace
Platforms []specs.Platform
// The caller has given us a hint or where the built image will be uploaded
// to, in case the builder implementation can use this information for
// optimization purposes. This may be null, and an implementation can always
// elect to ignore it.
PublishName compute.Computable[oci.AllocatedRepository]
}
func (p Plan) GetSourceLabel() string { return p.SourceLabel }
func (p Plan) GetSourcePackageRef() *schema.PackageRef {
return schema.MakePackageSingleRef(p.SourcePackage)
}
type Workspace interface {
ModuleName() string
Abs() string
VersionedFS(rel string, observeChanges bool) compute.Computable[wscontents.Versioned]
}
type BuildTarget interface {
SourcePackage() schema.PackageName
SourceLabel() string
TargetPlatform() *specs.Platform
// See Plan.PublishName.
PublishName() compute.Computable[oci.AllocatedRepository]
}
type Configuration interface {
BuildTarget
// If the builder has the ability to produce with buildkit, that's
// preferred. A reason to do this is for instance when we want to merge
// multiple images together, and want to defer the merge to buildkit.
PrefersBuildkit() bool
Workspace() Workspace
}
type BuildPlatformsVar struct{}
func (BuildPlatformsVar) String() string {
var p []string
for _, plat := range platformOverride {
p = append(p, platform.FormatPlatform(plat))
}
return strings.Join(p, ",")
}
func (BuildPlatformsVar) Set(s string) error {
platformParts := strings.Split(s, ",")
var ps []specs.Platform
for _, p := range platformParts {
parsed, err := platform.ParsePlatform(p)
if err != nil {
return err
}
ps = append(ps, parsed)
}
platformOverride = ps
return nil
}
func (BuildPlatformsVar) Type() string {
return ""
}
func PlatformsOrOverrides(platforms []specs.Platform) []specs.Platform {
if len(platformOverride) > 0 {
return platformOverride
}
return platforms
}