get.porter.sh/porter@v1.3.0/pkg/templates/templates.go (about) 1 package templates 2 3 import ( 4 "embed" 5 "fmt" 6 7 "get.porter.sh/porter/pkg/config" 8 "get.porter.sh/porter/pkg/experimental" 9 ) 10 11 //go:embed templates/* 12 var fs embed.FS 13 14 // Workaround until go:embed can include hidden files 15 // https://github.com/golang/go/issues/43854 16 // 17 //go:embed templates/create/.dockerignore 18 var dockerignore []byte 19 20 //go:embed templates/create/.gitignore 21 var gitignore []byte 22 23 type Templates struct { 24 *config.Config 25 fs embed.FS 26 } 27 28 func NewTemplates(c *config.Config) *Templates { 29 return &Templates{ 30 Config: c, 31 fs: fs, 32 } 33 } 34 35 // GetManifest returns a porter.yaml template file for use in new bundles. 36 func (t *Templates) GetManifest() ([]byte, error) { 37 return t.fs.ReadFile("templates/create/porter.yaml") 38 } 39 40 // GetHelpers returns a helpers.sh template file for use in new bundles. 41 func (t *Templates) GetManifestHelpers() ([]byte, error) { 42 return t.fs.ReadFile("templates/create/helpers.sh") 43 } 44 45 // GetReadme returns a README.md file for use in new bundles. 46 func (t *Templates) GetReadme() ([]byte, error) { 47 return t.fs.ReadFile("templates/create/README.md") 48 } 49 50 // GetGitignore returns a .gitignore file for use in new bundles. 51 func (t *Templates) GetGitignore() ([]byte, error) { 52 return gitignore, nil 53 } 54 55 // GetDockerignore returns a .dockerignore file for use in new bundles. 56 func (t *Templates) GetDockerignore() ([]byte, error) { 57 return dockerignore, nil 58 } 59 60 // GetDockerfileTemplate returns a template.Dockerfile file for use in new bundles. 61 func (t *Templates) GetDockerfileTemplate() ([]byte, error) { 62 tmpl := fmt.Sprintf("templates/create/template.%s.Dockerfile", t.GetBuildDriver()) 63 return t.fs.ReadFile(tmpl) 64 } 65 66 // GetRunScript returns a run script template for bundle images. 67 func (t *Templates) GetRunScript() ([]byte, error) { 68 return t.fs.ReadFile("templates/build/cnab/app/run") 69 } 70 71 // GetSchema returns the template manifest schema for the porter manifest. 72 // Note that it is incomplete and does not include the mixins' schemas. 73 func (t *Templates) GetSchema() ([]byte, error) { 74 if t.Config.IsFeatureEnabled(experimental.FlagDependenciesV2) { 75 return t.fs.ReadFile("templates/v1.1.0.schema.json") 76 } 77 return t.fs.ReadFile("templates/schema.json") 78 } 79 80 // GetDockerfile returns the default Dockerfile for bundle images. 81 func (t *Templates) GetDockerfile() ([]byte, error) { 82 tmpl := fmt.Sprintf("templates/build/%s.Dockerfile", t.GetBuildDriver()) 83 return t.fs.ReadFile(tmpl) 84 } 85 86 // GetCredentialSetJSON returns a credential-set.schema.json template file to define new credential set. 87 func (t *Templates) GetCredentialSetJSON() ([]byte, error) { 88 return t.fs.ReadFile("templates/credentials/create/credential-set.json") 89 } 90 91 // GetCredentialSetYAML returns a credential-set.yaml template file to define new credential set. 92 func (t *Templates) GetCredentialSetYAML() ([]byte, error) { 93 return t.fs.ReadFile("templates/credentials/create/credential-set.yaml") 94 } 95 96 // GetParameterSetJSON returns a parameter-set.schema.json template file to define new parameter set. 97 func (t *Templates) GetParameterSetJSON() ([]byte, error) { 98 return t.fs.ReadFile("templates/parameters/create/parameter-set.json") 99 } 100 101 // GetParameterSetYAML returns a parameter-set.yaml template file to define new parameter set. 102 func (t *Templates) GetParameterSetYAML() ([]byte, error) { 103 return t.fs.ReadFile("templates/parameters/create/parameter-set.yaml") 104 }