convert Dockerfile to dockerfile internally
Signed-off-by: Minh-Quan TRAN <account@itscaro.me> convert Dockerfile to dockerfile internally - testing files Signed-off-by: Minh-Quan TRAN <account@itscaro.me>
This commit is contained in:
committed by
Alex Ellis
parent
ca25c72ebf
commit
ff7a14ccda
@@ -81,7 +81,10 @@ func createBuildTemplate(functionName string, handler string, language string) s
|
||||
fmt.Printf("Error creating path %s - %s.\n", functionPath, mkdirErr.Error())
|
||||
}
|
||||
|
||||
// Drop in directory tree from template
|
||||
// Both Dockerfile and dockerfile are accepted
|
||||
if language == "Dockerfile" {
|
||||
language = "dockerfile"
|
||||
}
|
||||
CopyFiles("./template/"+language, tempPath)
|
||||
|
||||
// Overlay in user-function
|
||||
|
||||
@@ -65,7 +65,17 @@ via flags.`,
|
||||
faas-cli build -f ./stack.yml --regex "fn[0-9]_.*"
|
||||
faas-cli build --image=my_image --lang=python --handler=/path/to/fn/
|
||||
--name=my_fn --squash`,
|
||||
RunE: runBuild,
|
||||
PreRunE: preRunBuild,
|
||||
RunE: runBuild,
|
||||
}
|
||||
|
||||
// preRunBuild validates args & flags
|
||||
func preRunBuild(cmd *cobra.Command, args []string) error {
|
||||
if language == "Dockerfile" {
|
||||
language = "dockerfile"
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func runBuild(cmd *cobra.Command, args []string) error {
|
||||
|
||||
@@ -89,7 +89,17 @@ via flags. Note: --replace and --update are mutually exclusive.`,
|
||||
faas-cli deploy --image=my_image --name=my_fn --handler=/path/to/fn/
|
||||
--gateway=http://remote-site.com:8080 --lang=python
|
||||
--env=MYVAR=myval`,
|
||||
RunE: runDeploy,
|
||||
PreRunE: preRunDeploy,
|
||||
RunE: runDeploy,
|
||||
}
|
||||
|
||||
// preRunDeploy validates args & flags
|
||||
func preRunDeploy(cmd *cobra.Command, args []string) error {
|
||||
if language == "Dockerfile" {
|
||||
language = "dockerfile"
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func runDeploy(cmd *cobra.Command, args []string) error {
|
||||
|
||||
@@ -18,12 +18,11 @@ import (
|
||||
|
||||
var (
|
||||
appendFile string
|
||||
lang string
|
||||
list bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
newFunctionCmd.Flags().StringVar(&lang, "lang", "", "Language or template to use")
|
||||
newFunctionCmd.Flags().StringVar(&language, "lang", "", "Language or template to use")
|
||||
newFunctionCmd.Flags().StringVarP(&gateway, "gateway", "g", defaultGateway, "Gateway URL to store in YAML stack file")
|
||||
|
||||
newFunctionCmd.Flags().BoolVar(&list, "list", false, "List available languages")
|
||||
@@ -42,7 +41,17 @@ language or type in --list for a list of languages available.`,
|
||||
faas-cli new text-parser --lang python --gateway http://mydomain:8080
|
||||
faas-cli new text-reader --lang python --append stack.yml
|
||||
faas-cli new --list`,
|
||||
RunE: runNewFunction,
|
||||
PreRunE: preRunNewFunction,
|
||||
RunE: runNewFunction,
|
||||
}
|
||||
|
||||
// preRunNewFunction validates args & flags
|
||||
func preRunNewFunction(cmd *cobra.Command, args []string) error {
|
||||
if language == "Dockerfile" {
|
||||
language = "dockerfile"
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func runNewFunction(cmd *cobra.Command, args []string) error {
|
||||
@@ -72,14 +81,14 @@ func runNewFunction(cmd *cobra.Command, args []string) error {
|
||||
|
||||
functionName = args[0]
|
||||
|
||||
if len(lang) == 0 {
|
||||
if len(language) == 0 {
|
||||
return fmt.Errorf("you must supply a function language with the --lang flag")
|
||||
}
|
||||
|
||||
PullTemplates(DefaultTemplateRepository)
|
||||
|
||||
if stack.IsValidTemplate(lang) == false {
|
||||
return fmt.Errorf("%s is unavailable or not supported", lang)
|
||||
if stack.IsValidTemplate(language) == false {
|
||||
return fmt.Errorf("%s is unavailable or not supported", language)
|
||||
}
|
||||
|
||||
appendMode := len(appendFile) > 0
|
||||
@@ -107,10 +116,7 @@ func runNewFunction(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("got unexpected error while updating .gitignore file: %s", err)
|
||||
}
|
||||
|
||||
if lang == "Dockerfile" {
|
||||
lang = "dockerfile"
|
||||
}
|
||||
builder.CopyFiles(filepath.Join("template", lang, "function"), functionName)
|
||||
builder.CopyFiles(filepath.Join("template", language, "function"), functionName)
|
||||
|
||||
var stackYaml string
|
||||
|
||||
@@ -126,7 +132,7 @@ functions:
|
||||
|
||||
stackYaml +=
|
||||
` ` + functionName + `:
|
||||
lang: ` + lang + `
|
||||
lang: ` + language + `
|
||||
handler: ./` + functionName + `
|
||||
image: ` + functionName + `
|
||||
`
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
@@ -51,12 +50,6 @@ func ParseYAMLDataForLanguageTemplate(fileData []byte) (*LanguageTemplate, error
|
||||
func IsValidTemplate(lang string) bool {
|
||||
var found bool
|
||||
|
||||
// TODO harmonise to lowercase when fetching template & parsing yaml
|
||||
// Ensure that `lang` is lowercase in case of Dockerfile
|
||||
if strings.ToLower(lang) == "dockerfile" {
|
||||
lang = strings.ToLower(lang)
|
||||
}
|
||||
|
||||
if _, err := os.Stat("./template/" + lang); err == nil {
|
||||
templateYAMLPath := "./template/" + lang + "/template.yml"
|
||||
|
||||
|
||||
@@ -50,6 +50,12 @@ func ParseYAMLData(fileData []byte, regex string, filter string) (*Services, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, f := range services.Functions {
|
||||
if f.Language == "Dockerfile" {
|
||||
f.Language = "dockerfile"
|
||||
}
|
||||
}
|
||||
|
||||
if services.Provider.Name != providerName {
|
||||
return nil, fmt.Errorf("'%s' is the only valid provider for this tool - found: %s", providerName, services.Provider.Name)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ functions:
|
||||
image: alexellis/faas-nodejs-echo
|
||||
|
||||
imagemagick:
|
||||
lang: Dockerfile
|
||||
lang: dockerfile
|
||||
handler: ./sample/imagemagick
|
||||
image: functions/resizer
|
||||
fprocess: "convert - -resize 50% fd:1"
|
||||
|
||||
Reference in New Issue
Block a user