-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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/<lang> in deploy command 4. Adds mock-server test for addTemplate.go 5. Remove fprocess variable hard-coding in proxy/deploy.go Signed-off-by: Eric Stoekl <ems5311@gmail.com>
- Loading branch information
1 parent
3a2e814
commit 9543c0e
Showing
14 changed files
with
179 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Alex Ellis 2017. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Flags that are to be added to commands | ||
|
||
var ( | ||
URL string | ||
) | ||
|
||
func init() { | ||
// Setup flags that are used only by this command (variables defined above) | ||
addTemplateCmd.Flags().StringVar(&URL, "url", "http://github.com/alexellis/faas-cli", "URL from which to pull git repo to grab 'template' dir from") | ||
|
||
faasCmd.AddCommand(addTemplateCmd) | ||
} | ||
|
||
// addTemplateCmd represents the addTemplate command | ||
var addTemplateCmd = &cobra.Command{ | ||
Use: "add-template [--url URL]", | ||
Short: "Downloads templates from the specified github repo", | ||
Long: `Downloads the compressed github repo specified by [URL], and extracts the 'template' | ||
directory from the root of the repo, if it exists.`, | ||
Example: "faas-cli add-template --url https://github.com/alexellis/faas-cli", | ||
Run: runAddTemplate, | ||
} | ||
|
||
func runAddTemplate(cmd *cobra.Command, args []string) { | ||
URL = strings.TrimRight(URL, "/") | ||
URL = URL + "/archive/master.zip" | ||
|
||
err := os.Setenv("templateUrl", URL) | ||
if err != nil { | ||
fmt.Printf("Error setting templateUrl env var: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = fetchTemplates() | ||
if err != nil { | ||
fmt.Printf("Error getting templates from URL: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) Alex Ellis, Eric Stoekl 2017. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
package commands | ||
|
||
import ( | ||
"testing" | ||
"net/http" | ||
"net/http/httptest" | ||
"io/ioutil" | ||
"os" | ||
|
||
) | ||
|
||
func Test_addTemplate(t *testing.T) { | ||
const sampleMasterZipPath string = "../test/master.zip" | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
|
||
if _, err := os.Stat(sampleMasterZipPath); os.IsNotExist(err) { | ||
t.Error(err) | ||
} | ||
|
||
fileData, err := ioutil.ReadFile(sampleMasterZipPath) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
w.Write(fileData) | ||
})) | ||
defer ts.Close() | ||
|
||
URL = ts.URL | ||
faasCmd.SetArgs([]string{"add-template"}) | ||
faasCmd.Execute() | ||
|
||
// Remove existing master.zip file if it exists | ||
if _, err := os.Stat("master.zip"); err == nil { | ||
t.Log("Found a master.zip file, removing it...") | ||
|
||
err := os.Remove("master.zip") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
// Remove existing templates folder, if it exist | ||
if _, err := os.Stat("template/"); err == nil { | ||
t.Log("Found a template/ directory, removing it...") | ||
|
||
err := os.RemoveAll("template/") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Alex Ellis 2017. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
package stack | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
// ParseYAML parse a YAML file into a LanguageTemplate struct. | ||
func ParseYAMLForLanguageTemplate(yamlFile string) (*LanguageTemplate, error) { | ||
var langTemplate LanguageTemplate | ||
var err error | ||
var fileData []byte | ||
|
||
fileData, err = ioutil.ReadFile(yamlFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = yaml.Unmarshal(fileData, &langTemplate) | ||
if err != nil { | ||
fmt.Printf("Error with YAML file\n") | ||
return nil, err | ||
} | ||
|
||
return &langTemplate, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
language: csharp | ||
fprocess: dotnet ./root.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
language: node | ||
fprocess: node index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
language: node | ||
fprocess: node index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
language: python | ||
fprocess: python index.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
language: python | ||
fprocess: python index.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
language: ruby | ||
fprocess: ruby index.rb |