Using Fn CLI

This section will discuss how to use the basics of the Fn CLI, a command line to control Fn. Let's start with the installation of the Fn CLI. Make sure that the curl command exists on your system:

$ curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh

After installing the previous command, check its version and help by typing fn. The current version of the command line is 0.4.43 at the time of writing. Things move fast, so you can expect to use the different version anyway:

$ fn
fn 0.4.43

Fn command line tool

ENVIRONMENT VARIABLES:
FN_API_URL - Fn server address
FN_REGISTRY - Docker registry to push images to, use username only to push to Docker Hub - [[registry.hub.docker.com/]USERNAME]

COMMANDS:
...

There are several sub-commands provided by fn, for example:

  • fn start is a thin wrapper around the docker run command. This subcommand starts the new Fn Server instance. The default address will be http://localhost:8080. The Fn CLI will however be trying to connect to the address defined in FN_API_URL, if set as an environment variable.
  • fn update is the command for pulling the latest version of the Fn Server to a local Docker image.
  • fn init is the command for initializing a skeleton to develop a new function. It accepts the --runtime parameter to generate the template for a specific language, such as Go, for example.
  • fn apps contains subcommands for creating, updating, and deleting an application, and is a kind of namespace or package to group functions together. It is required that a function must be defined under an application.
  • fn routes is a set of commands to define a route pointing to a function container. For example, we have the application demo, then we can define the route, hello and point it to the Docker container image, test/hello:v1. An application may be many routes:
Figure 5.4: The relation between an Fn application and its routes

Here's how Fn organizes routes under an application. For example, an Fn's API URL is http://localhost:8080. We may have an application named demo containing a route named hello created for the container image, test/hello:v1. All these together form a fully qualified URL for accessing the function.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset