WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: docker/setup-buildx-action@v3
-
name: Local docker build (non-root image)
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
Expand All @@ -42,7 +42,7 @@ jobs:
tags: openfaas/faas-cli:${{ github.sha }}
-
name: Test for multi-arch build
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
Expand Down
434 changes: 0 additions & 434 deletions CHANGELOG.md

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ The main commands supported by the CLI are:
The default gateway URL of `127.0.0.1:8080` can be overridden in three places including an environmental variable.

* 1st priority `--gateway` flag
* 2nd priority `--yaml` / `-f` flag or `stack.yml` if in current directory
* 2nd priority `--yaml` / `-f` flag or `stack.yaml` if in current directory
* 3rd priority `OPENFAAS_URL` environmental variable

For Kubernetes users you may want to set this in your `.bash_rc` file:
Expand Down Expand Up @@ -293,7 +293,7 @@ A YAML stack file groups functions together and also saves on typing.

You can define individual functions or a set of them within a YAML file. This makes the CLI easier to use and means you can use this file to deploy to your OpenFaaS instance. By default the faas-cli will attempt to load `stack.yaml` from the current directory.

Here is an example file using the `stack.yml` file included in the repository.
Here is an example file using the `stack.yaml` file included in the repository.

```yaml
provider:
Expand All @@ -317,10 +317,10 @@ $ faas-cli build

> `-f` specifies the file or URL to download your YAML file from. The long version of the `-f` flag is: `--yaml`.

You can also download over HTTP(s):
You can also download over HTTP(s), for example:

```sh
$ faas-cli build -f https://raw.githubusercontent.com/openfaas/faas-cli/master/stack.yml
$ faas-cli build -f https://raw.githubusercontent.com/openfaas/store-functions/master/stack.yml
```

Docker along with a Python template will be used to build an image named alexellis2/faas-urlping.
Expand Down
2 changes: 1 addition & 1 deletion build_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def handle(event, context):
}
EOF

eval $cli build -f $function_name.yml
eval $cli build -f stack.yaml
}

wait_for_function_up() {
Expand Down
22 changes: 11 additions & 11 deletions commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func init() {
buildCmd.Flags().Var(&tagFormat, "tag", "Override latest tag on function Docker image, accepts 'digest', 'sha', 'branch', or 'describe', or 'latest'")
buildCmd.Flags().StringArrayVar(&buildLabels, "build-label", []string{}, "Add a label for Docker image (LABEL=VALUE)")
buildCmd.Flags().StringArrayVar(&copyExtra, "copy-extra", []string{}, "Extra paths that will be copied into the function build context")
buildCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yml file")
buildCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yaml file")
buildCmd.Flags().BoolVar(&quietBuild, "quiet", false, "Perform a quiet build, without showing output from Docker")
buildCmd.Flags().BoolVar(&disableStackPull, "disable-stack-pull", false, "Disables the template configuration in the stack.yml")
buildCmd.Flags().BoolVar(&disableStackPull, "disable-stack-pull", false, "Disables the template configuration in the stack.yaml")
buildCmd.Flags().BoolVar(&forcePull, "pull", false, "Force a re-pull of base images in template during build, useful for publishing images")

// Set bash-completion.
Expand Down Expand Up @@ -88,16 +88,16 @@ var buildCmd = &cobra.Command{
the "--yaml" flag (which may contain multiple function definitions), or directly
via flags.`,
Example: ` faas-cli build -f https://domain/path/myfunctions.yml
faas-cli build -f ./stack.yml --no-cache --build-arg NPM_VERSION=0.2.2
faas-cli build -f ./stack.yml --build-option dev
faas-cli build -f ./stack.yml --tag sha
faas-cli build -f ./stack.yml --tag branch
faas-cli build -f ./stack.yml --tag describe
faas-cli build -f ./stack.yml --filter "*gif*"
faas-cli build -f ./stack.yml --regex "fn[0-9]_.*"
faas-cli build --image=my_image --lang=python --handler=/path/to/fn/
faas-cli build -f stack.yaml --no-cache --build-arg NPM_VERSION=0.2.2
faas-cli build -f stack.yaml --build-option dev
faas-cli build -f stack.yaml --tag sha
faas-cli build -f stack.yaml --tag branch
faas-cli build -f stack.yaml --tag describe
faas-cli build -f stack.yaml --filter "*gif*"
faas-cli build -f stack.yaml --regex "fn[0-9]_.*"
faas-cli build --image=my_image --lang=python --handler=/path/to/fn/ \
--name=my_fn --squash
faas-cli build -f ./stack.yml --build-label org.label-schema.label-name="value"`,
faas-cli build -f stack.yaml --build-label org.label-schema.label-name="value"`,
PreRunE: preRunBuild,
RunE: runBuild,
}
Expand Down
22 changes: 11 additions & 11 deletions commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func init() {
deployCmd.Flags().Var(&tagFormat, "tag", "Override latest tag on function Docker image, accepts 'latest', 'sha', 'branch', or 'describe'")

deployCmd.Flags().BoolVar(&tlsInsecure, "tls-no-verify", false, "Disable TLS validation")
deployCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yml file")
deployCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yaml file")
deployCmd.Flags().StringVarP(&token, "token", "k", "", "Pass a JWT token to use instead of basic auth")
// Set bash-completion.
_ = deployCmd.Flags().SetAnnotation("handler", cobra.BashCompSubdirsInDir, []string{})
Expand Down Expand Up @@ -113,16 +113,16 @@ var deployCmd = &cobra.Command{
the "--yaml" flag (which may contain multiple function definitions), or directly
via flags. Note: --replace and --update are mutually exclusive.`,
Example: ` faas-cli deploy -f https://domain/path/myfunctions.yml
faas-cli deploy -f ./stack.yml
faas-cli deploy -f ./stack.yml --label canary=true
faas-cli deploy -f ./stack.yml --annotation user=true
faas-cli deploy -f ./stack.yml --filter "*gif*" --secret dockerhuborg
faas-cli deploy -f ./stack.yml --regex "fn[0-9]_.*"
faas-cli deploy -f ./stack.yml --replace=false --update=true
faas-cli deploy -f ./stack.yml --replace=true --update=false
faas-cli deploy -f ./stack.yml --tag sha
faas-cli deploy -f ./stack.yml --tag branch
faas-cli deploy -f ./stack.yml --tag describe
faas-cli deploy -f stack.yaml
faas-cli deploy -f stack.yaml --label canary=true
faas-cli deploy -f stack.yaml --annotation user=true
faas-cli deploy -f stack.yaml --filter "*gif*" --secret dockerhuborg
faas-cli deploy -f stack.yaml --regex "fn[0-9]_.*"
faas-cli deploy -f stack.yaml --replace=false --update=true
faas-cli deploy -f stack.yaml --replace=true --update=false
faas-cli deploy -f stack.yaml --tag sha
faas-cli deploy -f stack.yaml --tag branch
faas-cli deploy -f stack.yaml --tag describe
faas-cli deploy --image=alexellis/faas-url-ping --name=url-ping
faas-cli deploy --image=my_image --name=my_fn --handler=/path/to/fn/
--gateway=http://remote-site.com:8080 --lang=python
Expand Down
2 changes: 1 addition & 1 deletion commands/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {
describeCmd.Flags().StringVar(&functionName, "name", "", "Name of the function")
describeCmd.Flags().StringVarP(&gateway, "gateway", "g", defaultGateway, "Gateway URL starting with http(s)://")
describeCmd.Flags().BoolVar(&tlsInsecure, "tls-no-verify", false, "Disable TLS validation")
describeCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yml file")
describeCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yaml file")
describeCmd.Flags().StringVarP(&token, "token", "k", "", "Pass a JWT token to use instead of basic auth")
describeCmd.Flags().StringVarP(&functionNamespace, "namespace", "n", "", "Namespace of the function")
describeCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose output")
Expand Down
20 changes: 11 additions & 9 deletions commands/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func init() {
generateCmd.Flags().StringVar(&api, "api", defaultAPIVersion, "CRD API version e.g openfaas.com/v1, serving.knative.dev/v1")
generateCmd.Flags().StringVarP(&crdFunctionNamespace, "namespace", "n", "openfaas-fn", "Kubernetes namespace for functions")
generateCmd.Flags().Var(&tagFormat, "tag", "Override latest tag on function Docker image, accepts 'digest', 'latest', 'sha', 'branch', 'describe'")
generateCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yml file")
generateCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yaml file")
generateCmd.Flags().StringVar(&desiredArch, "arch", "x86_64", "Desired image arch. (Default x86_64)")
generateCmd.Flags().StringArrayVar(&annotationArgs, "annotation", []string{}, "Any annotations you want to add (to store functions only)")
generateCmd.Flags().StringArrayVar(&labelArgs, "label", []string{}, "Any labels you want to add (to store functions only)")
Expand All @@ -57,14 +57,14 @@ func init() {
}

var generateCmd = &cobra.Command{
Use: "generate --api=openfaas.com/v1 --yaml stack.yml --tag sha --namespace=openfaas-fn",
Use: "generate --api=openfaas.com/v1 --yaml stack.yaml --tag sha --namespace=openfaas-fn",
Short: "Generate Kubernetes CRD YAML file",
Long: `The generate command creates kubernetes CRD YAML file for functions`,
Example: `faas-cli generate --api=openfaas.com/v1 --yaml stack.yml | kubectl apply -f -
faas-cli generate --api=openfaas.com/v1 -f stack.yml
faas-cli generate --api=serving.knative.dev/v1 -f stack.yml
faas-cli generate --api=openfaas.com/v1 --namespace openfaas-fn -f stack.yml
faas-cli generate --api=openfaas.com/v1 -f stack.yml --tag branch -n openfaas-fn`,
Example: `faas-cli generate --api=openfaas.com/v1 --yaml stack.yaml | kubectl apply -f -
faas-cli generate --api=openfaas.com/v1 -f stack.yaml
faas-cli generate --api=serving.knative.dev/v1 -f stack.yaml
faas-cli generate --api=openfaas.com/v1 --namespace openfaas-fn -f stack.yaml
faas-cli generate --api=openfaas.com/v1 -f stack.yaml --tag branch -n openfaas-fn`,
PreRunE: preRunGenerate,
RunE: runGenerate,
}
Expand Down Expand Up @@ -183,8 +183,10 @@ func runGenerate(cmd *cobra.Command, args []string) error {
}
} else {
fmt.Println(
`"stack.yml" file not found in the current directory.
Use "--yaml" to pass a file or "--from-store" to generate using function store.`)
`No "stack.yaml" or "stack.yml" file was found in the current directory.
Use "--yaml" / "-f" to specify a custom filename.

Alternatively, to generate a definition for store functions, use "--from-store"`)
os.Exit(1)
}

Expand Down
9 changes: 5 additions & 4 deletions commands/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package commands

import (
"bytes"
"crypto"
"encoding/hex"
"fmt"
"io"
Expand All @@ -14,7 +15,7 @@ import (
"runtime"
"strings"

"github.com/alexellis/hmac"
"github.com/alexellis/hmac/v2"
"github.com/openfaas/faas-cli/stack"
"github.com/openfaas/faas-cli/version"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -51,7 +52,7 @@ func init() {
invokeCmd.Flags().StringVar(&sigHeader, "sign", "", "name of HTTP request header to hold the signature")
invokeCmd.Flags().StringVar(&key, "key", "", "key to be used to sign the request (must be used with --sign)")

invokeCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yml file")
invokeCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yaml file")

faasCmd.AddCommand(invokeCmd)
}
Expand Down Expand Up @@ -205,10 +206,10 @@ func runInvoke(cmd *cobra.Command, args []string) error {
}

func generateSignature(message []byte, key string) string {
hash := hmac.Sign(message, []byte(key))
hash := hmac.Sign(message, []byte(key), crypto.SHA256.New)
signature := hex.EncodeToString(hash)

return fmt.Sprintf(`%s=%s`, "sha1", string(signature[:]))
return fmt.Sprintf(`%s=%s`, "sha256", string(signature[:]))
}

func missingSignFlag(header string, key string) bool {
Expand Down
6 changes: 3 additions & 3 deletions commands/invoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ func Test_generateHeader(t *testing.T) {
name: "Empty key",
message: []byte("This is a message"),
key: "",
want: "sha1=cdefd604e685e5c8b31fbcf6621a6e8282770dfe",
want: "sha256=7fb67a61acd7a9fa2541bbde51cef1bd4086a5a3acec0a0c821b40e06e824cfc",
},
{
name: "Key with empty message",
message: []byte(""),
key: "KeySet",
want: "sha1=33dcd94ffaf13fce58615585c030c1a39d100b3c",
want: "sha256=51846d8900847a40a129743c98742c83a56c3cbc4f5aec188d7eb2de629d11df",
},
{
name: "Empty key and message",
message: []byte(""),
key: "",
want: "sha1=fbdb1d1b18aa6c08324b7d64b71fb76370690e1d",
want: "sha256=b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad",
},
}
for _, test := range tests {
Expand Down
2 changes: 1 addition & 1 deletion commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func init() {

listCmd.Flags().BoolVarP(&verboseList, "verbose", "v", false, "Verbose output for the function list")
listCmd.Flags().BoolVar(&tlsInsecure, "tls-no-verify", false, "Disable TLS validation")
listCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yml file")
listCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yaml file")
listCmd.Flags().StringVarP(&token, "token", "k", "", "Pass a JWT token to use instead of basic auth")
listCmd.Flags().StringVar(&sortOrder, "sort", "name", "Sort the functions by \"name\" or \"invocations\"")

Expand Down
6 changes: 3 additions & 3 deletions commands/local_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ services deployed within your OpenFaaS cluster.`,
# Run on a random port
faas-cli local-run -p 0

# Use a custom YAML file other than stack.yml
faas-cli local-run stronghash -f ./stronghash.yml
# Use a custom YAML file other than stack.yaml
faas-cli local-run stronghash -f ./stronghash.yaml
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 1 {
Expand Down Expand Up @@ -133,7 +133,7 @@ func localRunExec(cmd *cobra.Command, args []string, ctx context.Context) error
}

// AE: I found that the `localrun` command will do a build of all functions in
// the stack.yml if no argument is given and there is > 1 function in
// the stack.yaml if no argument is given and there is > 1 function in
// the file, then it will exit with an error when it comes to the run step
func localBuild(cmd *cobra.Command, args []string) error {
if err := preRunBuild(cmd, args); err != nil {
Expand Down
23 changes: 12 additions & 11 deletions commands/new_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var newFunctionCmd = &cobra.Command{
Long: `The new command creates a new function based upon hello-world in the given
language or type in --list for a list of languages available.`,
Example: ` faas-cli new chatbot --lang node
faas-cli new chatbot --lang node --append stack.yml
faas-cli new chatbot --lang node --append bots.yaml
faas-cli new text-parser --lang python --quiet
faas-cli new text-parser --lang python --gateway http://mydomain:8080
faas-cli new --list`,
Expand Down Expand Up @@ -97,6 +97,10 @@ func preRunNewFunction(cmd *cobra.Command, args []string) error {
return err
}

if len(yamlFile) == 0 && len(appendFile) == 0 {
yamlFile = defaultYAML
}

return nil
}

Expand Down Expand Up @@ -160,27 +164,24 @@ Download templates:
appendMode := len(appendFile) > 0

if appendMode {
if (strings.HasSuffix(appendFile, ".yml") || strings.HasSuffix(appendFile, ".yaml")) == false {
if !(strings.HasSuffix(appendFile, ".yml") || strings.HasSuffix(appendFile, ".yaml")) {
return fmt.Errorf("when appending to a stack the suffix should be .yml or .yaml")
}

if _, statErr := os.Stat(appendFile); statErr != nil {
return fmt.Errorf("unable to find file: %s - %s", appendFile, statErr.Error())
}

var duplicateError error
duplicateError = duplicateFunctionName(functionName, appendFile)

if duplicateError != nil {
return duplicateError
if err := duplicateFunctionName(functionName, appendFile); err != nil {
return err
}

fileName = appendFile
outputMsg = fmt.Sprintf("Stack file updated: %s\n", fileName)

} else {
gateway = getGatewayURL(gateway, defaultGateway, gateway, os.Getenv(openFaaSURLEnvironment))
fileName = functionName + ".yml"
fileName = yamlFile
outputMsg = fmt.Sprintf("Stack file written: %s\n", fileName)
}

Expand All @@ -192,14 +193,14 @@ Download templates:
return fmt.Errorf("folder: %s already exists", handlerDir)
}

_, err := os.Stat(fileName)
if err == nil && appendMode == false {
return fmt.Errorf("file: %s already exists", fileName)
if _, err := os.Stat(fileName); err == nil && !appendMode {
return fmt.Errorf("file: %s already exists. Try \"faas-cli new --append %s\" instead", fileName, fileName)
}

if err := os.Mkdir(handlerDir, 0700); err != nil {
return fmt.Errorf("folder: could not create %s : %s", handlerDir, err)
}

fmt.Printf("Folder: %s created.\n", handlerDir)

if err := updateGitignore(); err != nil {
Expand Down
Loading
Loading