Skip to content

Commit f69998d

Browse files
tip: Writing scripts to known container path (devcontainers#298)
* tip: Writing scripts to known container path * Update _implementors/features.md Co-authored-by: Brigit Murtaugh <[email protected]> * Update _implementors/features.md Co-authored-by: Brigit Murtaugh <[email protected]> --------- Co-authored-by: Brigit Murtaugh <[email protected]>
1 parent 5d58bb7 commit f69998d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

_implementors/features.md

+34
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,40 @@ If a Feature provides a given command with the [object syntax](/implementors/jso
8282

8383
> **Note**: These properties are stored within [image metadata](/implementors/spec/#merge-logic).
8484
85+
#### Writing scripts to known container path
86+
87+
It may be helpful for a Feature to write scripts to a known, persistent path within the container (i.e. for later use in a given lifecycle hook).
88+
89+
Take for instance the `git-lfs` Feature, which [writes a script](https://github.com/devcontainers/features/blob/4fca96b5e8a4bfc93679098cb19d73c65ce571eb/src/git-lfs/install.sh#L190-L216) to `/usr/local/share/pull-git-lfs-artifacts.sh` during installation.
90+
91+
##### install.sh
92+
```bash
93+
PULL_GIT_LFS_SCRIPT_PATH="/usr/local/share/pull-git-lfs-artifacts.sh"
94+
95+
tee "$PULL_GIT_LFS_SCRIPT_PATH" > /dev/null \
96+
<< EOF
97+
#!/bin/sh
98+
set -e
99+
<...truncated...>
100+
EOF
101+
```
102+
103+
This script is then executed during the [`postCreateCommand` lifecycle hook](https://github.com/devcontainers/features/blob/4fca96b5e8a4bfc93679098cb19d73c65ce571eb/src/git-lfs/devcontainer-feature.json#L23).
104+
105+
##### devcontainer-feature.json
106+
```jsonc
107+
{
108+
"id": "git-lfs",
109+
"version": "1.1.0",
110+
"name": "Git Large File Support (LFS)",
111+
// <...truncated...>
112+
"postCreateCommand": "/usr/local/share/pull-git-lfs-artifacts.sh",
113+
"installsAfter": [
114+
"ghcr.io/devcontainers/features/common-utils"
115+
]
116+
}
117+
```
118+
85119
### <a href="#options-property" name="options-property" class="anchor"> The `options` property </a>
86120

87121
The options property contains a map of option IDs and their related configuration settings. The ID becomes the name of the environment variable in all caps. See [option resolution](#option-resolution) for more details. For example:

0 commit comments

Comments
 (0)