-
Notifications
You must be signed in to change notification settings - Fork 9
/
configuration.go
92 lines (74 loc) · 2.94 KB
/
configuration.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
// 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 (
"fmt"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"namespacelabs.dev/foundation/internal/artifacts/oci"
"namespacelabs.dev/foundation/internal/compute"
"namespacelabs.dev/foundation/schema"
)
type buildTarget struct {
target *specs.Platform
name compute.Computable[oci.AllocatedRepository]
}
type buildConfiguration struct {
buildTarget *buildTarget
source schema.PackageName
label string
workspace Workspace
prefersBuildkit bool
}
func NewBuildTarget(target *specs.Platform) *buildTarget {
return &buildTarget{target: target}
}
func (c *buildTarget) WithTargetName(name compute.Computable[oci.AllocatedRepository]) *buildTarget {
c.name = name
return c
}
func (c *buildTarget) WithSourcePackage(pkg schema.PackageName) *buildConfiguration {
d := buildConfiguration{buildTarget: c}
return d.WithSourcePackage(pkg)
}
func (c *buildTarget) WithSourceLabel(format string, args ...any) *buildConfiguration {
d := buildConfiguration{buildTarget: c}
return d.WithSourceLabel(format, args...)
}
func (c *buildTarget) WithWorkspace(w Workspace) *buildConfiguration {
d := buildConfiguration{buildTarget: c}
return d.WithWorkspace(w)
}
func (d *buildConfiguration) WithPrefersBuildkit(prefers bool) *buildConfiguration {
d.prefersBuildkit = prefers
return d
}
func (d *buildConfiguration) WithWorkspace(w Workspace) *buildConfiguration {
d.workspace = w
return d
}
func (d *buildConfiguration) WithSourcePackage(pkg schema.PackageName) *buildConfiguration {
d.source = pkg
return d
}
func (d *buildConfiguration) WithSourceLabel(format string, args ...any) *buildConfiguration {
d.label = fmt.Sprintf(format, args...)
return d
}
func CopyConfiguration(b Configuration) *buildConfiguration {
t := NewBuildTarget(b.TargetPlatform())
if x := b.PublishName(); x != nil {
t = t.WithTargetName(x)
}
return t.WithSourcePackage(b.SourcePackage()).WithSourceLabel(b.SourceLabel()).WithPrefersBuildkit(b.PrefersBuildkit()).WithWorkspace(b.Workspace())
}
func (c *buildTarget) TargetPlatform() *specs.Platform { return c.target }
func (c *buildTarget) PublishName() compute.Computable[oci.AllocatedRepository] { return c.name }
func (d *buildConfiguration) TargetPlatform() *specs.Platform { return d.buildTarget.target }
func (d *buildConfiguration) PublishName() compute.Computable[oci.AllocatedRepository] {
return d.buildTarget.name
}
func (d *buildConfiguration) SourcePackage() schema.PackageName { return d.source }
func (d *buildConfiguration) SourceLabel() string { return d.label }
func (d *buildConfiguration) PrefersBuildkit() bool { return d.prefersBuildkit }
func (d *buildConfiguration) Workspace() Workspace { return d.workspace }