README
¶
Package Purpose
The purpose of the docker
package is to provide a single library that providers can use to easily create workspaces and projects.
Most providers will import the package and call commands from the DockerClient
in order to create workspaces and projects on provided targets.
Usage
To use the Daytona DockerClient
, the consumer of the library must provide a Docker API client from github.com/docker/docker/client
.
Example:
import (
"github.com/docker/docker/client"
"github.com/daytonaio/daytona/pkg/docker"
)
func GetDockerClient() (docker.IDockerClient, error) {
client, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return nil, err
}
return docker.NewDockerClient(docker.DockerClientConfig{
ApiClient: client,
}), nil
}
Testing
To test changes made in this library, other than writing tests, we recommend using the library locally with the Docker provider.
The procedure would be as follows:
- Clone the Docker provider
- Open the
go.mod
file. - Add
replace github.com/daytonaio/daytona => <PATH_TO_DAYTONA_REPO>
- Run
go mod tidy
- Build the Docker provider and store it to your local provider directory.
go build -o <PATH_TO_PROVIDER_DIR>/docker-provider/docker-provider main.go
- If you're developing Daytona in a devcontainer,
<PATH_TO_PROVIDER_DIR> = ~/.config/daytona/providers
Note: Any change to the docker
library will require that providers update the version of github.com/daytonaio/daytona
after the next release and post a release of their own.
Documentation
¶
Index ¶
- Constants
- func GetContainerCreateConfig(project *project.Project) *container.Config
- type CreateDevcontainerOptions
- type CreateProjectOptions
- type DevcontainerPaths
- type DockerClient
- func (d *DockerClient) CreateFromDevcontainer(opts CreateDevcontainerOptions) (string, RemoteUser, error)
- func (d *DockerClient) CreateProject(opts *CreateProjectOptions) error
- func (d *DockerClient) CreateWorkspace(workspace *workspace.Workspace, workspaceDir string, logWriter io.Writer, ...) error
- func (d *DockerClient) DeleteImage(imageName string, force bool, logWriter io.Writer) error
- func (d *DockerClient) DestroyProject(project *project.Project, projectDir string, sshClient *ssh.Client) error
- func (d *DockerClient) DestroyWorkspace(workspace *workspace.Workspace, workspaceDir string, sshClient *ssh.Client) error
- func (d *DockerClient) ExecSync(containerID string, config container.ExecOptions, outputWriter io.Writer) (*ExecResult, error)
- func (d *DockerClient) GetContainerLogs(containerName string, logWriter io.Writer) error
- func (d *DockerClient) GetProjectContainerName(project *project.Project) string
- func (d *DockerClient) GetProjectInfo(p *project.Project) (*project.ProjectInfo, error)
- func (d *DockerClient) GetProjectVolumeName(project *project.Project) string
- func (d *DockerClient) GetWorkspaceInfo(ws *workspace.Workspace) (*workspace.WorkspaceInfo, error)
- func (d *DockerClient) PullImage(imageName string, cr *containerregistry.ContainerRegistry, logWriter io.Writer) error
- func (d *DockerClient) PushImage(imageName string, cr *containerregistry.ContainerRegistry, logWriter io.Writer) error
- func (d *DockerClient) RemoveContainer(containerName string) error
- func (d *DockerClient) StartProject(opts *CreateProjectOptions, daytonaDownloadUrl string) error
- func (d *DockerClient) StopProject(p *project.Project, logWriter io.Writer) error
- type DockerClientConfig
- type ExecResult
- type IDockerClient
- type RemoteUser
Constants ¶
const ContainerNotFoundMetadata = "{\"state\": \"container not found\"}"
const UPDATE_UID_GID_SCRIPT = `` /* 1140-byte string literal not displayed */
const WorkspaceMetadataFormat = "{\"networkId\": \"%s\"}"
Variables ¶
This section is empty.
Functions ¶
func GetContainerCreateConfig ¶
func GetContainerCreateConfig(project *project.Project) *container.Config
Types ¶
type CreateDevcontainerOptions ¶ added in v0.26.0
type CreateDevcontainerOptions struct {
ProjectDir string
// Name of the project inside the devcontainer
ProjectName string
BuildConfig *buildconfig.BuildConfig
LogWriter io.Writer
SshClient *ssh.Client
ContainerRegistry *containerregistry.ContainerRegistry
Prebuild bool
EnvVars map[string]string
IdLabels map[string]string
}
type CreateProjectOptions ¶ added in v0.21.0
type CreateProjectOptions struct {
Project *project.Project
ProjectDir string
Cr *containerregistry.ContainerRegistry
LogWriter io.Writer
Gpc *gitprovider.GitProviderConfig
SshClient *ssh.Client
}
type DevcontainerPaths ¶ added in v0.22.0
type DevcontainerPaths struct {
OverridesDir string
OverridesTarget string
ProjectTarget string
TargetConfigFilePath string
}
type DockerClient ¶
type DockerClient struct {
// contains filtered or unexported fields
}
func (*DockerClient) CreateFromDevcontainer ¶ added in v0.26.0
func (d *DockerClient) CreateFromDevcontainer(opts CreateDevcontainerOptions) (string, RemoteUser, error)
func (*DockerClient) CreateProject ¶
func (d *DockerClient) CreateProject(opts *CreateProjectOptions) error
func (*DockerClient) CreateWorkspace ¶
func (d *DockerClient) CreateWorkspace(workspace *workspace.Workspace, workspaceDir string, logWriter io.Writer, sshClient *ssh.Client) error
func (*DockerClient) DeleteImage ¶ added in v0.26.0
func (d *DockerClient) DeleteImage(imageName string, force bool, logWriter io.Writer) error
func (*DockerClient) DestroyProject ¶
func (d *DockerClient) DestroyProject(project *project.Project, projectDir string, sshClient *ssh.Client) error
func (*DockerClient) DestroyWorkspace ¶
func (d *DockerClient) DestroyWorkspace(workspace *workspace.Workspace, workspaceDir string, sshClient *ssh.Client) error
func (*DockerClient) ExecSync ¶
func (d *DockerClient) ExecSync(containerID string, config container.ExecOptions, outputWriter io.Writer) (*ExecResult, error)
func (*DockerClient) GetContainerLogs ¶
func (d *DockerClient) GetContainerLogs(containerName string, logWriter io.Writer) error
func (*DockerClient) GetProjectContainerName ¶
func (d *DockerClient) GetProjectContainerName(project *project.Project) string
func (*DockerClient) GetProjectInfo ¶
func (d *DockerClient) GetProjectInfo(p *project.Project) (*project.ProjectInfo, error)
func (*DockerClient) GetProjectVolumeName ¶ added in v0.17.0
func (d *DockerClient) GetProjectVolumeName(project *project.Project) string
func (*DockerClient) GetWorkspaceInfo ¶
func (d *DockerClient) GetWorkspaceInfo(ws *workspace.Workspace) (*workspace.WorkspaceInfo, error)
func (*DockerClient) PullImage ¶ added in v0.17.0
func (d *DockerClient) PullImage(imageName string, cr *containerregistry.ContainerRegistry, logWriter io.Writer) error
func (*DockerClient) PushImage ¶ added in v0.17.0
func (d *DockerClient) PushImage(imageName string, cr *containerregistry.ContainerRegistry, logWriter io.Writer) error
func (*DockerClient) RemoveContainer ¶ added in v0.26.0
func (d *DockerClient) RemoveContainer(containerName string) error
func (*DockerClient) StartProject ¶
func (d *DockerClient) StartProject(opts *CreateProjectOptions, daytonaDownloadUrl string) error
func (*DockerClient) StopProject ¶
func (d *DockerClient) StopProject(p *project.Project, logWriter io.Writer) error
type DockerClientConfig ¶
type DockerClientConfig struct {
ApiClient client.APIClient
}
type ExecResult ¶
type ExecResult struct {
StdOut string
StdErr string
ExitCode int
}
type IDockerClient ¶
type IDockerClient interface {
CreateProject(opts *CreateProjectOptions) error
CreateWorkspace(workspace *workspace.Workspace, workspaceDir string, logWriter io.Writer, sshClient *ssh.Client) error
DestroyProject(project *project.Project, projectDir string, sshClient *ssh.Client) error
DestroyWorkspace(workspace *workspace.Workspace, workspaceDir string, sshClient *ssh.Client) error
StartProject(opts *CreateProjectOptions, daytonaDownloadUrl string) error
StopProject(project *project.Project, logWriter io.Writer) error
GetProjectInfo(project *project.Project) (*project.ProjectInfo, error)
GetWorkspaceInfo(ws *workspace.Workspace) (*workspace.WorkspaceInfo, error)
GetProjectContainerName(project *project.Project) string
GetProjectVolumeName(project *project.Project) string
ExecSync(containerID string, config container.ExecOptions, outputWriter io.Writer) (*ExecResult, error)
GetContainerLogs(containerName string, logWriter io.Writer) error
PullImage(imageName string, cr *containerregistry.ContainerRegistry, logWriter io.Writer) error
PushImage(imageName string, cr *containerregistry.ContainerRegistry, logWriter io.Writer) error
DeleteImage(imageName string, force bool, logWriter io.Writer) error
CreateFromDevcontainer(opts CreateDevcontainerOptions) (string, RemoteUser, error)
RemoveContainer(containerName string) error
}
func NewDockerClient ¶
func NewDockerClient(config DockerClientConfig) IDockerClient
type RemoteUser ¶ added in v0.21.0
type RemoteUser string