openfaas / faas-cli Goto Github PK
View Code? Open in Web Editor NEWOfficial CLI for OpenFaaS
Home Page: https://www.openfaas.com/
License: Other
Official CLI for OpenFaaS
Home Page: https://www.openfaas.com/
License: Other
./faas-cli version
___ _____ ____
/ _ \ _ __ ___ _ __ | ___|_ _ __ _/ ___|
| | | | '_ \ / _ \ '_ \| |_ / _` |/ _` \___ \
| |_| | |_) | __/ | | | _| (_| | (_| |___) |
\___/| .__/ \___|_| |_|_| \__,_|\__,_|____/
|_|
Version: dev-86370e8
./faas-cli version --short-version
dev-86370e8
./faas-cli version
___ _____ ____
/ _ \ _ __ ___ _ __ | ___|_ _ __ _/ ___|
| | | | '_ \ / _ \ '_ \| |_ / _` |/ _` \___ \
| |_| | |_) | __/ | | | _| (_| | (_| |___) |
\___/| .__/ \___|_| |_|_| \__,_|\__,_|____/
|_|
Version: 0.4.14-alpha-8f2ae9c
./faas-cli version --short-version
Version: 0.4.14-alpha-8f2ae9c
Version contains only SHA1
Provide a more human-readable version info, easier for people to report their version
go 1.8.3 linux/amd64
docker 17.06.2-ce
Build should "just work"
Fails with:
C:\Users\alex\Desktop\faas\sample-functions\ipconfig>.\faas-cli.exe build -f stack.yml
2017/09/12 05:57:49 No templates found in current directory.
2017/09/12 05:57:49 HTTP GET https://github.com/alexellis/faas-cli/archive/master.zip
2017/09/12 05:57:51 Writing 200Kb to master.zip
2017/09/12 05:57:51 Attempting to expand templates from master.zip
Found template/.
Writing 0 bytes to template/.
2017/09/12 05:57:51 Unable to download templates from Github.
2017/09/12 05:57:51 Could not pull templates for OpenFaaS. open template/: is a directory
Note this has been around for a while, reproduced on current release and old 0.4.8
User experience on Windows is compromised
Docker version docker version
(e.g. Docker 17.0.05 ):
Docker 17.06.1-ce
Are you using Docker Swarm or Kubernetes (FaaS-netes)?
Swarm
Operating System and version (e.g. Linux, Windows, MacOS):
Windows 10
Update - I have found a much better way of doing this, now available at #66
I have created a mock HTTP mode for the faas-cli build command, that swaps out the real http client Do()
method for a fake version when it is called in fetch_templates.go
, for the purpose of downloading the master.zip
file. Please check out this change at my forked branch:
What this change does is creates an interface called HttpClient
, which the fetchMasterZip()
function will use to get the zip file from github. When the --mock-http
flag is passed in, then the ClientMock
type will be used for the HttpClient
, which implements a fake version of the Do()
method. When you run fetchMasterZip()
, it will then fetch the fake master.zip
file.
The builder.BuildImage()
call in commands/build.go
will be skipped when the --mock-http
flag is set.
This is just a PoC. A potentially better way to do this is to create a mock server with httptest
, then use a handler function for both real and fake http calls.
Thanks,
Erich
I'm trying to build a python example using the tutorial https://blog.alexellis.io/first-faas-python-function/ and the moment I call:
$ faas-cli -action build -f ./stack.yml
I get:
open ./template/python: no such file or directory error
is there anything that I miss?
$ faas-cli -action build -f ./stack.yml
...
Successfully tagged faas-hello-python:latest
Image: faas-hello-python built.
➜ functions cat stack.yml
provider:
name: faas
gateway: http://localhost:8080
functions:
hello-python:
lang: python
handler: ./hello-python
image: faas-hello-python
➜ functions cat hello-python/handler.py
def handle(req):
print("Hello! You said: " + req)
%
➜ functions faas-cli -action build -f ./stack.yml
Building: hello-python.
Clearing temporary build folder: ./build/hello-python/
Preparing ./hello-python/ ./build/hello-python/function
2017/09/14 08:57:26 open ./template/python: no such file or directory
I was trying to follow the tutorial steps from here:
https://blog.alexellis.io/first-faas-python-function/
docker version
(e.g. Docker 17.0.05 ):➜ functions docker version
Client:
Version: 17.06.2-ce
API version: 1.30
Go version: go1.8.3
Git commit: cec0b72
Built: Tue Sep 5 20:12:06 2017
OS/Arch: darwin/amd64
Server:
Version: 17.06.2-ce
API version: 1.30 (minimum version 1.12)
Go version: go1.8.3
Git commit: cec0b72
Built: Tue Sep 5 19:59:19 2017
OS/Arch: linux/amd64
Experimental: true
➜ functions uname -a
Darwin C02SG3FQFVH6 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
I have started to work on providing a PHP template and I'd like to ensure support for PHP 5 and 7 (This proposal is also relevant for Python 2/3)
I'd like to propose that we add an additional parameter, either version
or language_version
I considered having a template for each and avoiding additional changes, but as very little would be different across the templates, I think it's better to provide the additional parameter.
As the template library grows, the version
parameter would also allow keen developers to benchmark / test / dabble with newer, but potentially breaking, versions of their run-time.
It would be nice to be able to list the functions on the current gateway from the CLI. This would improve the functionality of the CLI, and make discoverability/updates easier.
I am thinking in a similar vein to how apex does things:
When re-deploying a function (aka Docker Swarm Service) we can get an error "Address in use - unable to allocate container" or similar.
I've raised the issue upstream but it's been open 30 days already. I don't believe the issue occurs when using Kubernetes as a back-end.
The Docker swarm work-around appears to be to deploy again after a few seconds or to use docker service rm
via the Docker CLI first.
I think this might also be fixed with a restart policy of > 1.
https://github.com/alexellis/faas/blob/master/gateway/handlers/functionshandler.go#L189
We need to start moving the FaaS projects to 1.8.x. The CLI has the least complex dependency-set so let's start here.
We're using 1.7.x for x86 and ARM.
Maybe the FaaS CLI should look at the uname
on a local machine to decide whether to use the armv7 or armv8 templates.
i.e.
templates/armv6/node
templates/armv8/python
The main part of a template that needs to change is the line that picks up the watchdog binary and the base Docker image.
Running through the demo commands in the README. Install seemed to go fine as did build the sample functions with faas-cli -action build -f ./samples.yml
When deploy though, it seems to hang.
faas-cli -action deploy -f ./samples.yml
...hangs with Deploying: url_ping.
This is on x86 architecture and Docker 17.06.0-ce.
Use a constant to declare the default gateway instead of having "http://localhost:8080" hard-coded in multiple places
It would be nice to be able to invoke functions on the current gateway from the CLI. This would improve the functionality of the CLI.
I am thinking in a similar vein to how apex does things:
When I try to call a function created with the C# template, I get the following result:
$ curl http://localhost:8080/function/csharp-hello-app -d "stuff"
exit status 145
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
This error code apparently indicates that the image that is built does not have the SDK installed. (https://stackoverflow.com/questions/42346498/dotnet-aspnetcore-docker-build-fails-with-a-145-error-code)
Are others seeing this issue? I'm deploying by adding the following to ./samples.yml
:
functions:
csharp-hello-app:
lang: csharp
handler: ./sample/csharp-hello
image: yourname/csharp-hello-app
Csharp app echos input.
Returns exit status 145
functions:
block of your yaml file: csharp-hello-app:
lang: csharp
handler: ./sample/csharp-hello
image: yourname/csharp-hello-app
faas-cli build -f <yourfile.yaml>
faas-cli deploy -f <yourfile.yaml>
curl http://localhost:8080/function/csharp-hello-app -d "stuff"
docker version
(e.g. Docker 17.0.05 ):If a stack has 10 functions but I only want to build one (by name) - then I should be able to do this:
$ faas-cli build -f stack.yml --filter "payroll"
Applies to:
I am working on the faas-and-furious/youtube-dl function. My workflow was:
faas-cli push -f <yaml>
entry.sh
filefaas-cli build -f <yaml>; faas-cli deploy -f <yaml>
, and the function is not updated!My current version of the code: https://github.com/faas-and-furious/youtube-dl
The only way I can get my image to reflect the new state of the youtube-dl
function is to name the image something different in the YAML file.
I tried build with --no-cache
and it doesn't work either.
Also, If I do faas-cli push -f <YAML>
, it will show Layer already exists
for every line.
The yaml file is:
provider:
name: faas
gateway: http://localhost:8080
functions:
youtube-dl:
lang: Dockerfile
handler: ./youtube-dl
image: ems5311/youtube-dl:latest
Docker version docker version
(e.g. Docker 17.0.05 ):
Are you using Docker Swarm or Kubernetes (FaaS-netes)?
Operating System and version (e.g. Linux, Windows, MacOS):
Link to your project or a code example to reproduce issue:
Expected Behaviour
Add template for PHP in order to support built-in build for PHP
Your Environment
Docker Version: 17.06.1-ce
Go version: go1.8.3
OS/Arch: linux/amd64
Similar to curl get-faas.com | sh
Currently to look at deployed OpenFaaS commands we have to use things like:
docker service ls
docker service ps <function_name>
docker service logs <function_name>
While this is fine if you understand the underlying technologies, it adds another barrier of entry for new users, and another difference in usability between backends.
Wrapping this functionality in a common way into the faas-cli
would simplify this, and make it more 'directly discoverable' without having to go and look up additional documentation:
faas-cli ls
(or faas-cli ls -f stack.yml
)faas-cli ps <function_name>
(or faas-cli ps -f stack.yml <function_name>
)faas-cli logs <function_name>
(or faas-cli logs -f stack.yml <function_name>
)Ideally, these commands would largely mirror their docker alternatives, but remove any 'extraneous' stuff that can be hidden away by OpenFaaS (in a similar way to how docker compose
hides away extra details that could be manually specified with the raw docker
equivalent)
Considering the below mxnet.yml file to build and deploy my function (code residing under a sample/mxnet folder):
provider:
name: faas
gateway: http://localhost:8080
network: "func_functions" # this is optional and defaults to func_functions
functions:
mxnet:
lang: python
handler: ./sample/mxnet
image: jmkhael/faas-mxnet
I would like to have a way to tell faas-cli to use a specific Dockerfile (e.g. under sample/mxnet) instead of the default lang template one.
faas-cli -action build -f ./sample/mxnet/mxnet.yml
When I deploy a command to my custom named stack, it works (or gives me an error saying it can't)
The CLI claims to successfully deploy the command, but it doesn't work. There is an error in the logs of the gateway. The CLI appears to have hardcoded the name:
⇒ docker service logs openfaas_gateway
..snip..
openfaas_gateway.1.5v3xwo4u9mvb@moby | 2017/09/14 00:19:43 Error response from daemon: network func_functions not found
There also seems to be a defaultNetwork
defined that may not be used anywhere yet:
Allow the network to be specified in the CLI. Return a proper error when deploys fail. Investigate whether the gateway can determine the correct network itself, without relying on the CLI telling it.
⇒ docker --version
Docker version 17.06.2-ce, build cec0b72
⇒ faas-cli version
Git Commit: 118e3e904aa930cafdb64f0efd4538c76fb27088
If there is a file which need to be reformatted, the docker build is interrupted.
There is no verification.
This will result in potentially smaller images.
Private registries are supported by the FaaS REST API - https://github.com/alexellis/faas/blob/master/docs/managing-images.md
The support hasn't been added to the CLI / YAML yet.
Similar to what we've done in the brew
formula - we should write some tests to check that correct operations are called on a remote server. This doesn't need to be white-box testing of classes and can invoke the CLI directly. It would just need a temporary server at the start of the tests.
There was a suggestion by @rgee0 to refactor into separate files. I think we have to do this now due to the upcoming cobra CLI changes.
Use Makefile instead of shell scripts
Tasks are organized in makefiles folder along with the main Makefile at root.
Current scripts will call the corresponding makefile rule in order to maintain backward compatibility.
build.sh
calls make build
build_redist.sh
calls make build_redist
test/version.sh
calls make test_version
deploy_samples
calls make deploy_samples
make test
runs go test
in docker image to test against a specific version of Go
Update all Dockerfiles in samples directory to get the latest version of fwatchdog, 0.6.1
Update help message for "action" option to include "push" and "delete" keywords
Currently there are templates for: csharp, node, python, ruby. It would be great to have a go template as well.
There is a golang base function in the main FaaS repository that can be used as a base. Though this could be improved even more using Docker multi-stage build syntax, and separating the golang compilation environment from the run environment (eg. static compilation)
The faas-cli new command would also need to be updated to include this new template.
Docker builds can be run in parallel rather than serial.
Pros:
Cons
Hi, as Clojure is a great functional language (of the lisp family, you know with lot of parenthesis), I was thinking of adding a template for it in OpenFaaS.
Some of the benefits of Clojure:
When building an application, the project.clj file defines the dependencies. It contains metadata and deps. For instance:
(defproject clojure-echo "0.1.0-SNAPSHOT"
:description "echo function"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.7.0"]]
:main ^:skip-aot clojure-echo.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
Those dependencies are installed with 'lein deps'.
To benefit from the cache when building the image, the deps can be downloaded and installed beforehand. The application can then be built and run as a jar.
Tagging a release should automatically upload the built cli binaries to the Github release from Travis.
If I edit the sample url-ping
python handler in sample/url-ping/handler.py
, run faas-cli build -f ./samples.yml
I can see a new latest image is created alexellis/faas-url-ping:latest
.
I would expect that running faas-cli deploy -f ./samples.yml
would use the local alexellis/faas-url-ping:latest
image.
What appears to happen is that the local images are removed and latest
is pulled from Docker hub.
sample/url-ping/handler.py
, add a new print statementfaas-cli remove url-ping
faas-cli build -f ./samples.yml
docker run -ti --rm alexellis/faas-url-ping sh
faas-cli build -f ./samples.yml
url-ping
end point and see that your changes aren't applied, check the images and see that the newly build image has been replaced with the latest from the hub docker images | grep ping
.This behaviour is counter-intuitive when developing and complicates dev when updating functions that have been pushed to the hub.
docker version
(e.g. Docker 17.0.05 ):This issue tracks the core supported languages by the FaaS-CLI. This is a finite set of languages the project maintainers are happy to support.
These may be covered by community support #85
Anything else can be submitted as a "sample-function" to:
http://github.com/alexellis/faas/blob/master/sample-functions/
Alex
In a similar vein to docker compose
it would be nice if faas-cli
defaulted to a well-known, named yaml file (eg openfaas.yml
or similar) If it did, it wouldn't be a requirement to specify -f foo.yaml
on each CLI command.
All / any assets such as a "src" or "samples" folder should be copied into the final image.
Only files in the root directory are copied in
Seems as simple as setting a flag to "true" in the builder.
It should be possible to "build" a function which isn't using one of the known / supported template types. An example would be the shrink_image example in the repo.
Snippet:
shrink-image:
lang: Dockerfile
handler: ./samples/image-magick
image: functions/resizer
fprocess: "convert - -resize 50% fd:1"
The context is whatever is in the handler
folder and the Dockerfile in the root of the directory will be used for the build.
Build manually and remove the lang
element then mark the item as skip_build
When setting the language to custom
then a docker build
is invoked in the handler folder directly.
This will add versatility - especially for languages which don't suit dynamic templating like Golang.
Instead of "root" let's run as a non-privileged user
They use the default root user.
https://github.com/alexellis/faas-cli/blob/master/template/node/Dockerfile
It would be nice if all of the required 'knowledge' for creating a new function/etc was built into the command line, with something akin to faas-cli init funcName
Be able to create a new function/etc with ease from the command line
Need to read through a lot of different places to understand how to create a new function.
Add init/new/create commands to the CLI that walk a new user through creating a new function, or setting up a stack. Ideally this would allow parameters to be passed directly on the command line, and if they are missing, to 'guide' the user through the process. eg
faas-cli new function
Name []: foo-func
Language [python]: golang
etc
The available 'templates' would be those currently usable, with optional support for pulling remote repos (such as a 3rd party template on github)
Additionally, it would be good to be able to setup a FaaS gateway stack as easy as we can do docker swarm init
.
N/A
When starting a new OpenFaaS based project, there are numerous steps to getting started, that currently seem to require reading a bunch of README's, samples, and blog posts. Minimising this to as few 'built in' steps would ease the onboarding requirement for new users.
Docker version docker version
(e.g. Docker 17.0.05 ): 17.06.1-ce
Are you using Docker Swarm or Kubernetes (FaaS-netes)? Swarm
Operating System and version (e.g. Linux, Windows, MacOS): MacOS
Link to your project or a code example to reproduce issue: N/A
This results in the following output for a brew installed CLI:
$ ./faas-cli version
Git Commit: thisisavalidsha
Following the merge of #50 and the move of the GitCommit
variable from the old main
package rather than commands
package this commit SHA isn't getting populated.
This results in the following output:
$ ./faas-cli version
Git Commit:
0.4.9
release, or build locally using build_redist.sh
and run ./faas-cli version
Docker version docker version
(e.g. Docker 17.0.05 ):
n/a
Are you using Docker Swarm or Kubernetes (FaaS-netes)?
n/a
Operating System and version (e.g. Linux, Windows, MacOS):
MacOS
Link to your project or a code example to reproduce issue:
n/a
Optimizes final image size and uses published rather than debug build.
The help text tells you what the various flags do. It should also give some fully worked examples, or at the very least, pointers in URL format to same.
It is not possible to delete functions via the FaaS CLI.
Extend faas-cli
with the ability to delete a specified function.
Suggest we do do after #17 has been implemented and do so via the faas-cli delete <fn>
verb based approach.
Example: moby/moby#27186
Docker CLI - https://github.com/moby/moby/blob/master/cli/command/image/build.go
When building a function with a node template for instance any additional sub-folders are not copied into the final image - just flat files at the root.
This should be a change in the build step in https://github.com/alexellis/faas-cli/blob/master/app.go#L293
When attempting to deploy a function with faas-cli -action deploy -f ./urlping.yaml
I get the following error message:
~/github/faas-cli$ sudo ./faas-cli -action deploy -f ./urlping.yaml
Deploying: url_ping.
Error removing existing function: Delete http://localhost:8080/system/functions: dial tcp 127.0.0.1:8080: getsockopt: connection refused, gateway=http://localhost:8080, functionName=url_ping
Is FaaS deployed? Do you need to specify the -gateway flag?
Post http://localhost:8080/system/functions: dial tcp 127.0.0.1:8080: getsockopt: connection refused
The file, urlping.yaml, is as described in the README.md example file.
This happens with both the faas-cli downloaded from https://cli.openfaas.com, or one which I have compiled from this repo.
Deploys function
Produces output pasted above
faas-cli -action deploy -f ./urlping.yaml
faas-cli -action deploy -f ./urlping.yaml
docker version
(e.g. Docker 17.0.05 ):Track usage of commands (verbs), parameters (used), build times and other anonymous data that can help us understand usage and improve the CLI.
Remit:
This would only cover the CLI usage - this would not instrument the back-end services.
Opt-in by default, opt-out of collection via environmental variable in a similar fashion to VSCode and Brew.
.bash_profile
export OPEN_FAAS_TELEMETRY=0
We must explain how data is used, how long it is kept for etc and make sure it's in keeping with data protection.
Data must be anonymised
Relying on unsolicited feedback / word of mouth
Google Analytics (subject to costing out) - has a Golang library. https://github.com/google/google-api-go-client/blob/master/analytics/v3/analytics-gen.go
Initial work would only be a PoC
Anyone should be able to download a community-supported 3rd party template for Perl, PHP, Kotlin etc.
PRs to main project.
I'm open to input on this too.
$ faas-cli add-template https://github.com/alexellis/kotlin-template
Downloading https://github.com/alexellis/kotlin-template/master/blob/master.zip
Expanding kotlin/Dockerfile to template/kotlin/Dockerfile
...
Repo structure:
./template/kotlin/Dockerfile
./template/kotlin/handler.java
./README.md
Initial version of this can be a "dumb" shortcut to download a zip file and unzip into a directory.
Out of scope for v1:
Mentions: @johnmccabe and others for the suggestion. @nicholasjackson how does Hashicorp do this?
Other files which need changes:
#82 (comment)
fprocess
needs to come out of the Golang code and sit in a template.yml
file within i.e. ./template/kotlin/template.yml
language: kotlin
fprocess: kotlin handler.kotlin
faas-cli publish -f ./samples.yml -gw kong
Simple documentation fix in Readme.md to change it from ./faas-cli to faas-cli so it doesn't confuse beginners.
Docker version docker version
(e.g. Docker 17.0.05 ):
Are you using Docker Swarm or Kubernetes (FaaS-netes)?
Operating System and version (e.g. Linux, Windows, MacOS):
Link to your project or a code example to reproduce issue:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.