forked from knative/func
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.go
65 lines (55 loc) · 1.52 KB
/
template.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
package function
import (
"context"
"path"
)
// template
type template struct {
name string
runtime string
repository string
fs Filesystem
config templateConfig
}
func (t template) Name() string {
return t.name
}
func (t template) Runtime() string {
return t.runtime
}
func (t template) Repository() string {
return t.repository
}
func (t template) Fullname() string {
return t.repository + "/" + t.name
}
func (t template) Write(ctx context.Context, f *Function) error {
// Apply fields from the template onto the function itself (Denormalize).
// The template is already the denormalized view of repo->runtime->template
// so it's values are treated as defaults.
// TODO: this begs the question: should the Template's manifest.yaml actually
// be a partially-populated func.yaml?
if len(f.BuilderImages) == 0 {
f.BuilderImages = t.config.BuilderImages
}
if len(f.Buildpacks) == 0 {
f.Buildpacks = t.config.Buildpacks
}
if len(f.BuildEnvs) == 0 {
f.BuildEnvs = t.config.BuildEnvs
}
if f.HealthEndpoints.Liveness == "" {
f.HealthEndpoints.Liveness = t.config.HealthEndpoints.Liveness
}
if f.HealthEndpoints.Readiness == "" {
f.HealthEndpoints.Readiness = t.config.HealthEndpoints.Readiness
}
if f.Invocation.Format == "" {
f.Invocation.Format = t.config.Invocation.Format
}
isManifest := func(p string) bool {
_, f := path.Split(p)
return f == templateManifest
}
return copyFromFS(".", f.Root, maskingFS{fs: t.fs, masked: isManifest}) // copy everything but manifest.yaml
}