Extensibility
Daytona is designed to be highly extensible through the use of plugins and providers. These features allow users to customize the functionality of Daytona to meet their specific needs.
Plugins
Plugins extend Daytona’s functionality by adding new commands and features. They can be written in Go and are loaded at runtime. Plugins are discovered and loaded based on their Plugin
interface. The Plugin
interface defines a single method: Run
which takes a Context
object. This Context
contains information about the current plugin environment, including access to the Daytona API and other plugin resources.
Here’s an example of a plugin structure:
package example
import (
"fmt"
"github.com/daytonaio/daytona/pkg/core/plugin"
"github.com/daytonaio/daytona/pkg/core/types"
)
type ExamplePlugin struct{}
func (e ExamplePlugin) Run(ctx plugin.Context) error {
// Access the Daytona API through the Context.
api := ctx.API()
// Get the current workspace.
workspace, err := api.GetWorkspace(ctx, "my-workspace")
if err != nil {
return err
}
// Example: Display workspace information.
fmt.Printf("Workspace Name: %s\n", workspace.Name)
// Access other plugin resources through the Context.
// Example: Get a list of registered providers.
providers := ctx.Providers()
// Do something with the providers.
fmt.Printf("Registered Providers: %v\n", providers)
return nil
}
func main() {
// Register the plugin with Daytona.
plugin.Register("example", ExamplePlugin{})
}
This example demonstrates how a plugin can access the Daytona API, get the current workspace, and get a list of registered providers.
Providers
Providers are responsible for managing the underlying infrastructure that Daytona uses. They are also written in Go and are registered with Daytona through the Provider
interface. The Provider
interface defines a set of methods for managing resources, including creating, starting, stopping, and deleting resources.
Here’s an example of a provider structure:
package example
import (
"context"
"github.com/daytonaio/daytona/pkg/core/provider"
"github.com/daytonaio/daytona/pkg/core/types"
)
type ExampleProvider struct{}
func (e ExampleProvider) Create(ctx context.Context, target types.ProviderTarget) error {
// Do something to create a resource on the target.
// ...
return nil
}
func (e ExampleProvider) Start(ctx context.Context, target types.ProviderTarget) error {
// Do something to start a resource on the target.
// ...
return nil
}
func (e ExampleProvider) Stop(ctx context.Context, target types.ProviderTarget) error {
// Do something to stop a resource on the target.
// ...
return nil
}
func (e ExampleProvider) Delete(ctx context.Context, target types.ProviderTarget) error {
// Do something to delete a resource on the target.
// ...
return nil
}
func main() {
// Register the provider with Daytona.
provider.Register("example", ExampleProvider{})
}
This example demonstrates how a provider can implement the Provider
interface and handle the creation, starting, stopping, and deleting of resources on a target.
Provider Targets
Provider targets are configurations that specify how a provider should manage resources. Each target is defined by a set of properties and values. Provider targets can be created and managed through the Daytona CLI.
Here’s an example of a provider target configuration:
name: "example-target"
provider: "example"
properties:
# Define properties for the target.
# ...
This example demonstrates how a provider target can be configured with a name, provider, and a set of properties.
Extending Daytona
Daytona’s extensibility through plugins and providers enables users to create custom workflows, add new integrations, and manage different types of resources. This flexibility makes Daytona a powerful tool for developers who need a customizable and efficient development environment manager.
Top-Level Directory Explanations
assets/ - Directory for storing static files such as images, stylesheets, and scripts.
assets/images/ - Subdirectory for storing project images.
internal/ - Private package directory for the project’s internal modules.
internal/util/ - Subdirectory for utility modules.
pkg/ - Go packages directory.
pkg/views/ - Subdirectory for view templates.
pkg/views/containerregistry/ - Subdirectory for container registry view templates.