-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create faas-cli add-template --url <URL>
command
#87
Conversation
Looking forward to looking at this. One quick note. It would be
"add-template" for the command and add_template for filenames.
…On 8 Sep 2017 16:50, "Erich Stoekl" ***@***.***> wrote:
1. Create faas-cli addTemplate --URL <URL> command
2. Add template.yml files for each language in the template/ dir.
3. Read fProcess from template in deploy command, if language of
function is not Dockerfile
4. Adds mock-server test for addTemplate.go
Description
Adds the addTemplate command and a basic test for it. Changes the way
that fProcess command is acquired: from a hard-coded value in
proxy/deploy.go to a new YAML file in each language-specific dir in the
template/ dir, for example template/csharp/template.yml.
Motivation and Context
- I have raised an issue to propose this change (required
<https://github.com/alexellis/faas/blob/master/CONTRIBUTING.md>)
#85 <#85>
How Has This Been Tested?
Tests added in addTemplate_test.go
Types of changes
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to change)
Checklist:
- My code follows the code style of this project.
- My change requires a change to the documentation.
- I have updated the documentation accordingly.
- I've read the CONTRIBUTION
<https://github.com/alexellis/faas/blob/master/CONTRIBUTING.md> guide
- I have signed-off my commits with git commit -s
- I have added tests to cover my changes.
- All new and existing tests passed.
------------------------------
You can view, comment on, or merge this pull request online at:
#87
Commit Summary
- 1. Create `faas-cli addTemplate --URL <URL>` command
File Changes
- *A* commands/addTemplate.go
<https://github.com/alexellis/faas-cli/pull/87/files#diff-0> (52)
- *A* commands/addTemplate_test.go
<https://github.com/alexellis/faas-cli/pull/87/files#diff-1> (54)
- *M* commands/deploy.go
<https://github.com/alexellis/faas-cli/pull/87/files#diff-2> (23)
- *M* commands/list.go
<https://github.com/alexellis/faas-cli/pull/87/files#diff-3> (1)
- *M* proxy/deploy.go
<https://github.com/alexellis/faas-cli/pull/87/files#diff-4> (10)
- *A* stack/language_template.go
<https://github.com/alexellis/faas-cli/pull/87/files#diff-5> (31)
- *M* stack/schema.go
<https://github.com/alexellis/faas-cli/pull/87/files#diff-6> (5)
- *A* template/csharp/template.yml
<https://github.com/alexellis/faas-cli/pull/87/files#diff-7> (2)
- *A* template/node-armhf/template.yml
<https://github.com/alexellis/faas-cli/pull/87/files#diff-8> (2)
- *A* template/node/template.yml
<https://github.com/alexellis/faas-cli/pull/87/files#diff-9> (2)
- *A* template/python-armhf/template.yml
<https://github.com/alexellis/faas-cli/pull/87/files#diff-10> (2)
- *A* template/python/template.yml
<https://github.com/alexellis/faas-cli/pull/87/files#diff-11> (2)
- *A* template/ruby/template.yml
<https://github.com/alexellis/faas-cli/pull/87/files#diff-12> (2)
Patch Links:
- https://github.com/alexellis/faas-cli/pull/87.patch
- https://github.com/alexellis/faas-cli/pull/87.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#87>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGEGzze92XaFzkhEpFD-cqV8HsNlkHotks5sgWJIgaJpZM4PRXcH>
.
|
eb76a4f
to
9543c0e
Compare
Updated file names, improved help for |
9543c0e
to
5bc737c
Compare
For reference let's update the description of this PR with the naming "add-template". |
faas-cli addTemplate --URL <URL>
commandfaas-cli add-template --url <URL>
command
commands/add_template.go
Outdated
URL = strings.TrimRight(URL, "/") | ||
URL = URL + "/archive/master.zip" | ||
|
||
err := os.Setenv("templateUrl", URL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to avoid passing the URL via environmental variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I can change fetchTemplates()
in fetch_temlates.go
to accept a param of the custom URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updated version no longer uses env var.
Question about this PR: should I add some logic to scan through the repository that is passed in to search for the template dir? Or should we look for third party templates in the root path of a repo? Currently |
Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off. |
c91e809
to
8ff3fdc
Compare
8ff3fdc
to
cd9bb4c
Compare
@ericstoekl what's remaining to get this in? |
@alexellis It's ready to be merge ;-) |
@alexellis , I agree with Minh-Quan, it looks ready for merging. |
|
a5bac0e
to
cd9bb4c
Compare
Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off. |
12b7ddb
to
a6ebcc9
Compare
@alexellis Conflicts are resolved 👍 |
a6ebcc9
to
163eec4
Compare
1f9c06d
to
37c4fef
Compare
commands/fetch_templates.go
Outdated
|
||
templateURLSplit := strings.Split(templateURL, "/") | ||
templateURLSplit = templateURLSplit[len(templateURLSplit)-4 : len(templateURLSplit)-2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the magic numbers -4 -2
What's this doing? maybe break out a function and document the indexes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just to name the master.zip
file as the name of the repository. It's not necessary so I'm removing it.
commands/fetch_templates.go
Outdated
@@ -137,3 +184,34 @@ func createPath(relativePath string, perms os.FileMode) error { | |||
err := os.MkdirAll(dir, perms) | |||
return err | |||
} | |||
|
|||
// canWriteLanguage tells whether the language can be processed or not | |||
// if overwrite is activated, the directory template/language/ is removed before to keep it in sync |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rgee0 @johnmccabe I don't know if overwrite should delete anything. It should probably dump over the top. Not sure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete is a strong action. I do think it important that the user knows exactly what the current state of their templates is and that they aren't able to 'accidentally' overwrite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated it to no longer delete before --overwrite
.
commands/fetch_templates.go
Outdated
// if overwrite is activated, the directory template/language/ is removed before to keep it in sync | ||
func canWriteLanguage(language string, overwrite bool) bool { | ||
|
||
if len(language) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm struggling to read/decipher this function - think it can be made simpler?
commands/invoke.go
Outdated
@@ -51,7 +51,7 @@ func runInvoke(cmd *cobra.Command, args []string) { | |||
functionName = args[0] | |||
|
|||
if len(yamlFile) > 0 { | |||
parsedServices, err := stack.ParseYAMLFile(yamlFile, regex, filter) | |||
parsedServices, err := stack.ParseYAMLFileForStack(yamlFile, regex, filter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ParseYAMLFileForStack vs ParseYAMLFile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this one back.
commands/new_function.go
Outdated
@@ -45,14 +45,20 @@ language or type in --list for a list of languages available.`, | |||
|
|||
func runNewFunction(cmd *cobra.Command, args []string) { | |||
if list == true { | |||
var available_templates string | |||
|
|||
if f, err := ioutil.ReadDir(templateDirectory); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we change f
to something else please?
commands/new_function.go
Outdated
var available_templates string | ||
|
||
if f, err := ioutil.ReadDir(templateDirectory); err != nil { | ||
available_templates = "There is no available languages" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"No language templates were found. Please run 'faas-cli template pull'."
commands/new_function.go
Outdated
} else { | ||
for _, file := range f { | ||
if file.IsDir() { | ||
available_templates += fmt.Sprintf("- %s\n", file.Name()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build up an array in a separate function then return this - and have the formatting/printing separate.
commands/new_function_test.go
Outdated
|
||
if err := os.Chdir("../.."); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I like this because it's cryptic. Please can you explain what's happening?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to execute these tests in faas-cli/commands/testdir/new_function
directory, so we need to cd
into it for the test to run, then cd back to the home directory afterwards (because we don't know what order the tests will execute in).
I've changed this to save the full directory path at the beginning of the function, then cd
back into it instead of using the relative ../..
.
proxy/deploy.go
Outdated
} else if language == "python3" { | ||
fprocessTemplate = "python3 index.py" | ||
} else { | ||
fmt.Printf("Command to be invoked for function %s not found.\n", functionName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would this error fire off? There is no hard need to provide an fprocess at the deployment time. Some Dockerfiles will bake this in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverting this
stack/common.go
Outdated
) | ||
|
||
func ParseYAML( | ||
file string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't read very well split over so many lines. How does it look on one line?
If there is a function being passed in - perhaps extract it to an interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by extract to an interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually removing this entire file for now
stack/common.go
Outdated
file string, | ||
parseFunc func([]byte, ...string) (interface{}, error), | ||
parseFuncArgs ...string, | ||
) (interface{}, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this return interface{}?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the interface may not be necessary for what we're doing here, I might refactor it to something more simple
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was for mutualise this function for parsing Stack & Language
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will add this back in the next re-factoring PR
stack/language_template.go
Outdated
|
||
// iParseYAMLDataForLanguageTemplate parses YAML data into language template | ||
// Use the alias ParseYAMLDataForLanguageTemplate | ||
func iParseYAMLDataForLanguageTemplate(fileData []byte, args ...string) (interface{}, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the "i"-prefix convention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it returns an interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I'm going to try doing this without the interface approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually "i" was for "internal", I wanted not to expose it and use the public method to do the assertion on return type.
That's why ParseYAMLDataForLanguageTemplate calls iParseYAMLDataForLanguageTemplate.
This re-factoring is because I wanted to extract ParseYAMLFile to ParseYAML, since the part of parsing can be re-used for both LanguageTemplate & Stack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking we will add this re-factoring in a future PR, after this one is merged. The plan for this PR is to add minimal functionality.
stack/stack.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
return object.(*Services), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why we need to use untyped interfaces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eric I think this will be a good addition to the CLI - it's been requested a number of times.
This PR touches a lot of files (at least 35) and involves both refactoring and new features. I have added some notes and questions.
i would like us to resolve as much as possible before merging.
@ericstoekl I add a verif when downloading an invalid url, the zip is removed if it's not valid. |
37c4fef
to
4b13408
Compare
Squashed the commits into 2 separate ones - First commit is everything before Alex's comments on 10/25, second commit is the changes to address those comments. After the latest commit, the functionality is all the same, but the code has been changed in many places for simplification. |
4b13408
to
15b9aa7
Compare
1. add-template updates 2. overwrite functionality 3. cacheLanguages for faster parsing, cache directory for zip file 4. tests for add-template, with overwrite option 5. test for PullTemplates function 1) Enable github repo ending in '/' 2) Allow 'faas-cli add-template' (no need to specify repo), picks default repo 3) More concise (shorter) summary of language templates applied/not applied 4) Change validTemplate to public facing IsValidTemplate function in stack package 5) Refactor BuildImage() function to use IsValidTemplate to check if language is valid (rather than hard-coded values) 6) Remove --lang option from invoke command (it is not used) Signed-off-by: Eric Stoekl <ems5311@gmail.com> Signed-off-by: Minh-Quan TRAN <account@itscaro.me>
2) Update guide with new links 3) Change to simplified version of ParseYAMLFile/ParseYAMLFileForLanguageTemplate 4) simplify canWriteLanguage map, remove global variable usage 5) Don't print error message if no fprocess supplied (proxy/deploy.go) 6) Use absolute filepath for switching back to home directory after each new_function_test 7) Don't remove files before --overwrite Signed-off-by: Eric Stoekl <ems5311@gmail.com> Signed-off-by: Minh-Quan TRAN <account@itscaro.me>
15b9aa7
to
43b9a12
Compare
Ran the tests on my machine and they all passed. Tried the command without parameters and found it pulls the templates from this repo's templates. Something I didn't expect, but it didn't overwrite changes to the existing templates, so I don't see a problem with that. Nice work! |
Work in this PR is continued here: #201 |
faas-cli add-template --url <URL>
commandDescription
Adds the
addTemplate
command and a basic test for it. Changes the way thatfProcess
command is acquired: from a hard-coded value inproxy/deploy.go
to a new YAML file in each language-specific dir in thetemplate/
dir, for exampletemplate/csharp/template.yml
.Motivation and Context
Proposal: third-party templates via GitHub #85
How Has This Been Tested?
Tests added in
addTemplate_test.go
Types of changes
Checklist:
git commit -s