You can synchronize your code (and other files) to and from running containers using dev mode.
Dev mode works similarly to the older hot reloading functionality, but is much faster and more reliable. It also supports bidirectional syncing, which enables you to sync new/changed files from your containers to your local machine.
This new sync mode uses Mutagen under the hood. Garden automatically takes care of fetching Mutagen, so you don't need to install any dependencies yourself to make use of dev mode.
Dev mode sync is not affected by includes/excludes, which makes it more flexible than hot reloading. For example, you can use it to sync your
dist directory into your container while running local, incremental builds (without having to remove those directories from your ignorefiles).
To configure a service for dev mode, add
devMode to your module/service configuration to specify your sync targets:
kind: Moduledescription: Node greeting servicename: node-servicetype: containerservices:- name: node-serviceargs: [npm, start]devMode:command: [npm, run, dev] # Overrides the container's default when the service is deployed in dev modesync:# Source/target configuration for dev mode is the same as for hot reloading.- target: /app# Make sure to specify any paths that should not be synced!exclude: [node_modules]# You can use several sync specs for the same service.- source: /tmp/somedirtarget: /somedir...
kind: Moduletype: kubernetes # this example looks the same for helm modules (i.e. with `type: helm`)name: node-service# For `kubernetes` and `helm` modules, the `devMode` field is located at the top level.devMode:command: [npm, run, dev]sync:- target: /app- source: /tmp/somedirtarget: /somedirserviceResource:kind: Deploymentname: node-service-deploymentcontainerModule: node-service-imagecontainerName: node-service...
To deploy your services with dev mode enabled, you can use the
# Deploy specific services in dev mode:garden deploy --dev myservicegarden deploy --dev myservice,my-other-service# Deploy all applicable services in dev mode:garden deploy --dev=*# The dev command deploys services in dev mode by default:garden dev myservice
In certain cases you may need to set a specific owner/group or permission bits on the synced files and directories at the target.
To do this, you can set a few options on each sync:
kind: Moduledescription: Node greeting servicename: node-servicetype: containerservices:- name: node-serviceargs: [npm, start]devMode:command: [npm, run, dev]sync:- target: /appexclude: [node_modules]defaultOwner: 1000 # <- set an integer user ID or a string namedefaultGroup: 1000 # <- set an integer group ID or a string namedefaultFileMode: 0666 # <- set the permission bits (as octals) for synced filesdefaultDirectoryMode: 0777 # <- set the permission bits (as octals) for synced directories...
These options are passed directly to Mutagen. For more information, please see the Mutagen docs.