container Deploy
Last updated
Last updated
Deploy a container image, e.g. in a Kubernetes namespace (when used with the kubernetes
provider).
This is a simplified abstraction, which can be convenient for simple deployments, but has limited features compared to more platform-specific types. For example, you cannot specify replicas for redundancy, and various platform-specific options are not included. For more flexibility, please look at other Deploy types like helm or kubernetes.
Below is the full schema reference for the action. For an introduction to configuring Garden, please look at our Configuration guide.
container
actions also export values that are available in template strings. See the Outputs section below for details.
type
The type of action, e.g. exec
, container
or kubernetes
. Some are built into Garden but mostly these will be defined by your configured providers.
Type | Required |
---|---|
name
A valid name for the action. Must be unique across all actions of the same kind in your project.
Type | Required |
---|---|
description
A description of the action.
source
By default, the directory where the action is defined is used as the source for the build context.
You can override this by setting either source.path
to another (POSIX-style) path relative to the action source directory, or source.repository
to get the source from an external repository.
If using source.path
, you must make sure the target path is in a git repository.
For source.repository
behavior, please refer to the Remote Sources guide.
source.path
source > path
A relative POSIX-style path to the source directory for this action. You must make sure this path exists and is in a git repository!
source.repository
source > repository
When set, Garden will import the action source from this repository, but use this action configuration (and not scan for configs in the separate repository).
source.repository.url
source > repository > url
A remote repository URL. Currently only supports git servers. Must contain a hash suffix pointing to a specific branch or tag, with the format: #<branch|tag>
Example:
dependencies[]
A list of other actions that this action depends on, and should be built, deployed or run (depending on the action type) before processing this action.
Each dependency should generally be expressed as a "<kind>.<name>"
string, where is one of build
, deploy
, run
or test
, and is the name of the action to depend on.
You may also optionally specify a dependency as an object, e.g. { kind: "Build", name: "some-image" }
.
Any empty values (i.e. null or empty strings) are ignored, so that you can conditionally add in a dependency via template expressions.
Example:
disabled
Set this to true
to disable the action. You can use this with conditional template strings to disable actions based on, for example, the current environment or other variables (e.g. disabled: ${environment.name == "prod"}
). This can be handy when you only need certain actions for specific environments, e.g. only for development.
For Build actions, this means the build is not performed unless it is declared as a dependency by another enabled action (in which case the Build is assumed to be necessary for the dependant action to be run or built).
For other action kinds, the action is skipped in all scenarios, and dependency declarations to it are ignored. Note however that template strings referencing outputs (i.e. runtime outputs) will fail to resolve when the action is disabled, so you need to make sure to provide alternate values for those if you're using them, using conditional expressions.
environments[]
If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the disabled
field with an expression for environments. For example, environments: ["prod"]
is equivalent to disabled: ${environment.name != "prod"}
.
include[]
Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed version of the action.
For actions other than Build actions, this is usually not necessary to specify, or is implicitly inferred. An exception would be e.g. an exec
action without a build
reference, where the relevant files cannot be inferred and you want to define which files should affect the version of the action, e.g. to make sure a Test action is run when certain files are modified.
Build actions have a different behavior, since they generally are based on some files in the source tree, so please reference the docs for more information on those.
Note that you can also exclude files using the exclude
field or by placing .gardenignore
files in your source tree, which use the same format as .gitignore
files. See the Configuration Files guide for details.
Example:
exclude[]
Specify a list of POSIX-style paths or glob patterns that should be explicitly excluded from the action's version.
For actions other than Build actions, this is usually not necessary to specify, or is implicitly inferred. For Deploy, Run and Test actions, the exclusions specified here only applied on top of explicitly set include
paths, or such paths inferred by providers. See the Configuration Files guide for details.
Unlike the scan.exclude
field in the project config, the filters here have no effect on which files and directories are watched for changes when watching is enabled. Use the project scan.exclude
field to affect those, if you have large directories that should not be watched for changes.
Example:
variables
A map of variables scoped to this particular action. These are resolved before any other parts of the action configuration and take precedence over group-scoped variables (if applicable) and project-scoped variables, in that order. They may reference group-scoped and project-scoped variables, and generally can use any template strings normally allowed when resolving the action.
varfiles[]
Specify a list of paths (relative to the directory where the action is defined) to a file containing variables, that we apply on top of the action-level variables
field, and take precedence over group-level variables (if applicable) and project-level variables, in that order.
If you specify multiple paths, they are merged in the order specified, i.e. the last one takes precedence over the previous ones.
The format of the files is determined by the configured file's extension:
.yaml
/.yml
- YAML. The file must consist of a YAML document, which must be a map (dictionary). Keys may contain any value type. YAML format is used by default.
.env
- Standard "dotenv" format, as defined by dotenv.
.json
- JSON. Must contain a single JSON object (not an array).
NOTE: The default varfile format was changed to YAML in Garden v0.13, since YAML allows for definition of nested objects and arrays.
To use different varfiles in different environments, you can template in the environment name to the varfile name, e.g. varfile: "my-action.${environment.name}.env"
(this assumes that the corresponding varfiles exist).
If a listed varfile cannot be found, throwing an error. To add optional varfiles, you can use a list item object with a path
and an optional optional
boolean field.
Example:
varfiles[].path
varfiles > path
Path to a file containing a path.
varfiles[].optional
varfiles > optional
Whether the varfile is optional.
build
Specify a Build action, and resolve this action from the context of that Build.
For example, you might create an exec
Build which prepares some manifests, and then reference that in a kubernetes
Deploy action, and the resulting manifests from the Build.
This would mean that instead of looking for manifest files relative to this action's location in your project structure, the output directory for the referenced exec
Build would be the source.
kind
timeout
Timeout for the deploy to complete, in seconds.
spec
spec.command[]
spec > command
The command/entrypoint to run the container with.
Example:
spec.args[]
spec > args
The arguments (on top of the command
, i.e. entrypoint) to run the container with.
Example:
spec.env
spec > env
Key/value map of environment variables. Keys must be valid POSIX environment variable names (must not start with GARDEN
) and values must be primitives or references to secrets.
Example:
spec.cpu
spec > cpu
spec.cpu.min
The minimum amount of CPU the container needs to be available for it to be deployed, in millicpus (i.e. 1000 = 1 CPU)
spec.cpu.max
The maximum amount of CPU the container can use, in millicpus (i.e. 1000 = 1 CPU). If set to null will result in no limit being set.
spec.memory
spec > memory
spec.memory.min
The minimum amount of RAM the container needs to be available for it to be deployed, in megabytes (i.e. 1024 = 1 GB)
spec.memory.max
The maximum amount of RAM the container can use, in megabytes (i.e. 1024 = 1 GB) If set to null will result in no limit being set.
spec.volumes[]
spec > volumes
List of volumes that should be mounted when starting the container.
Note: If neither hostPath
nor action
is specified, an empty ephemeral volume is created and mounted when deploying the container.
spec.volumes[].name
The name of the allocated volume.
spec.volumes[].containerPath
spec > volumes > containerPath
The path where the volume should be mounted in the container.
spec.volumes[].hostPath
NOTE: Usage of hostPath is generally discouraged, since it doesn't work reliably across different platforms and providers. Some providers may not support it at all.
A local path or path on the node that's running the container, to mount in the container, relative to the config source directory (or absolute).
Example:
spec.volumes[].action
The action reference to a volume Deploy action that should be mounted at containerPath
. The supported action types are persistentvolumeclaim
and configmap
.
Note: Make sure to pay attention to the supported accessModes
of the referenced volume. Unless it supports the ReadWriteMany access mode, you'll need to make sure it is not configured to be mounted by multiple services at the same time. Refer to the documentation of the module type in question to learn more.
spec.privileged
spec > privileged
If true, run the main container in privileged mode. Processes in privileged containers are essentially equivalent to root on the host. Defaults to false.
spec.addCapabilities[]
spec > addCapabilities
POSIX capabilities to add when running the container.
spec.dropCapabilities[]
spec > dropCapabilities
POSIX capabilities to remove when running the container.
spec.tty
spec > tty
Specify if containers in this action have TTY support enabled (which implies having stdin support enabled).
spec.deploymentStrategy
spec > deploymentStrategy
Specifies the container's deployment strategy.
spec.annotations
spec > annotations
Annotations to attach to the service (note: May not be applicable to all providers).
When using the Kubernetes provider, these annotations are applied to both Service and Pod resources. You can generally specify the annotations intended for both Pods or Services here, and the ones that don't apply on either side will be ignored (i.e. if you put a Service annotation here, it'll also appear on Pod specs but will be safely ignored there, and vice versa).
Example:
spec.daemon
spec > daemon
Whether to run the service as a daemon (to ensure exactly one instance runs per node). May not be supported by all providers.
spec.sync
spec > sync
Specifies which files or directories to sync to which paths inside the running containers of the service when it's in sync mode, and overrides for the container command and/or arguments.
Sync is enabled e.g. by setting the --sync
flag on the garden deploy
command.
See the Code Synchronization guide for more information.
spec.sync.args[]
Override the default container arguments when in sync mode.
spec.sync.command[]
Override the default container command (i.e. entrypoint) when in sync mode.
spec.sync.paths[]
Specify one or more source files or directories to automatically sync with the running container.
spec.sync.paths[].source
Path to a local directory to be synchronized with the target. This should generally be a templated path to another action's source path (e.g. ${actions.build.my-container-image.sourcePath}
), or a relative path. If a path is hard-coded, we recommend sticking with relative paths here, and using forward slashes (/
) as a delimiter, as Windows-style paths with back slashes (\
) and absolute paths will work on some platforms, but they are not portable and will not work for users on other platforms. Defaults to the Deploy action's config's directory if no value is provided.
Example:
spec.sync.paths[].target
POSIX-style absolute path to sync to inside the container. The root path (i.e. "/") is not allowed.
Example:
spec.sync.paths[].exclude[]
Specify a list of POSIX-style paths or glob patterns that should be excluded from the sync.
.git
directories and .garden
directories are always ignored.
Example:
spec.sync.paths[].mode
The sync mode to use for the given paths. See the Code Synchronization guide for details.
spec.sync.paths[].defaultFileMode
spec > sync > paths > defaultFileMode
The default permission bits, specified as an octal, to set on files at the sync target. Defaults to 0o644 (user can read/write, everyone else can read). See the Mutagen docs for more information.
spec.sync.paths[].defaultDirectoryMode
spec > sync > paths > defaultDirectoryMode
The default permission bits, specified as an octal, to set on directories at the sync target. Defaults to 0o755 (user can read/write, everyone else can read). See the Mutagen docs for more information.
spec.sync.paths[].defaultOwner
spec > sync > paths > defaultOwner
Set the default owner of files and directories at the target. Specify either an integer ID or a string name. See the Mutagen docs for more information.
spec.sync.paths[].defaultGroup
spec > sync > paths > defaultGroup
Set the default group on files and directories at the target. Specify either an integer ID or a string name. See the Mutagen docs for more information.
spec.localMode
spec > localMode
[EXPERIMENTAL] Configures the local application which will send and receive network requests instead of the target resource.
The target service will be replaced by a proxy container which runs an SSH server to proxy requests. Reverse port-forwarding will be automatically configured to route traffic to the local service and back.
Local mode is enabled by setting the --local
option on the garden deploy
command. Local mode always takes the precedence over sync mode if there are any conflicting service names.
Health checks are disabled for services running in local mode.
See the Local Mode guide for more information.
Note! This feature is still experimental. Some incompatible changes can be made until the first non-experimental release.
spec.localMode.ports[]
The reverse port-forwards configuration for the local application.
spec.localMode.ports[].local
spec > localMode > ports > local
The local port to be used for reverse port-forward.
spec.localMode.ports[].remote
spec > localMode > ports > remote
The remote port to be used for reverse port-forward.