This page discusses how to set up file sync for files that don’t require full rebuild.
NoteFile sync is alpha and may change between releases.
Skaffold supports copying changed files to a deployed container so as to avoid the need to rebuild, redeploy, and restart the corresponding pod.
The file copying is enabled by adding a
sync section with sync rules to the
artifact in the
Under the hood, Skaffold creates a tar file with changed files that match the sync rules.
This tar file is sent to and extracted on the corresponding containers.
Manual sync mode
A manual sync rule must specify the
src field is a glob pattern to match files relative to the artifact context directory, which may contain
** to match nested files.
dest field is the absolute or relative destination path in the container.
If the destination is a relative path, an absolute path will be inferred by prepending the path with the container’s
By default, matched files are transplanted with their whole directory hierarchy below the artifact context directory onto the destination.
strip field can cut off some levels from the directory hierarchy.
The following example showcases manual filesync:
build: artifacts: - image: gcr.io/k8s-skaffold/node-example context: node sync: manual: # sync a single file into the `/etc` folder - src: '.filebaserc' dest: /etc # sync files directly below `static-html` into `static/` - src: 'static-html/*.html' dest: static # sync any `png` file into the assets folder - src: '**/*.png' dest: assets # sync all `md` files from `content/en` into `content` - src: 'content/en/**/*.md' dest: content strip: 'content/en/'
- The first rule synchronizes the file
/etcfolder in the container.
- The second rule synchronizes all
htmlfiles in the
static-htmlfolder into the
<WORKDIR>/staticfolder in the container. Note that this pattern does not match files in sub-folders below
- The third rule synchronizes all
pngfiles from any sub-folder into the
assetsfolder on the container. For example,
- The last rule synchronizes all
mdfiles below the
content/endirectory into the
contentfolder on the container. The
stripdirective ensures that only the directory hierarchy below
content/enis re-created at the destination. For example,
Currently, there is only manual filesync mode, but a mode with destination inference is already in the making.
File sync has some limitations:
- File sync can only update files that can be modified by the container’s configured User ID.
- File sync requires the
tarcommand to be available in the container.
- Only local source files can be synchronized: files created by the builder will not be copied.