|
| 1 | +// Copyright (c) OpenFaaS Ltd 2025. All rights reserved. |
| 2 | +// // Copyright (c) Alex Ellis 2017. All rights reserved. |
| 3 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 4 | + |
| 5 | +package stack |
| 6 | + |
| 7 | +// Provider for the FaaS set of functions. |
| 8 | +type Provider struct { |
| 9 | + Name string `yaml:"name"` |
| 10 | + GatewayURL string `yaml:"gateway"` |
| 11 | +} |
| 12 | + |
| 13 | +// Function as deployed or built on FaaS |
| 14 | +type Function struct { |
| 15 | + // Name of deployed function |
| 16 | + Name string `yaml:"-"` |
| 17 | + |
| 18 | + Language string `yaml:"lang"` |
| 19 | + |
| 20 | + // Handler Local folder to use for function |
| 21 | + Handler string `yaml:"handler"` |
| 22 | + |
| 23 | + // Image Docker image name |
| 24 | + Image string `yaml:"image"` |
| 25 | + |
| 26 | + FProcess string `yaml:"fprocess"` |
| 27 | + |
| 28 | + Environment map[string]string `yaml:"environment"` |
| 29 | + |
| 30 | + // Secrets list of secrets to be made available to function |
| 31 | + Secrets []string `yaml:"secrets,omitempty"` |
| 32 | + |
| 33 | + SkipBuild bool `yaml:"skip_build,omitempty"` |
| 34 | + |
| 35 | + Constraints *[]string `yaml:"constraints,omitempty"` |
| 36 | + |
| 37 | + // EnvironmentFile is a list of files to import and override environmental variables. |
| 38 | + // These are overriden in order. |
| 39 | + EnvironmentFile []string `yaml:"environment_file,omitempty"` |
| 40 | + |
| 41 | + Labels *map[string]string `yaml:"labels,omitempty"` |
| 42 | + |
| 43 | + // Limits for function |
| 44 | + Limits *FunctionResources `yaml:"limits,omitempty"` |
| 45 | + |
| 46 | + // Requests of resources requested by function |
| 47 | + Requests *FunctionResources `yaml:"requests,omitempty"` |
| 48 | + |
| 49 | + // ReadOnlyRootFilesystem is used to set the container filesystem to read-only |
| 50 | + ReadOnlyRootFilesystem bool `yaml:"readonly_root_filesystem,omitempty"` |
| 51 | + |
| 52 | + // BuildOptions to determine native packages |
| 53 | + BuildOptions []string `yaml:"build_options,omitempty"` |
| 54 | + |
| 55 | + // Annotations |
| 56 | + Annotations *map[string]string `yaml:"annotations,omitempty"` |
| 57 | + |
| 58 | + // Namespace of the function |
| 59 | + Namespace string `yaml:"namespace,omitempty"` |
| 60 | + |
| 61 | + // BuildArgs for providing build-args |
| 62 | + BuildArgs map[string]string `yaml:"build_args,omitempty"` |
| 63 | + |
| 64 | + // Platforms for use with buildx and faas-cli publish |
| 65 | + Platforms string `yaml:"platforms,omitempty"` |
| 66 | + |
| 67 | + // BuildSecrets is a set of secrets to mount with buildkit |
| 68 | + BuildSecrets map[string]string `yaml:"build_secrets,omitempty"` |
| 69 | +} |
| 70 | + |
| 71 | +// Configuration for the stack.yaml file |
| 72 | +type Configuration struct { |
| 73 | + StackConfig StackConfiguration `yaml:"configuration"` |
| 74 | +} |
| 75 | + |
| 76 | +// StackConfiguration for the overall stack.yaml |
| 77 | +type StackConfiguration struct { |
| 78 | + TemplateConfigs []TemplateSource `yaml:"templates"` |
| 79 | + |
| 80 | + // CopyExtraPaths specifies additional paths (relative to the stack file) that will be copied |
| 81 | + // into the functions build context, e.g. specifying `"common"` will look for and copy the |
| 82 | + // "common/" folder of file in the same root as the stack file. All paths must be contained |
| 83 | + // within the project root defined by the location of the stack file. |
| 84 | + // |
| 85 | + // The yaml uses the shorter name `copy` to make it easier for developers to read and use |
| 86 | + CopyExtraPaths []string `yaml:"copy"` |
| 87 | +} |
| 88 | + |
| 89 | +// TemplateSource for build templates |
| 90 | +type TemplateSource struct { |
| 91 | + Name string `yaml:"name"` |
| 92 | + Source string `yaml:"source,omitempty"` |
| 93 | +} |
| 94 | + |
| 95 | +// FunctionResources Memory and CPU |
| 96 | +type FunctionResources struct { |
| 97 | + Memory string `yaml:"memory"` |
| 98 | + CPU string `yaml:"cpu"` |
| 99 | +} |
| 100 | + |
| 101 | +// EnvironmentFile represents external file for environment data |
| 102 | +type EnvironmentFile struct { |
| 103 | + Environment map[string]string `yaml:"environment"` |
| 104 | +} |
| 105 | + |
| 106 | +// Services root level YAML file to define FaaS function-set |
| 107 | +type Services struct { |
| 108 | + Version string `yaml:"version,omitempty"` |
| 109 | + Functions map[string]Function `yaml:"functions,omitempty"` |
| 110 | + Provider Provider `yaml:"provider,omitempty"` |
| 111 | + StackConfiguration StackConfiguration `yaml:"configuration,omitempty"` |
| 112 | +} |
| 113 | + |
| 114 | +// LanguageTemplate read from template.yml within root of a language template folder |
| 115 | +type LanguageTemplate struct { |
| 116 | + Language string `yaml:"language,omitempty"` |
| 117 | + FProcess string `yaml:"fprocess,omitempty"` |
| 118 | + |
| 119 | + BuildOptions []BuildOption `yaml:"build_options,omitempty"` |
| 120 | + |
| 121 | + // WelcomeMessage is printed to the user after generating a function |
| 122 | + WelcomeMessage string `yaml:"welcome_message,omitempty"` |
| 123 | + |
| 124 | + // HandlerFolder to copy the function code into |
| 125 | + HandlerFolder string `yaml:"handler_folder,omitempty"` |
| 126 | + |
| 127 | + MountSSH bool `yaml:"mount_ssh,omitempty"` |
| 128 | +} |
| 129 | + |
| 130 | +// BuildOption a named build option for one or more packages |
| 131 | +type BuildOption struct { |
| 132 | + Name string `yaml:"name"` |
| 133 | + Packages []string `yaml:"packages"` |
| 134 | +} |
0 commit comments