Skip to content

Commit

Permalink
tip: Writing scripts to known container path (#298)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
joshspicer and bamurtaugh authored Jan 24, 2024
1 parent 5d58bb7 commit f69998d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions _implementors/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,40 @@ If a Feature provides a given command with the [object syntax](/implementors/jso

> **Note**: These properties are stored within [image metadata](/implementors/spec/#merge-logic).
#### Writing scripts to known container path

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).

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.

##### install.sh
```bash
PULL_GIT_LFS_SCRIPT_PATH="/usr/local/share/pull-git-lfs-artifacts.sh"

tee "$PULL_GIT_LFS_SCRIPT_PATH" > /dev/null \
<< EOF
#!/bin/sh
set -e
<...truncated...>
EOF
```

This script is then executed during the [`postCreateCommand` lifecycle hook](https://github.com/devcontainers/features/blob/4fca96b5e8a4bfc93679098cb19d73c65ce571eb/src/git-lfs/devcontainer-feature.json#L23).

##### devcontainer-feature.json
```jsonc
{
"id": "git-lfs",
"version": "1.1.0",
"name": "Git Large File Support (LFS)",
// <...truncated...>
"postCreateCommand": "/usr/local/share/pull-git-lfs-artifacts.sh",
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
}
```

### <a href="#options-property" name="options-property" class="anchor"> The `options` property </a>

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:
Expand Down

0 comments on commit f69998d

Please sign in to comment.