Is there a way to access workspace files during feature execution? #404
-
I am trying something like this: {
"name": "exercice2-go",
"image": "mcr.microsoft.com/devcontainers/go:1-1.21-bullseye",
"features": {
"ghcr.io/nikaro/features/ansible:1": {
"dependencies": "-r ${containerWorkspaceFolder}/deploy/requirements.txt"
}
}
} The feature uses the if [ -n "${DEPENDENCIES:-}" ]; then
# ensure packages are separated by spaces
DEPENDENCIES=$(printf '%s' "$DEPENDENCIES" | tr ',' ' ')
"${VENV_PATH}/bin/pip" install $DEPENDENCIES
fi And it fails with this error:
Is it possible to do something like that in some way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Yes, you can access workspace files during the execution of a Dev Container Feature. However, the timing of when the Feature scripts are run in relation to when the workspace files are mounted can affect this. In a Dev Container, the workspace files are mounted into the container at the path specified by the Feature scripts are run after the Docker image is built but before the workspace files are mounted. This means that if you try to access workspace files in a feature script, they might not be available yet. To work around this, you can use a Looping in @joshspicer, feel free to correct my understanding if necessary. |
Beta Was this translation helpful? Give feedback.
That's true that lifecycle hooks don't have access to Feature arguments - that sounds like a helpful feature request, and would be useful in this scenario.
One way I can think to do this today is similar to how the
git-lfs
Feature works, writing the lifecycle hook script in theinstall.sh
and injecting the relevant Feature's options. That script is then run as a postCreate hook once the filesystem is mounted.Note the usage of both
EOF
and'EOF'
to control when variables are substituted or not (https://unix.stackexchange.com/questions/138418/passing-a-variable-to-a-bash-script-that-uses-eof-and-considers-the-variable-a)