Skip to content

Commit acb912d

Browse files
committed
Update faas-cli new to use stack.yaml
Updates faas-cli new to create a stack.yaml file instead of a YAML file named after the function. This is to help users discover that stack.yaml does not require a --yaml or -f flag which can become cumbersome. When a stack.yaml or the file specified via -f already exists the new command will now prompt users to use --append Convert to SHA256 signatures for the invoke command This is a convenience option for invoking functions along with a signature, if a function accepts one. They should all have been moved to sha256 now if they were even using it Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 13a967a commit acb912d

22 files changed

+219
-626
lines changed

.github/workflows/build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
uses: docker/setup-buildx-action@v3
2828
-
2929
name: Local docker build (non-root image)
30-
uses: docker/build-push-action@v5
30+
uses: docker/build-push-action@v6
3131
with:
3232
context: .
3333
file: ./Dockerfile
@@ -42,7 +42,7 @@ jobs:
4242
tags: openfaas/faas-cli:${{ github.sha }}
4343
-
4444
name: Test for multi-arch build
45-
uses: docker/build-push-action@v5
45+
uses: docker/build-push-action@v6
4646
with:
4747
context: .
4848
file: ./Dockerfile

CHANGELOG.md

Lines changed: 0 additions & 434 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ The main commands supported by the CLI are:
9090
The default gateway URL of `127.0.0.1:8080` can be overridden in three places including an environmental variable.
9191

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

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

294294
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.
295295

296-
Here is an example file using the `stack.yml` file included in the repository.
296+
Here is an example file using the `stack.yaml` file included in the repository.
297297

298298
```yaml
299299
provider:
@@ -317,10 +317,10 @@ $ faas-cli build
317317

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

320-
You can also download over HTTP(s):
320+
You can also download over HTTP(s), for example:
321321

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

326326
Docker along with a Python template will be used to build an image named alexellis2/faas-urlping.

build_integration_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def handle(event, context):
5353
}
5454
EOF
5555

56-
eval $cli build -f $function_name.yml
56+
eval $cli build -f stack.yaml
5757
}
5858

5959
wait_for_function_up() {

commands/build.go

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

6464
// Set bash-completion.
@@ -88,16 +88,16 @@ var buildCmd = &cobra.Command{
8888
the "--yaml" flag (which may contain multiple function definitions), or directly
8989
via flags.`,
9090
Example: ` faas-cli build -f https://domain/path/myfunctions.yml
91-
faas-cli build -f ./stack.yml --no-cache --build-arg NPM_VERSION=0.2.2
92-
faas-cli build -f ./stack.yml --build-option dev
93-
faas-cli build -f ./stack.yml --tag sha
94-
faas-cli build -f ./stack.yml --tag branch
95-
faas-cli build -f ./stack.yml --tag describe
96-
faas-cli build -f ./stack.yml --filter "*gif*"
97-
faas-cli build -f ./stack.yml --regex "fn[0-9]_.*"
98-
faas-cli build --image=my_image --lang=python --handler=/path/to/fn/
91+
faas-cli build -f stack.yaml --no-cache --build-arg NPM_VERSION=0.2.2
92+
faas-cli build -f stack.yaml --build-option dev
93+
faas-cli build -f stack.yaml --tag sha
94+
faas-cli build -f stack.yaml --tag branch
95+
faas-cli build -f stack.yaml --tag describe
96+
faas-cli build -f stack.yaml --filter "*gif*"
97+
faas-cli build -f stack.yaml --regex "fn[0-9]_.*"
98+
faas-cli build --image=my_image --lang=python --handler=/path/to/fn/ \
9999
--name=my_fn --squash
100-
faas-cli build -f ./stack.yml --build-label org.label-schema.label-name="value"`,
100+
faas-cli build -f stack.yaml --build-label org.label-schema.label-name="value"`,
101101
PreRunE: preRunBuild,
102102
RunE: runBuild,
103103
}

commands/deploy.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func init() {
6969
deployCmd.Flags().Var(&tagFormat, "tag", "Override latest tag on function Docker image, accepts 'latest', 'sha', 'branch', or 'describe'")
7070

7171
deployCmd.Flags().BoolVar(&tlsInsecure, "tls-no-verify", false, "Disable TLS validation")
72-
deployCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yml file")
72+
deployCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yaml file")
7373
deployCmd.Flags().StringVarP(&token, "token", "k", "", "Pass a JWT token to use instead of basic auth")
7474
// Set bash-completion.
7575
_ = deployCmd.Flags().SetAnnotation("handler", cobra.BashCompSubdirsInDir, []string{})
@@ -113,16 +113,16 @@ var deployCmd = &cobra.Command{
113113
the "--yaml" flag (which may contain multiple function definitions), or directly
114114
via flags. Note: --replace and --update are mutually exclusive.`,
115115
Example: ` faas-cli deploy -f https://domain/path/myfunctions.yml
116-
faas-cli deploy -f ./stack.yml
117-
faas-cli deploy -f ./stack.yml --label canary=true
118-
faas-cli deploy -f ./stack.yml --annotation user=true
119-
faas-cli deploy -f ./stack.yml --filter "*gif*" --secret dockerhuborg
120-
faas-cli deploy -f ./stack.yml --regex "fn[0-9]_.*"
121-
faas-cli deploy -f ./stack.yml --replace=false --update=true
122-
faas-cli deploy -f ./stack.yml --replace=true --update=false
123-
faas-cli deploy -f ./stack.yml --tag sha
124-
faas-cli deploy -f ./stack.yml --tag branch
125-
faas-cli deploy -f ./stack.yml --tag describe
116+
faas-cli deploy -f stack.yaml
117+
faas-cli deploy -f stack.yaml --label canary=true
118+
faas-cli deploy -f stack.yaml --annotation user=true
119+
faas-cli deploy -f stack.yaml --filter "*gif*" --secret dockerhuborg
120+
faas-cli deploy -f stack.yaml --regex "fn[0-9]_.*"
121+
faas-cli deploy -f stack.yaml --replace=false --update=true
122+
faas-cli deploy -f stack.yaml --replace=true --update=false
123+
faas-cli deploy -f stack.yaml --tag sha
124+
faas-cli deploy -f stack.yaml --tag branch
125+
faas-cli deploy -f stack.yaml --tag describe
126126
faas-cli deploy --image=alexellis/faas-url-ping --name=url-ping
127127
faas-cli deploy --image=my_image --name=my_fn --handler=/path/to/fn/
128128
--gateway=http://remote-site.com:8080 --lang=python

commands/describe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func init() {
2626
describeCmd.Flags().StringVar(&functionName, "name", "", "Name of the function")
2727
describeCmd.Flags().StringVarP(&gateway, "gateway", "g", defaultGateway, "Gateway URL starting with http(s)://")
2828
describeCmd.Flags().BoolVar(&tlsInsecure, "tls-no-verify", false, "Disable TLS validation")
29-
describeCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yml file")
29+
describeCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yaml file")
3030
describeCmd.Flags().StringVarP(&token, "token", "k", "", "Pass a JWT token to use instead of basic auth")
3131
describeCmd.Flags().StringVarP(&functionNamespace, "namespace", "n", "", "Namespace of the function")
3232
describeCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose output")

commands/generate.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func init() {
4848
generateCmd.Flags().StringVar(&api, "api", defaultAPIVersion, "CRD API version e.g openfaas.com/v1, serving.knative.dev/v1")
4949
generateCmd.Flags().StringVarP(&crdFunctionNamespace, "namespace", "n", "openfaas-fn", "Kubernetes namespace for functions")
5050
generateCmd.Flags().Var(&tagFormat, "tag", "Override latest tag on function Docker image, accepts 'digest', 'latest', 'sha', 'branch', 'describe'")
51-
generateCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yml file")
51+
generateCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yaml file")
5252
generateCmd.Flags().StringVar(&desiredArch, "arch", "x86_64", "Desired image arch. (Default x86_64)")
5353
generateCmd.Flags().StringArrayVar(&annotationArgs, "annotation", []string{}, "Any annotations you want to add (to store functions only)")
5454
generateCmd.Flags().StringArrayVar(&labelArgs, "label", []string{}, "Any labels you want to add (to store functions only)")
@@ -57,14 +57,14 @@ func init() {
5757
}
5858

5959
var generateCmd = &cobra.Command{
60-
Use: "generate --api=openfaas.com/v1 --yaml stack.yml --tag sha --namespace=openfaas-fn",
60+
Use: "generate --api=openfaas.com/v1 --yaml stack.yaml --tag sha --namespace=openfaas-fn",
6161
Short: "Generate Kubernetes CRD YAML file",
6262
Long: `The generate command creates kubernetes CRD YAML file for functions`,
63-
Example: `faas-cli generate --api=openfaas.com/v1 --yaml stack.yml | kubectl apply -f -
64-
faas-cli generate --api=openfaas.com/v1 -f stack.yml
65-
faas-cli generate --api=serving.knative.dev/v1 -f stack.yml
66-
faas-cli generate --api=openfaas.com/v1 --namespace openfaas-fn -f stack.yml
67-
faas-cli generate --api=openfaas.com/v1 -f stack.yml --tag branch -n openfaas-fn`,
63+
Example: `faas-cli generate --api=openfaas.com/v1 --yaml stack.yaml | kubectl apply -f -
64+
faas-cli generate --api=openfaas.com/v1 -f stack.yaml
65+
faas-cli generate --api=serving.knative.dev/v1 -f stack.yaml
66+
faas-cli generate --api=openfaas.com/v1 --namespace openfaas-fn -f stack.yaml
67+
faas-cli generate --api=openfaas.com/v1 -f stack.yaml --tag branch -n openfaas-fn`,
6868
PreRunE: preRunGenerate,
6969
RunE: runGenerate,
7070
}
@@ -183,8 +183,10 @@ func runGenerate(cmd *cobra.Command, args []string) error {
183183
}
184184
} else {
185185
fmt.Println(
186-
`"stack.yml" file not found in the current directory.
187-
Use "--yaml" to pass a file or "--from-store" to generate using function store.`)
186+
`No "stack.yaml" or "stack.yml" file was found in the current directory.
187+
Use "--yaml" / "-f" to specify a custom filename.
188+
189+
Alternatively, to generate a definition for store functions, use "--from-store"`)
188190
os.Exit(1)
189191
}
190192

commands/invoke.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package commands
55

66
import (
77
"bytes"
8+
"crypto"
89
"encoding/hex"
910
"fmt"
1011
"io"
@@ -14,7 +15,7 @@ import (
1415
"runtime"
1516
"strings"
1617

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

54-
invokeCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yml file")
55+
invokeCmd.Flags().BoolVar(&envsubst, "envsubst", true, "Substitute environment variables in stack.yaml file")
5556

5657
faasCmd.AddCommand(invokeCmd)
5758
}
@@ -205,10 +206,10 @@ func runInvoke(cmd *cobra.Command, args []string) error {
205206
}
206207

207208
func generateSignature(message []byte, key string) string {
208-
hash := hmac.Sign(message, []byte(key))
209+
hash := hmac.Sign(message, []byte(key), crypto.SHA256.New)
209210
signature := hex.EncodeToString(hash)
210211

211-
return fmt.Sprintf(`%s=%s`, "sha1", string(signature[:]))
212+
return fmt.Sprintf(`%s=%s`, "sha256", string(signature[:]))
212213
}
213214

214215
func missingSignFlag(header string, key string) bool {

commands/invoke_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,19 @@ func Test_generateHeader(t *testing.T) {
9898
name: "Empty key",
9999
message: []byte("This is a message"),
100100
key: "",
101-
want: "sha1=cdefd604e685e5c8b31fbcf6621a6e8282770dfe",
101+
want: "sha256=7fb67a61acd7a9fa2541bbde51cef1bd4086a5a3acec0a0c821b40e06e824cfc",
102102
},
103103
{
104104
name: "Key with empty message",
105105
message: []byte(""),
106106
key: "KeySet",
107-
want: "sha1=33dcd94ffaf13fce58615585c030c1a39d100b3c",
107+
want: "sha256=51846d8900847a40a129743c98742c83a56c3cbc4f5aec188d7eb2de629d11df",
108108
},
109109
{
110110
name: "Empty key and message",
111111
message: []byte(""),
112112
key: "",
113-
want: "sha1=fbdb1d1b18aa6c08324b7d64b71fb76370690e1d",
113+
want: "sha256=b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad",
114114
},
115115
}
116116
for _, test := range tests {

0 commit comments

Comments
 (0)