Hooks: distinguish sync
The documentation states...
start:sync:[name], stop:sync:[name], error:sync:[name], restart:sync:[name], before:initialSync:[name], after:initialSync:[name], error:initialSync:[name]:executed while DevSpace syncs files with dev.sync.[name]can be replaced with the config name of a sync configuration or * to match all.
However, I do not see a way to a specify a name in the file sync config.
Having more than one dev.app.sync[] entry the "before:initialSync:*" hook is started for each entry, but I do not see a way to detect the sync entry for which a specific hook call is executed.
Hello! The [name] part refers to the name of the dev configuration, so for your dev.app.sync configuration, you should be able to target that specific one with before:initialSync:app.
The sync configuration is available in the environment variable DEVSPACE_HOOK_SYNC_CONFIG. It looks like the value will be a JSON parsable string.
I do not find a DEVSPACE_HOOK_SYNC_CONFIG environment variable in my hook (or any `DEVSPACE_HOOK_*``).
Tested with hook command: "env | sort"
DevSpace version : 6.3.14
Edit: same with DevSpace version : 6.3.15
I tried the following hooks config in devspace.yaml
hooks:
- events: ["before:initialSync:app"]
command: "env | sort"
And it shows the $DEVSPACE_HOOK_SYNC_CONFIG environment variable in the output:
dev:app sync Execute hook 'env | sort' at before:initialSync:*
dev:app sync COMMAND_MODE=unix2003
dev:app sync DEVSPACE_CONTEXT=kind-dual
dev:app sync DEVSPACE_EXECUTABLE=/opt/homebrew/bin/devspace
dev:app sync DEVSPACE_HOOK_EVENT=before:initialSync:*
dev:app sync DEVSPACE_HOOK_KUBE_CONTEXT=kind-dual
dev:app sync DEVSPACE_HOOK_KUBE_NAMESPACE=russ
dev:app sync DEVSPACE_HOOK_OS_ARGS=["devspace","dev","-n","russ"]
dev:app sync DEVSPACE_HOOK_SYNC_CONFIG={"path":"./:/app","startContainer":true,"disableDownload":true}
dev:app sync DEVSPACE_KUBECTL_EXECUTABLE=kubectl
dev:app sync DEVSPACE_NAME=timeout
dev:app sync DEVSPACE_NAMESPACE=russ
dev:app sync DEVSPACE_PROFILE=
dev:app sync DEVSPACE_PROFILES=
dev:app sync DEVSPACE_RANDOM=KeRHCn
dev:app sync DEVSPACE_SPACE=russ
dev:app sync DEVSPACE_TIMESTAMP=1751037902
dev:app sync DEVSPACE_TMPDIR=/var/folders/3k/f2wz_n393392ky9z0999d4bm0000gn/T/devspace-1784488974
dev:app sync DEVSPACE_USER_HOME=/Users/russellcentanni
dev:app sync DEVSPACE_VERSION=6.3.15
There's not currently a way to attach a hook to an individual dev.app.sync[] entry, but there is an onUpload option to execute a command when a file is uploaded to the container. onUpload might be another approach, but if not, share more about your use case and we'll try to help.
The Devspace project currently lacks enough contributors to adequately respond to all issues. Since there hasn't been a response. the issue is closed. You can re-open this issue if you still want help.