docker

package
v0.52.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 40 Imported by: 7

README

Package Purpose

The purpose of the docker package is to provide a single library that providers can use to easily create targets and workspaces. Most providers will import the package and call commands from the DockerClient in order to create targets and workspaces 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:

  1. Clone the Docker provider
  2. Open the go.mod file.
  3. Add replace github.com/daytonaio/daytona => <PATH_TO_DAYTONA_REPO>
  4. Run go mod tidy
  5. 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

View Source
const UPDATE_UID_GID_SCRIPT = `` /* 1140-byte string literal not displayed */

Variables

This section is empty.

Functions

func GetContainerCreateConfig

func GetContainerCreateConfig(workspace *models.Workspace, toolboxApiHostPort *uint16) *container.Config

Types

type CreateDevcontainerOptions added in v0.26.0

type CreateDevcontainerOptions struct {
	WorkspaceDir string
	// Name of the project inside the devcontainer
	WorkspaceFolderName string
	BuildConfig         *models.BuildConfig
	LogWriter           io.Writer
	SshClient           *ssh.Client
	ContainerRegistries common.ContainerRegistries
	Prebuild            bool
	EnvVars             map[string]string
	IdLabels            map[string]string
	BuilderImage        string
}

type CreateWorkspaceOptions added in v0.52.0

type CreateWorkspaceOptions struct {
	Workspace           *models.Workspace
	WorkspaceDir        string
	ContainerRegistries common.ContainerRegistries
	LogWriter           io.Writer
	Gpc                 *models.GitProviderConfig
	SshClient           *ssh.Client
	BuilderImage        string
}

type DevcontainerPaths added in v0.22.0

type DevcontainerPaths struct {
	OverridesDir         string
	OverridesTarget      string
	WorkspaceDirTarget   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) CreateTarget added in v0.52.0

func (d *DockerClient) CreateTarget(target *models.Target, targetDir string, logWriter io.Writer, sshClient *ssh.Client) error

func (*DockerClient) CreateWorkspace

func (d *DockerClient) CreateWorkspace(opts *CreateWorkspaceOptions) error

func (*DockerClient) DeleteImage added in v0.26.0

func (d *DockerClient) DeleteImage(imageName string, force bool, logWriter io.Writer) error

func (*DockerClient) DestroyTarget added in v0.52.0

func (d *DockerClient) DestroyTarget(target *models.Target, targetDir string, sshClient *ssh.Client) error

func (*DockerClient) DestroyWorkspace

func (d *DockerClient) DestroyWorkspace(workspace *models.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) GetTargetProviderMetadata added in v0.52.0

func (d *DockerClient) GetTargetProviderMetadata(t *models.Target) (string, error)

func (*DockerClient) GetWorkspaceContainerName added in v0.52.0

func (d *DockerClient) GetWorkspaceContainerName(workspace *models.Workspace) string

func (*DockerClient) GetWorkspaceProviderMetadata added in v0.52.0

func (d *DockerClient) GetWorkspaceProviderMetadata(w *models.Workspace) (string, error)

func (*DockerClient) GetWorkspaceVolumeName added in v0.52.0

func (d *DockerClient) GetWorkspaceVolumeName(workspace *models.Workspace) string

func (*DockerClient) PullImage added in v0.17.0

func (d *DockerClient) PullImage(imageName string, cr *models.ContainerRegistry, logWriter io.Writer) error

func (*DockerClient) PushImage added in v0.17.0

func (d *DockerClient) PushImage(imageName string, cr *models.ContainerRegistry, logWriter io.Writer) error

func (*DockerClient) RemoveContainer added in v0.26.0

func (d *DockerClient) RemoveContainer(containerName string) error

func (*DockerClient) StartWorkspace added in v0.52.0

func (d *DockerClient) StartWorkspace(opts *CreateWorkspaceOptions, daytonaDownloadUrl string) error

func (*DockerClient) StopWorkspace added in v0.52.0

func (d *DockerClient) StopWorkspace(w *models.Workspace, logWriter io.Writer) error

type DockerClientConfig

type DockerClientConfig struct {
	ApiClient client.APIClient
}

type DockerCredHelper added in v0.52.0

type DockerCredHelper struct {
	DockerConfigFileName string
	LogWriter            io.Writer
	HomeDir              string
}

func (*DockerCredHelper) SetDockerConfig added in v0.52.0

func (d *DockerCredHelper) SetDockerConfig() error

type ExecResult

type ExecResult struct {
	StdOut   string
	StdErr   string
	ExitCode int
}

type FeatureItem added in v0.32.0

type FeatureItem struct {
	ID         string `json:"id"`
	Entrypoint string `json:"entrypoint,omitempty"`
}

type IDockerClient

type IDockerClient interface {
	CreateWorkspace(opts *CreateWorkspaceOptions) error
	CreateTarget(target *models.Target, targetDir string, logWriter io.Writer, sshClient *ssh.Client) error

	DestroyWorkspace(workspace *models.Workspace, workspaceDir string, sshClient *ssh.Client) error
	DestroyTarget(target *models.Target, targetDir string, sshClient *ssh.Client) error

	StartWorkspace(opts *CreateWorkspaceOptions, daytonaDownloadUrl string) error
	StopWorkspace(workspace *models.Workspace, logWriter io.Writer) error

	GetWorkspaceProviderMetadata(workspace *models.Workspace) (string, error)
	GetTargetProviderMetadata(t *models.Target) (string, error)

	GetWorkspaceContainerName(workspace *models.Workspace) string
	GetWorkspaceVolumeName(workspace *models.Workspace) string
	ExecSync(containerID string, config container.ExecOptions, outputWriter io.Writer) (*ExecResult, error)
	GetContainerLogs(containerName string, logWriter io.Writer) error
	PullImage(imageName string, cr *models.ContainerRegistry, logWriter io.Writer) error
	PushImage(imageName string, cr *models.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 IDockerCredHelper added in v0.52.0

type IDockerCredHelper interface {
	SetDockerConfig() error
}

type RemoteUser added in v0.21.0

type RemoteUser string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL