cmd

package
v0.0.0-...-bae1a90 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTemplateRepository = "https://github.com/openfaas/templates.git"

DefaultTemplateRepository contains the Git repo for the official templates

View Source
const TemplateDirectory = "./template/"

TemplateDirectory contains the directory where templates are stored

Variables

View Source
var BuildCmd = &cobra.Command{
	Use: `build -f YAML_FILE [--no-cache] [--squash]
  faas-cli build --image IMAGE_NAME
                 --handler HANDLER_DIR
                 --name FUNCTION_NAME
                 [--lang <ruby|python|python3|node|csharp|dockerfile>]
                 [--no-cache] [--squash]
                 [--regex "REGEX"]
                 [--filter "WILDCARD"]
                 [--parallel PARALLEL_DEPTH]
                 [--build-arg KEY=VALUE]
                 [--build-option VALUE]
                 [--copy-extra PATH]`,
	Short: "Builds OpenFaaS function containers",
	Long: `Builds OpenFaaS function containers either via the supplied YAML config using
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 --filter "*gif*"
  faas-cli build -f ./stack.yml --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"`,
	RunE: runBuild,
}

BuildCmd allows the user to build an OpenFaaS function container

View Source
var CheckCmd = &cobra.Command{
	Use:     "check <path to infrastructure file>",
	Short:   "Check the infrastructure",
	Long:    "Check the infrastructure defined in the specified file.",
	Example: `  ermes-cli check my-infra.json`,
	Args:    cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		log.Println("Checking infrastructure defined in", args[0])

		infrastructureFileName := args[0]

		infraBytes, err := os.ReadFile(infrastructureFileName)

		if err != nil {
			log.Fatal("Error reading infrastructure file:", err)
			return
		}

		_, _, err = infrastructure.UnmarshalInfrastructure(infraBytes)

		if err != nil {
			log.Fatal("Error parsing infrastructure JSON:", err)
			return
		}

		log.Println("The infrastructure is valid.")
	},
}
View Source
var DeployCmd = &cobra.Command{
	Use:   "deploy <function name> <path to infrastructure file>",
	Short: "Deploy a function to specified infrastructure.",
	Long:  "Deploy a function to specified infrastructure.",
	Example: `  ermes-cli deploy my-function my-infra.json
	ermes-cli deploy my-function my-infra.json --deploy-in "#Milan"
	ermes-cli deploy my-function my-infra.json --ermes-cli "--gateway http://localhost:8080"`,
	Args: cobra.ExactArgs(2),
	Run: func(cmd *cobra.Command, args []string) {

		log.Println("Deploying function", args[0], "to infrastructure", args[1])

		functionName, infrastructureFileName := args[0], args[1]

		infraBytes, err := os.ReadFile(infrastructureFileName)

		if err != nil {
			log.Fatal("Error reading infrastructure file:", err)
			return
		}

		infra, areasMap, err := infrastructure.UnmarshalInfrastructure(infraBytes)

		if err != nil {
			log.Fatal("Error parsing infrastructure JSON:", err)
			return
		}

		in, _ := cmd.Flags().GetString("deploy-in")

		if in == "" {
			in = "*"
		}

		areas, err := query.CollectAreas(infra, areasMap, in)

		if err != nil {
			log.Fatal("Error collecting areas:", err)
			return
		}

		openFaasCliArguments, err := cmd.Flags().GetStringArray("faas-cli")

		if err != nil {
			log.Fatal("Error getting faas-cli arguments:", err)
			return
		}

		core.Deploy(functionName, openFaasCliArguments, areas)
	},
}
View Source
var NewFunctionCmd = &cobra.Command{
	Use:   "new FUNCTION_NAME --lang=FUNCTION_LANGUAGE [--gateway=http://host:port] | --list | --append=STACK_FILE)",
	Short: "Create a new template in the current folder with the name given as name",
	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: `  ermes-cli new chatbot --lang node
  ermes-cli new chatbot --lang node --append stack.yml
  ermes-cli new text-parser --lang python --quiet
  ermes-cli new text-parser --lang python --gateway http://mydomain:8080
  ermes-cli new --list`,
	Args: cobra.MinimumNArgs(1),
	RunE: runNewFunction,
}

NewFunctionCmd displays newFunction information

View Source
var PrintCmd = &cobra.Command{
	Use:     "print <path to infrastructure file>",
	Short:   "Print the infrastructure",
	Long:    "Print the infrastructure defined in the specified file.",
	Example: `  ermes-cli print my-infra.json`,
	Args:    cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		log.Println("Printing infrastructure defined in", args[0])

		infrastructureFileName := args[0]

		infraBytes, err := os.ReadFile(infrastructureFileName)

		if err != nil {
			log.Fatal("Error reading infrastructure file:", err)
			return
		}

		infra, _, err := infrastructure.UnmarshalInfrastructure(infraBytes)

		if err != nil {
			log.Fatal("Error parsing infrastructure JSON:", err)
			return
		}

		log.Println(infra.String())
	},
}
View Source
var RootCmd = &cobra.Command{
	Use:     "ermes-cli",
	Short:   "CLI for Ermes",
	Version: "0.0.1",
}
View Source
var TemplateCmd = &cobra.Command{
	Use:     `template [COMMAND]`,
	Short:   "OpenFaaS template store and pull commands",
	Long:    "Allows pulling custom templates",
	Example: `  ermes-cli template pull https://github.com/custom/template`,
}

templateCmd allows access to store and pull commands

View Source
var TemplatePullCmd = &cobra.Command{
	Use:   `pull [REPOSITORY_URL]`,
	Short: `Downloads templates from the specified git repo`,
	Long: `Downloads templates from the specified git repo specified by [REPOSITORY_URL], and copies the 'template'
directory from the root of the repo, if it exists (The default repo is https://github.com/ermes-labs/templates).

[REPOSITORY_URL] may specify a specific branch or tag to copy by adding a URL fragment with the branch or tag name.
	`,
	Example: `
  ermes-cli template pull https://github.com/ermes-labs/templates
`,
	Args: cobra.RangeArgs(0, 1),
	Run: func(_ *cobra.Command, args []string) {
		repositoryURL := "https://github.com/ermes-labs/templates"
		if len(args) > 0 {
			repositoryURL = args[0]
		}

		err := exec.Command("faas-cli", "template", "pull", repositoryURL).Run()

		if err != nil {

			log.Fatal("Error pulling template:", err)
		}
	},
}

templatePullCmd allows the user to fetch a template from a repository

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL