-
Notifications
You must be signed in to change notification settings - Fork 9
/
prebuilt.go
72 lines (57 loc) · 2.07 KB
/
prebuilt.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
// 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"
"namespacelabs.dev/foundation/internal/artifacts/oci"
"namespacelabs.dev/foundation/internal/compute"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/pkggraph"
"namespacelabs.dev/foundation/std/tasks"
)
func PrebuiltResolveOpts() oci.RegistryAccess {
// We assume all prebuilts are public, unless noted otherwise.
return oci.RegistryAccess{
PublicImage: true,
}
}
func PrebuiltPlan(imgid oci.ImageID, platformIndependent bool, opts oci.RegistryAccess) Spec {
return prebuilt{imgid, platformIndependent, opts}
}
func IsPrebuilt(spec Spec) (oci.ImageID, bool) {
if x, ok := spec.(prebuilt); ok {
return x.imgid, true
}
return oci.ImageID{}, false
}
type prebuilt struct {
imgid oci.ImageID
platformIndependent bool
opts oci.RegistryAccess
}
func (p prebuilt) BuildImage(ctx context.Context, _ pkggraph.SealedContext, conf Configuration) (compute.Computable[oci.Image], error) {
return oci.ImageP(p.imgid.ImageRef(), conf.TargetPlatform(), p.opts), nil
}
func (p prebuilt) PlatformIndependent() bool { return p.platformIndependent }
func Prebuilt(imgid oci.ImageID) compute.Computable[oci.ImageID] {
return &prebuiltImage{imgid: imgid}
}
type prebuiltImage struct {
imgid oci.ImageID
compute.PrecomputeScoped[oci.ImageID]
}
var _ compute.Digestible = prebuiltImage{}
func (p prebuiltImage) Action() *tasks.ActionEvent {
return tasks.Action("build.plan.prebuilt").Arg("ref", p.imgid)
}
func (p prebuiltImage) Inputs() *compute.In { return compute.Inputs().Stringer("ref", p.imgid) }
func (p prebuiltImage) Output() compute.Output {
return compute.Output{NotCacheable: true}
}
func (p prebuiltImage) Compute(context.Context, compute.Resolved) (oci.ImageID, error) {
return p.imgid, nil
}
func (p prebuiltImage) ComputeDigest(context.Context) (schema.Digest, error) {
return schema.DigestOf(p.imgid)
}