forked from openfaas/faas-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fetch templates from web when not in local folder.
Update get.sh to new 0.4 release.
- Loading branch information
Showing
5 changed files
with
142 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ build/ | |
faas-cli | ||
faas-cli-darwin | ||
faas-cli-armhf | ||
master.zip | ||
|
||
*.jpg | ||
*.pyc |
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,9 @@ | ||
#!/bin/sh | ||
|
||
docker build -f Dockerfile.redist --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy -t faas-cli . && \ | ||
docker create --name faas-cli faas-cli && \ | ||
docker cp faas-cli:/root/faas-cli . && \ | ||
docker cp faas-cli:/root/faas-cli-darwin . && \ | ||
docker cp faas-cli:/root/faas-cli-armhf . && \ | ||
docker rm -f faas-cli | ||
|
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,110 @@ | ||
package main | ||
|
||
import ( | ||
"archive/zip" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func fetchTemplates() error { | ||
|
||
err := fetchMasterZip() | ||
|
||
zipFile, err := zip.OpenReader("./master.zip") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("Attempting to expand templates from master.zip\n") | ||
|
||
for _, z := range zipFile.File { | ||
relativePath := strings.Replace(z.Name, "faas-cli-master/", "", -1) | ||
if strings.Index(relativePath, "template") == 0 { | ||
fmt.Printf("Found %s.\n", relativePath) | ||
rc, err := z.Open() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = createPath(relativePath, z.Mode()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// If relativePath is just a directory, then skip expanding it. | ||
if len(relativePath) > 1 && relativePath[len(relativePath)-1:] != string(os.PathSeparator) { | ||
err = writeFile(rc, z.UncompressedSize64, relativePath, z.Mode()) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
} | ||
|
||
return err | ||
} | ||
|
||
func fetchMasterZip() error { | ||
var err error | ||
if _, err = os.Stat("master.zip"); err != nil { | ||
templateURL := os.Getenv("templateUrl") | ||
if len(templateURL) == 0 { | ||
templateURL = "https://github.com/alexellis/faas-cli/archive/master.zip" | ||
} | ||
c := http.Client{} | ||
|
||
req, err := http.NewRequest("GET", templateURL, nil) | ||
if err != nil { | ||
log.Println(err.Error()) | ||
return err | ||
} | ||
log.Printf("HTTP GET %s\n", templateURL) | ||
res, err := c.Do(req) | ||
if err != nil { | ||
log.Println(err.Error()) | ||
return err | ||
} | ||
if res.Body != nil { | ||
defer res.Body.Close() | ||
} | ||
bytesOut, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
log.Println(err.Error()) | ||
return err | ||
} | ||
|
||
log.Printf("Writing %dKb to master.zip\n", len(bytesOut)/1024) | ||
err = ioutil.WriteFile("./master.zip", bytesOut, 0700) | ||
if err != nil { | ||
log.Println(err.Error()) | ||
} | ||
} | ||
return err | ||
} | ||
|
||
func writeFile(rc io.ReadCloser, size uint64, relativePath string, perms os.FileMode) error { | ||
var err error | ||
|
||
defer rc.Close() | ||
fmt.Printf("Writing %d bytes to %s.\n", size, relativePath) | ||
f, err := os.OpenFile(relativePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perms) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
_, err = io.CopyN(f, rc, int64(size)) | ||
|
||
return err | ||
} | ||
|
||
func createPath(relativePath string, perms os.FileMode) error { | ||
dir := filepath.Dir(relativePath) | ||
err := os.MkdirAll(dir, perms) | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
version=0.3 | ||
#!/bin/sh | ||
|
||
# Deployed to cli.get-faas.com | ||
|
||
version=0.4 | ||
|
||
hasCli() { | ||
has=$(which faas-cli) | ||
|