You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To use the `devcontainer snippet` commands you need to enable experimental feaaures and configure some snippet folders.
12
10
13
-
A snippet folder can be as simple as a set of `.sh` scripts - examples can be found in the `snippets` folder of [stuartleeks/devcontainers](https://github.com/stuartleeks/devcontainers).
11
+
A snippet collection can be as simple as a set of `.sh` scripts. Good starting points for snippets are the `snippets` folder of [stuartleeks/devcontainers](https://github.com/stuartleeks/devcontainers) and [benc-uk/tools-install](https://github.com/benc-uk/tools-install/).
12
+
13
+
Choose a directory to put the snippets in, and clone the repos:
14
14
15
-
Choose a directory, and clone the repo using `git clone https://github.com/stuartleeks/devcontainers`
Next, we need to tell the `devcontainer` CLI to use this folder. If you haven't previously created a config file, run `devcontainer config write` to save a config file and then open `~/.devcontainer-cli/devcontainer-cli.json` in your favourite editor.
20
+
Next, we need to tell the `devcontainer` CLI to use these folders. If you haven't previously created a config file, run `devcontainer config write` to save a config file and then open `~/.devcontainer-cli/devcontainer-cli.json` in your favourite editor.
18
21
19
22
The starting configuration will look something like:
20
23
21
24
```json
22
25
{
23
-
"templatepaths": []
26
+
"templatepaths": []
24
27
}
25
28
```
26
29
27
-
Add an `experimental` setting with the value `true`to turn on experimental features, and add a `snippetpaths` setting with an array value containing the path to your snippet folder, e.g.:
30
+
Add a `snippetpaths` setting with an array value containing the path to your snippet folders. For example, if you cloned the repos into your `~/source` folder add the following to your config file:
NOTE: You also need to add the `experimental` setting with the value `true` as snippets are currently an experimental features
40
+
36
41
## Listing snippets
37
42
38
43
Running `devcontainer snippet list` will show the snippets that `devcontainer` discovered
39
44
40
45
## Adding a snippet
41
46
42
-
To add a snippet to the dev container definition to your project, change directory to the project folder (i.e. the one with the `.devcontainer` folder) and then run:
47
+
To add a snippet to the dev container definition to your project, change directory to the project folder (i.e. the one containing the `.devcontainer` folder) and then run:
This will copy in the snippet files for you to modify as you wish.
50
55
51
-
## Creating your own snippets **TODO**
56
+
## Creating your own snippets
57
+
58
+
`devcontainer` can be configured to scan multiple folders to find snippets. For each folder configured in the `snippetpaths` setting it searches for snippets. There are currently two types of snippet supported: single file snippets and folder-based snippets.
59
+
60
+
### Single file snippets
61
+
62
+
Single file snippets are `.sh` files that are copied to the `.devcontainer/scripts` folder and added to the `Dockerfile`. This is the simplest place to start when creating a snippet.
63
+
64
+
### Folder-based snippets
65
+
66
+
Folder-based snippets are folders containing a `snippet.json` file. The `snippet.json` describes the actions to take when applying the snippet, for example:
67
+
68
+
```json
69
+
{
70
+
"actions": [
71
+
{
72
+
"type" : "copyAndRun",
73
+
"source": "my-script.sh"
74
+
}
75
+
]
76
+
}
77
+
```
78
+
79
+
The `actions` property can contain multiple actions and they are applied in order.
80
+
81
+
The following action types are supported:
82
+
83
+
-`copyAndRun`
84
+
-`mergeJSON`
85
+
-`dockerfileSnippet`
86
+
87
+
#### copyAndRun action
88
+
89
+
The `copyAndRun` action provides the same capability as the single file snippet, i.e. the source file is copied and added to the `Dockerfile`.
90
+
91
+
The following properties are supported for a `copyAndRun` action:
| source | The path to the script file to copy (relative to the snippet.json) |
96
+
97
+
For example:
52
98
53
-
`devcontainer` can be configured to scan multiple folders to find snippets. For each folder configured in the `snippetpaths` setting it searches for `*.sh` files.
99
+
```json
100
+
{
101
+
"actions": [
102
+
{
103
+
"type": "copyAndRun",
104
+
"source": "golang.sh"
105
+
}
106
+
]
107
+
}
108
+
```
109
+
110
+
#### mergeJSON action
111
+
112
+
The `mergeJSON` action provides the ability to merge changes into a JSON file (e.g. `devcontainer.json`).
113
+
114
+
The following properties are supported for a `mergeJSON` action:
0 commit comments