forked from knative/func
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.go
65 lines (55 loc) · 1.57 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.Build.BuilderImages) == 0 {
f.Build.BuilderImages = t.config.BuilderImages
}
if len(f.Build.Buildpacks) == 0 {
f.Build.Buildpacks = t.config.Buildpacks
}
if len(f.Build.BuildEnvs) == 0 {
f.Build.BuildEnvs = t.config.BuildEnvs
}
if f.Deploy.HealthEndpoints.Liveness == "" {
f.Deploy.HealthEndpoints.Liveness = t.config.HealthEndpoints.Liveness
}
if f.Deploy.HealthEndpoints.Readiness == "" {
f.Deploy.HealthEndpoints.Readiness = t.config.HealthEndpoints.Readiness
}
if f.Invoke == "" && t.config.Invoke != "http" {
f.Invoke = t.config.Invoke
}
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
}