Skip to content

Commit b0567c2

Browse files
authored
Update templates-distribution.md (#152)
1 parent a43650b commit b0567c2

File tree

1 file changed

+63
-5
lines changed

1 file changed

+63
-5
lines changed

_implementors/templates-distribution.md

+63-5
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,13 @@ Tooling that handles publishing Templates will not republish Templates if that e
6464

6565
## <a href="#packaging" name="packaging" class="anchor"> Packaging </a>
6666

67-
6867
Templates are distributed as tarballs. The tarball contains the entire contents of the Template sub-directory, including the `devcontainer-template.json`, `.devcontainer.json` (or `.devcontainer/devcontainer.json`), and any other files in the directory.
6968

7069
The tarball is named `devcontainer-template-<id>.tgz`, where `<id>` is the Templates's `id` field.
7170

7271
A reference implementation for packaging and distributing Templates is provided as a GitHub Action (https://github.com/devcontainers/action).
7372

74-
75-
<div id="devcontainer-collection.json"></div>
76-
### devcontainer-collection.json
73+
### <a href="#devcontainer-collection" name="devcontainer-collection" class="anchor"> devcontainer-collection.json </a>
7774

7875
The `devcontainer-collection.json` is an auto-generated metadata file.
7976

@@ -133,4 +130,65 @@ NAMESPACE=devcontainers/templates
133130
oras push ${REGISTRY}/${NAMESPACE}:latest \
134131
--manifest-config /dev/null:application/vnd.devcontainers \
135132
./devcontainer-collection.json:application/vnd.devcontainers.collection.layer.v1+json
136-
```
133+
```
134+
135+
## <a href="#guide-to-publishing-templates" name="guide-to-publishing-templates" class="anchor">Guide to publishing Templates</a>
136+
137+
The dev container CLI can be used to publish [Dev Container Template](https://containers.dev/implementors/templates/) artifacts to an OCI registry (that supports the [artifacts specification](https://oras.land/implementors/)).
138+
139+
To see all the available options, run `devcontainers templates publish --help`.
140+
141+
## <a href="#example" name="example" class="anchor">Example</a>
142+
143+
Given a directory that is organized according to the [Templates distribution specification](https://containers.dev/implementors/templates-distribution/) - for example:
144+
145+
```
146+
├── src
147+
│ ├── color
148+
│ │ ├── devcontainer-template.json
149+
│ │ └──| .devcontainer
150+
│ │ └── devcontainer.json
151+
│ ├── hello
152+
│ │ ├── devcontainer-template.json
153+
│ │ └──| .devcontainer
154+
│ │ ├── devcontainer.json
155+
│ │ └── Dockerfile
156+
| ├── ...
157+
│ │ ├── devcontainer-template.json
158+
│ │ └──| .devcontainer
159+
│ │ └── devcontainer.json
160+
├── test
161+
│ ├── color
162+
│ │ └── test.sh
163+
│ ├── hello
164+
│ │ └── test.sh
165+
│ └──test-utils
166+
│ └── test-utils.sh
167+
...
168+
```
169+
170+
The following command will publish each Template above (`color,hello`) to the registry `ghcr.io` with the following namespace (prefix) `devcontainers/templates`.
171+
172+
```
173+
[/tmp]$ GITHUB_TOKEN="$CR_PAT" devcontainer templates publish -r ghcr.io -n devcontainers/templates ./src
174+
```
175+
176+
To later apply a published Template (in the example below, the `color` template) with the CLI, the following `apply` command would be used:
177+
178+
```
179+
[/tmp]$ devcontainer templates apply \
180+
-t 'ghcr.io/devcontainers/templates/color' \
181+
-a '{"favorite": "red"}'
182+
```
183+
184+
### <a href="#authentication-methods" name="authentication-methods" class="anchor">Authentication Methods</a>
185+
186+
> NOTE: OS-specific docker credential helpers (Docker Desktop credential helper) are not currently recognized by the CLI.
187+
- Adding a $HOME/.docker/config.json with your credentials following [this commonly defined format](https://www.systutorials.com/docs/linux/man/5-docker-config-json/).
188+
- Your `docker login` command may write this file for you depending on your operating system.
189+
- Using our custom env variable DEVCONTAINERS_OCI_AUTH
190+
- eg: `DEVCONTAINERS_OCI_AUTH=service1|user1|token1,service2|user2|token2`
191+
192+
For publishing to `ghcr.io`
193+
- Using the `devcontainers/action` GitHub action to handle the `GITHUB_TOKEN` credential for you.
194+
- Providing a GITHUB_TOKEN with permission to `write:packages`.

0 commit comments

Comments
 (0)