-
Notifications
You must be signed in to change notification settings - Fork 202
/
templates.go
104 lines (84 loc) · 3.3 KB
/
templates.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
package templates
import (
"embed"
"fmt"
"get.porter.sh/porter/pkg/config"
"get.porter.sh/porter/pkg/experimental"
)
//go:embed templates/*
var fs embed.FS
// Workaround until go:embed can include hidden files
// https://github.com/golang/go/issues/43854
//
//go:embed templates/create/.dockerignore
var dockerignore []byte
//go:embed templates/create/.gitignore
var gitignore []byte
type Templates struct {
*config.Config
fs embed.FS
}
func NewTemplates(c *config.Config) *Templates {
return &Templates{
Config: c,
fs: fs,
}
}
// GetManifest returns a porter.yaml template file for use in new bundles.
func (t *Templates) GetManifest() ([]byte, error) {
return t.fs.ReadFile("templates/create/porter.yaml")
}
// GetHelpers returns a helpers.sh template file for use in new bundles.
func (t *Templates) GetManifestHelpers() ([]byte, error) {
return t.fs.ReadFile("templates/create/helpers.sh")
}
// GetReadme returns a README.md file for use in new bundles.
func (t *Templates) GetReadme() ([]byte, error) {
return t.fs.ReadFile("templates/create/README.md")
}
// GetGitignore returns a .gitignore file for use in new bundles.
func (t *Templates) GetGitignore() ([]byte, error) {
return gitignore, nil
}
// GetDockerignore returns a .dockerignore file for use in new bundles.
func (t *Templates) GetDockerignore() ([]byte, error) {
return dockerignore, nil
}
// GetDockerfileTemplate returns a template.Dockerfile file for use in new bundles.
func (t *Templates) GetDockerfileTemplate() ([]byte, error) {
tmpl := fmt.Sprintf("templates/create/template.%s.Dockerfile", t.GetBuildDriver())
return t.fs.ReadFile(tmpl)
}
// GetRunScript returns a run script template for invocation images.
func (t *Templates) GetRunScript() ([]byte, error) {
return t.fs.ReadFile("templates/build/cnab/app/run")
}
// GetSchema returns the template manifest schema for the porter manifest.
// Note that it is incomplete and does not include the mixins' schemas.
func (t *Templates) GetSchema() ([]byte, error) {
if t.Config.IsFeatureEnabled(experimental.FlagDependenciesV2) {
return t.fs.ReadFile("templates/v1.1.0.schema.json")
}
return t.fs.ReadFile("templates/schema.json")
}
// GetDockerfile returns the default Dockerfile for invocation images.
func (t *Templates) GetDockerfile() ([]byte, error) {
tmpl := fmt.Sprintf("templates/build/%s.Dockerfile", t.GetBuildDriver())
return t.fs.ReadFile(tmpl)
}
// GetCredentialSetJSON returns a credential-set.schema.json template file to define new credential set.
func (t *Templates) GetCredentialSetJSON() ([]byte, error) {
return t.fs.ReadFile("templates/credentials/create/credential-set.json")
}
// GetCredentialSetYAML returns a credential-set.yaml template file to define new credential set.
func (t *Templates) GetCredentialSetYAML() ([]byte, error) {
return t.fs.ReadFile("templates/credentials/create/credential-set.yaml")
}
// GetParameterSetJSON returns a parameter-set.schema.json template file to define new parameter set.
func (t *Templates) GetParameterSetJSON() ([]byte, error) {
return t.fs.ReadFile("templates/parameters/create/parameter-set.json")
}
// GetParameterSetYAML returns a parameter-set.yaml template file to define new parameter set.
func (t *Templates) GetParameterSetYAML() ([]byte, error) {
return t.fs.ReadFile("templates/parameters/create/parameter-set.yaml")
}