mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
27
docs/apps.md
27
docs/apps.md
@@ -1,9 +1,30 @@
|
||||
# Applications
|
||||
|
||||
Applications are the top level object that groups routes together to create an API.
|
||||
Applications are the top level object that groups routes together to create an API.
|
||||
|
||||
## App level configuration
|
||||
|
||||
When creating or updating an app, you can pass in a map of config variables.
|
||||
When creating or updating an app, you can pass in a map of config variables.
|
||||
|
||||
TODO: link to swagger doc on swaggerhub after it's updated.
|
||||
`config` is a map of values passed to the route runtime in the form of
|
||||
environment variables prefixed with `CONFIG_`.
|
||||
|
||||
Note: Route level configuration overrides app level configuration.
|
||||
|
||||
```sh
|
||||
fnctl apps create --config k1=v1 --config k2=v2 myapp
|
||||
```
|
||||
|
||||
Or using a cURL:
|
||||
|
||||
```sh
|
||||
curl -H "Content-Type: application/json" -X POST -d '{
|
||||
"app": {
|
||||
"name":"myapp-curl",
|
||||
"config": {
|
||||
"k1": "v1",
|
||||
"k2": "v2"
|
||||
}
|
||||
}
|
||||
}' http://localhost:8080/v1/apps
|
||||
```
|
||||
@@ -6,7 +6,7 @@ swagger: '2.0'
|
||||
info:
|
||||
title: IronFunctions
|
||||
description:
|
||||
version: "0.0.13"
|
||||
version: "0.0.14"
|
||||
# the domain of the service
|
||||
host: "127.0.0.1:8080"
|
||||
# array of all schemes that your API supports
|
||||
@@ -287,7 +287,7 @@ definitions:
|
||||
description: Route type
|
||||
config:
|
||||
type: object
|
||||
description: Route configuration
|
||||
description: Route configuration - overrides application configuration
|
||||
additionalProperties:
|
||||
type: string
|
||||
|
||||
@@ -298,6 +298,11 @@ definitions:
|
||||
type: string
|
||||
description: "Name of this app. Must be different than the image name. Can ony contain alphanumeric, -, and _."
|
||||
readOnly: true
|
||||
config:
|
||||
type: object
|
||||
description: Application configuration
|
||||
additionalProperties:
|
||||
type: string
|
||||
|
||||
RoutesWrapper:
|
||||
type: object
|
||||
|
||||
@@ -26,6 +26,10 @@ myapp
|
||||
$ fnctl apps create otherapp # create new app
|
||||
otherapp created
|
||||
|
||||
$ fnctl apps describe otherapp # describe an app
|
||||
app: otherapp
|
||||
no specific configuration
|
||||
|
||||
$ fnctl apps
|
||||
myapp
|
||||
otherapp
|
||||
@@ -180,6 +184,23 @@ path result
|
||||
their version according to [semver](http://semver.org/) rules. In their absence,
|
||||
it will skip.
|
||||
|
||||
## Application level configuration
|
||||
|
||||
When creating an application, you can configure it to tweak its behavior and its
|
||||
routes' with an appropriate flag, `config`.
|
||||
|
||||
Thus a more complete example of an application creation will look like:
|
||||
```sh
|
||||
fnctl apps create --config DB_URL=http://example.org/ otherapp
|
||||
```
|
||||
|
||||
`--config` is a map of values passed to the route runtime in the form of
|
||||
environment variables prefixed with `CONFIG_`.
|
||||
|
||||
Repeated calls to `fnctl apps create` will trigger an update of the given
|
||||
route, thus you will be able to change any of these attributes later in time
|
||||
if necessary.
|
||||
|
||||
## Route level configuration
|
||||
|
||||
When creating a route, you can configure it to tweak its behavior, the possible
|
||||
|
||||
@@ -3,6 +3,9 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/iron-io/functions_go"
|
||||
"github.com/urfave/cli"
|
||||
@@ -26,6 +29,17 @@ func apps() cli.Command {
|
||||
Name: "create",
|
||||
Usage: "create a new app",
|
||||
Action: a.create,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "config",
|
||||
Usage: "application configuration",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "describe",
|
||||
Usage: "describe an existing app",
|
||||
Action: a.describe,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -63,7 +77,15 @@ func (a *appsCmd) create(c *cli.Context) error {
|
||||
}
|
||||
|
||||
appName := c.Args().Get(0)
|
||||
body := functions.AppWrapper{App: functions.App{Name: appName}}
|
||||
configs := make(map[string]string)
|
||||
for _, v := range c.StringSlice("config") {
|
||||
kv := strings.SplitN(v, "=", 2)
|
||||
configs[kv[0]] = kv[1]
|
||||
}
|
||||
body := functions.AppWrapper{App: functions.App{
|
||||
Name: appName,
|
||||
Config: configs,
|
||||
}}
|
||||
wrapper, _, err := a.AppsPost(body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating app: %v", err)
|
||||
@@ -72,3 +94,31 @@ func (a *appsCmd) create(c *cli.Context) error {
|
||||
fmt.Println(wrapper.App.Name, "created")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *appsCmd) describe(c *cli.Context) error {
|
||||
if c.Args().First() == "" {
|
||||
return errors.New("error: app description takes one argument, an app name")
|
||||
}
|
||||
|
||||
if err := resetBasePath(&a.Configuration); err != nil {
|
||||
return fmt.Errorf("error setting endpoint: %v", err)
|
||||
}
|
||||
|
||||
appName := c.Args().Get(0)
|
||||
wrapper, _, err := a.AppsAppGet(appName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating app: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("app:", wrapper.App.Name)
|
||||
if config := wrapper.App.Config; len(config) > 0 {
|
||||
fmt.Println("configuration:")
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, ' ', 0)
|
||||
fmt.Fprintln(w, "key\tvalue")
|
||||
for k, v := range wrapper.App.Config {
|
||||
fmt.Fprint(w, k, "\t", v, "\n")
|
||||
}
|
||||
w.Flush()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
6
fnctl/glide.lock
generated
6
fnctl/glide.lock
generated
@@ -1,5 +1,5 @@
|
||||
hash: ed621664a6ddc808b65620c5be9966978530b06cb1e452ba8db0a5655cbb19d2
|
||||
updated: 2016-11-09T00:20:54.36270079+01:00
|
||||
hash: a7faac39f56e73fb3987d7a00062a52817432ba5e9620cc83dca15b75496f926
|
||||
updated: 2016-11-09T20:59:19.840009806+01:00
|
||||
imports:
|
||||
- name: github.com/aws/aws-sdk-go
|
||||
version: 90dec2183a5f5458ee79cbaf4b8e9ab910bc81a6
|
||||
@@ -77,7 +77,7 @@ imports:
|
||||
- name: github.com/hashicorp/go-cleanhttp
|
||||
version: ad28ea4487f05916463e2423a55166280e8254b5
|
||||
- name: github.com/iron-io/functions_go
|
||||
version: 2942fd282d03cc17dc9663c95b9ee3f6c513db43
|
||||
version: 7f5bf75abece5380e916b594e17a552be365276d
|
||||
- name: github.com/iron-io/iron_go3
|
||||
version: b50ecf8ff90187fc5fabccd9d028dd461adce4ee
|
||||
subpackages:
|
||||
|
||||
@@ -8,7 +8,7 @@ import:
|
||||
- bump
|
||||
- storage
|
||||
- package: github.com/iron-io/functions_go
|
||||
version: 2942fd282d03cc17dc9663c95b9ee3f6c513db43
|
||||
version: 7f5bf75abece5380e916b594e17a552be365276d
|
||||
- package: github.com/iron-io/iron_go3
|
||||
subpackages:
|
||||
- config
|
||||
|
||||
Reference in New Issue
Block a user