|
| 1 | +--- |
| 2 | +title: Samples |
| 3 | +description: Learn how to create and manage samples in Daytona. |
| 4 | +sidebar: |
| 5 | + label: Samples |
| 6 | +--- |
| 7 | + |
| 8 | +import Keyboard from "../../../components/Keyboard.astro" |
| 9 | +import Label from '@components/Label.astro' |
| 10 | + |
| 11 | +<Label> |
| 12 | + Distribution: **Open Source**, **Cloud**, **Self-Managed** |
| 13 | +</Label> |
| 14 | + |
| 15 | +Samples are quick-start repositories with predefined development configurations, environments, and dependencies used to create Workspaces. |
| 16 | + |
| 17 | +## Custom Samples |
| 18 | + |
| 19 | +Daytona provides an option to use custom Samples to create Workspaces. Creating custom Samples is a two-step process that involves: |
| 20 | + |
| 21 | +- [**Sample Repository**](#sample-repository) |
| 22 | + |
| 23 | + A repository containing the Sample code and a `devcontainer.json` file defining the development environment. |
| 24 | + |
| 25 | +- [**Samples Index**](#samples-index) |
| 26 | + |
| 27 | + Samples Index (`index.json`) file serving as a registry of available Samples for creating Workspaces. |
| 28 | + |
| 29 | +### Sample Repository |
| 30 | + |
| 31 | +Custom Sample repository is a Git repository that contains the Sample code and a `devcontainer.json` file that defines the development environment. The repository serves as the core content of the Sample and is used to create a Workspace. |
| 32 | + |
| 33 | +1. Create a repository representing the custom Sample. |
| 34 | + |
| 35 | +2. Define the custom Sample code, development configurations and dependencies. |
| 36 | + |
| 37 | +3. Create a **`devcontainer.json`** file that defines the development environment. |
| 38 | + |
| 39 | +- Use the [development container standard](https://containers.dev/) to define your development environment. Development containers vary based on the programming language, configurations, and tools used within the Sample. |
| 40 | + |
| 41 | +Example of a **`devcontainer.json`** file for development environment using Go programming language: |
| 42 | + |
| 43 | +```json |
| 44 | +{ |
| 45 | + "name": "Go", |
| 46 | + "image": "mcr.microsoft.com/devcontainers/go:1-1.21-bookworm", |
| 47 | + "customizations": { |
| 48 | + "vscode": { |
| 49 | + "extensions": [ |
| 50 | + "golang.Go" |
| 51 | + ] |
| 52 | + } |
| 53 | + }, |
| 54 | + "postCreateCommand": "go test -v" |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +4. Host the Sample repository on a Git repository or another platform. |
| 59 | + |
| 60 | +5. Add Sample properties to the [Samples Index](#samples-index). |
| 61 | + |
| 62 | +Sample will be used to create a Workspace by cloning the repository and using the `devcontainer.json` file to define the development environment. |
| 63 | + |
| 64 | +### Samples Index |
| 65 | + |
| 66 | +Samples require a Sample Index (`index.json`) file that serves as a registry of available Samples for creating Workspaces. The Samples Index is used to display the available Samples when creating a Workspace. |
| 67 | + |
| 68 | +1. Create an **`index.json`** file representing the Samples Index. |
| 69 | + |
| 70 | +2. Define an array of JSON objects representing the Samples. |
| 71 | + |
| 72 | + Each JSON object in the array represents a Sample: |
| 73 | + |
| 74 | +```json |
| 75 | +[ |
| 76 | + { |
| 77 | + "name": "My Custom Sample", |
| 78 | + "description": "My custom Samples description", |
| 79 | + "gitUrl": "https://github.com/<username>/<repository>" |
| 80 | + } |
| 81 | +] |
| 82 | +``` |
| 83 | + |
| 84 | +- **`name`** |
| 85 | + |
| 86 | + Name of the Sample. |
| 87 | + |
| 88 | +- **`gitUrl`** |
| 89 | + |
| 90 | + Link to the publicly available Sample repository. |
| 91 | + |
| 92 | +3. Host the **`index.json`** file publicly on a Git repository or another platform. |
| 93 | + |
| 94 | +4. Run the following command to configure the Samples Index URL: |
| 95 | + |
| 96 | +```sh |
| 97 | +daytona server configure |
| 98 | +``` |
| 99 | + |
| 100 | +5. Enter the public raw URL of the **`index.json`** file in the **`Samples Index URL`** field. |
| 101 | + |
| 102 | +```text |
| 103 | +Samples Index URL |
| 104 | +Leave empty to disable samples |
| 105 | +https://raw.githubusercontent.com/<username>/<repository>/<path>/index.json |
| 106 | +``` |
| 107 | + |
| 108 | +```text |
| 109 | +Server configuration updated. You need to restart the server for the changes to take effect. |
| 110 | +``` |
| 111 | + |
| 112 | +6. Restart the Daytona server to apply the changes. |
| 113 | + |
| 114 | +```sh |
| 115 | +daytona server restart |
| 116 | +``` |
| 117 | + |
| 118 | +Custom Samples will be available available when creating a Workspace. The chosen Sample will be cloned and used to create the Workspace. |
| 119 | + |
| 120 | +## Daytona Samples |
| 121 | + |
| 122 | +Daytona provides a collection of default Samples with predefined development configurations, environments, and dependencies. Daytona Samples are available to choose from when [creating a Workspace](/usage/workspaces#create-a-workspace). |
| 123 | + |
| 124 | +Daytona Samples are integrated via a Samples Index (`index.json`) file that serves as a registry of available Daytona Samples for creating Workspaces. |
| 125 | + |
| 126 | +The chosen Sample will be cloned and used to create the Workspace. The Daytona Sample repository will serve as the core content of the Sample used to create a Workspace. |
| 127 | + |
| 128 | +View the list of available Daytona Samples in the [Samples Index](https://github.com/daytonaio/daytona/blob/main/hack/samples/index.json). |
| 129 | + |
| 130 | +:::tip |
| 131 | +You can contribute to the Daytona Samples by suggesting new Samples to be added to the [Daytona Samples Index](https://github.com/daytonaio/daytona/blob/main/hack/samples/index.json). |
| 132 | +::: |
0 commit comments