dockerimg

package
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

README

Docker Containers

Why!?!

To support multiple Sketch sessions in parallel, and to give the sessions isolation, each Sketch session runs in its own container. (At the end of the day, the output of a Sketch session is new git commit(s).)

Customization

Customizing Sketch's containers

By default, Sketch uses a Docker container generated by https://github.com/boldsoftware/sketch/blob/main/dockerimg/Dockerfile.base and published to https://github.com/boldsoftware/sketch/pkgs/container/sketch. This container is based on Ubuntu 24.04 and contains many popular tools. Sketch will install additional tools as it needs.

Locally, Sketch creates a container image based on the default that includes your working tree. This image is cached (identified by a container label that is a hash of your working tree directory and the base image id) to speed up starting up Sketch. (Future invocations do a "git reset" inside the image, but don't need to copy over the whole git repo.) You can force re-creation with the -force-rebuild-container flag.

If you'd like to customize the container, specify -base-image and point Sketch to an image you've built. We recommend layering your customizations on top of our base image, but this is not strictly necessary. Sketch will then add your repo on top of it, at runtime.

Docker Container Visualization

For example, if you want to add Node 22, you might create a Dockerfile like below, and build it with docker build -t sketch-with-node-22 - < Dockerfile.sketch, and pass it to sketch with -base-image sketch-with-node-22.

FROM ghcr.io/boldsoftware/sketch:latest

RUN apt-get update && \
    apt-get install -y curl && \
    curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
    apt-get install -y nodejs && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

Troubleshooting

"no space left on device"

docker system prune -a removes stopped containers and unused images, which usually frees up significant disk space.

Documentation

Overview

Package dockerimg

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckForIncludeWithFS

func CheckForIncludeWithFS(fs FileSystem, stdinReader bufio.Reader) error

func CheckSSHReachability

func CheckSSHReachability(cntrName string) error

CheckSSHReachability checks if the user's SSH config includes the Sketch SSH config file

func DefaultImage

func DefaultImage() (name, dockerfile, tag string)

DefaultImage is intended to ONLY be used by the pushdockerimg.go script.

func LaunchContainer

func LaunchContainer(ctx context.Context, config ContainerConfig) error

LaunchContainer creates a docker container for a project, installs sketch and opens a connection to it. It writes status to stdout.

Types

type ContainerConfig

type ContainerConfig struct {
	// SessionID is the unique identifier for this session
	SessionID string

	// LocalAddr is the initial address to use (though it may be overwritten later)
	LocalAddr string

	// SkabandAddr is the address of the skaband service if available
	SkabandAddr string

	// Model is the name of the LLM model to use.
	Model string

	// ModelURL is the URL of the LLM service.
	ModelURL string

	// OAIModelName is the openai model name of the LLM model to use.
	OAIModelName string

	// ModelAPIKey is the API key for LLM service.
	ModelAPIKey string

	// Path is the local filesystem path to use
	Path string

	// GitUsername is the username to use for git operations
	GitUsername string

	// GitEmail is the email to use for git operations
	GitEmail string

	// OpenBrowser determines whether to open a browser automatically
	OpenBrowser bool

	// NoCleanup prevents container cleanup when set to true
	NoCleanup bool

	// ForceRebuild forces rebuilding of the Docker image even if it exists
	ForceRebuild bool

	// BaseImage is the base Docker image to use for layering the repo
	BaseImage string

	// Host directory to copy container logs into, if not set to ""
	ContainerLogDest string

	// Path to pre-built linux sketch binary, or build a new one if set to ""
	SketchBinaryLinux string

	// Sketch client public key.
	SketchPubKey string

	// Host port for the container's ssh server
	SSHPort int

	// Outside information to pass to the container
	OutsideHostname   string
	OutsideOS         string
	OutsideWorkingDir string

	// If true, exit after the first turn
	OneShot bool

	// Initial prompt
	Prompt string

	// Verbose enables verbose output
	Verbose bool

	// DockerArgs are additional arguments to pass to the docker create command
	DockerArgs string

	// Mounts specifies volumes to mount in the container in format /path/on/host:/path/in/container
	Mounts []string

	// ExperimentFlag contains the experimental features to enable
	ExperimentFlag string

	// TermUI enables terminal UI
	TermUI bool

	// Budget configuration
	MaxDollars float64

	GitRemoteUrl string

	// Original git origin URL from the host repository
	OriginalGitOrigin string

	// Upstream branch for git work
	Upstream string

	// Commit hash to checkout from GetRemoteUrl
	Commit string

	// Outtie's HTTP server
	OutsideHTTP string

	// Prefix for git branches created by sketch
	BranchPrefix string

	// LinkToGitHub enables GitHub branch linking in UI
	LinkToGitHub bool

	// SubtraceToken enables running sketch under subtrace.dev (development only)
	SubtraceToken string

	// MCPServers contains MCP server configurations
	MCPServers []string

	// PassthroughUpstream configures upstream remote for passthrough to innie
	PassthroughUpstream bool

	// DumpLLM requests dumping of raw communications with LLM services to files
	DumpLLM bool

	// FetchOnLaunch enables git fetch during initialization
	FetchOnLaunch bool
}

ContainerConfig holds all configuration for launching a container

type FileSystem

type FileSystem interface {
	Stat(name string) (fs.FileInfo, error)
	Mkdir(name string, perm fs.FileMode) error
	MkdirAll(name string, perm fs.FileMode) error
	ReadFile(name string) ([]byte, error)
	WriteFile(name string, data []byte, perm fs.FileMode) error
	OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error)
	TempFile(dir, pattern string) (*os.File, error)
	Rename(oldpath, newpath string) error
	SafeWriteFile(name string, data []byte, perm fs.FileMode) error
}

FileSystem represents a filesystem interface for testability

type KeyGenerator

type KeyGenerator interface {
	GenerateKeyPair() (ed25519.PrivateKey, ed25519.PublicKey, error)
	ConvertToSSHPublicKey(publicKey ed25519.PublicKey) (ssh.PublicKey, error)
}

KeyGenerator represents an interface for generating SSH keys for testability

type LocalSSHimmer

type LocalSSHimmer struct {
	// contains filtered or unexported fields
}

LocalSSHimmer does the necessary key pair generation, known_hosts updates, ssh_config file updates etc steps so that ssh can connect to a locally running sketch container to other local processes like vscode without the user having to run the usual ssh obstacle course.

LocalSSHimmer does not modify your default .ssh/config, or known_hosts files. However, in order for you to be able to use it properly you will have to make a one-time edit to your ~/.ssh/config file.

In your ~/.ssh/config file, add the following line:

Include $HOME/.config/sketch/ssh_config

where $HOME is your home directory.

LocalSSHimmer uses Ed25519 keys for improved security and performance.

func NewLocalSSHimmer

func NewLocalSSHimmer(cntrName, sshHost, sshPort string) (*LocalSSHimmer, error)

NewLocalSSHimmer will set up everything so that you can use ssh on localhost to connect to the sketch container. Call #Clean when you are done with the container to remove the various entries it created in its known_hosts and ssh_config files. Also note that this will generate key pairs for both the ssh server identity and the user identity, if these files do not already exist. These key pair files are not deleted by #Cleanup, so they can be re-used across invocations of sketch. This means every sketch container that runs on this host will use the same ssh server identity. The system uses Ed25519 keys for better security and performance.

If this doesn't return an error, you should be able to run "ssh <cntrName>" in a terminal on your host machine to open a shell into the container without having to manually accept changes to your known_hosts file etc.

func (*LocalSSHimmer) Cleanup

func (c *LocalSSHimmer) Cleanup() error

Cleanup removes the container-specific entries from the SSH configuration and known_hosts files. It preserves the certificate authority entries that might be used by other containers.

type RealFileSystem

type RealFileSystem struct{}

RealFileSystem is the default implementation of FileSystem that uses the OS

func (*RealFileSystem) Mkdir

func (fs *RealFileSystem) Mkdir(name string, perm fs.FileMode) error

func (*RealFileSystem) MkdirAll

func (fs *RealFileSystem) MkdirAll(name string, perm fs.FileMode) error

func (*RealFileSystem) OpenFile

func (fs *RealFileSystem) OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error)

func (*RealFileSystem) ReadFile

func (fs *RealFileSystem) ReadFile(name string) ([]byte, error)

func (*RealFileSystem) Rename

func (fs *RealFileSystem) Rename(oldpath, newpath string) error

func (*RealFileSystem) SafeWriteFile

func (fs *RealFileSystem) SafeWriteFile(name string, data []byte, perm fs.FileMode) error

SafeWriteFile writes data to a temporary file, syncs to disk, creates a backup of the existing file if it exists, and then renames the temporary file to the target file name.

func (*RealFileSystem) Stat

func (fs *RealFileSystem) Stat(name string) (fs.FileInfo, error)

func (*RealFileSystem) TempFile

func (fs *RealFileSystem) TempFile(dir, pattern string) (*os.File, error)

func (*RealFileSystem) WriteFile

func (fs *RealFileSystem) WriteFile(name string, data []byte, perm fs.FileMode) error

type RealKeyGenerator

type RealKeyGenerator struct{}

RealKeyGenerator is the default implementation of KeyGenerator

func (*RealKeyGenerator) ConvertToSSHPublicKey

func (kg *RealKeyGenerator) ConvertToSSHPublicKey(publicKey ed25519.PublicKey) (ssh.PublicKey, error)

func (*RealKeyGenerator) GenerateKeyPair

func (kg *RealKeyGenerator) GenerateKeyPair() (ed25519.PrivateKey, ed25519.PublicKey, error)

Jump to

Keyboard shortcuts

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