devbox

package
v0.0.0-...-b7fc2af Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package devbox provides state management functionality to the Cobra CLI cmds.

Index

Constants

View Source
const DefaultStateFile = "~/.devbox.state.yaml"

DefaultStateFile defines the default location of the state file.

Variables

View Source
var DefaultConfig = Config{
	Image:       "github.com/mojochao/devbox-base",
	User:        "developer",
	Shell:       "sh",
	Name:        fmt.Sprintf("devbox-%s", getCurrentUsername()),
	Namespace:   "",
	Kubeconfig:  "",
	Description: "",
}

DefaultConfig is a Config containing default configuration values.

View Source
var ManifestTypes = []string{
	"bash",
	"zsh",
	"git",
	"ssh",
	"tmux",
	"vim",
	"emacs",
}

ManifestTypes contains the list of defaultManifest types in install order.

Functions

This section is empty.

Types

type Box

type Box struct {
	// Image of devbox running in Docker container or Kubernetes pod.
	Image string `yaml:"image"`

	// User in docker container or Kubernetes pod running devbox image.
	User string `yaml:"user"`

	// Shell to exec in devbox running in Docker container or Kubernetes pod.
	Shell string `yaml:"shell"`

	// Name of Docker container or Kubernetes pod running devbox image.
	Name string `yaml:"name"`

	// Namespace is namespace of Kubernetes cluster hosting devbox pod.
	Namespace string `yaml:"namespace"`

	// Kubeconfig is path to kubeconfig of Kubernetes cluster hosting devbox pod.
	Kubeconfig string `yaml:"kubeconfig"`

	// Description of devbox.
	Description string `yaml:"description"`

	// Manifest of devbox.
	Manifest Manifest `yaml:"defaultManifest"`
}

Box contains information on a devbox.

func New

func New(cfg *Config) Box

New returns a fully constructed Box.

func (Box) CopyFile

func (box Box) CopyFile(src string, dst string) error

CopyFile copies a file to a Box.

func (Box) HomeDir

func (box Box) HomeDir() string

HomeDir returns the home directory of the devbox user.

func (Box) OpenShell

func (box Box) OpenShell(shellPath string) error

OpenShell opens a shell in a Box.

func (Box) Setup

func (box Box) Setup(manifestType string) error

Setup sets up a Box.

func (Box) Start

func (box Box) Start() error

Start starts a Box.

func (Box) Stop

func (box Box) Stop() error

Stop stops a Box.

type BoxID

type BoxID = string

BoxID is an identifier for a devbox persisted in application state.

type Boxes

type Boxes = map[BoxID]Box

Boxes contains Box values keyed by BoxID.

type Config

type Config struct {
	// Image of devbox running in Docker container or Kubernetes pod.
	Image string

	// User in docker container or Kubernetes pod running devbox image.
	User string

	// Shell to exec in devbox running in Docker container or Kubernetes pod.
	Shell string

	// Name of Docker container or Kubernetes pod running devbox image.
	Name string

	// Namespace is namespace of Kubernetes cluster hosting devbox pod.
	Namespace string

	// Kubeconfig is path to kubeconfig of Kubernetes cluster hosting devbox pod.
	Kubeconfig string

	// Description of devbox.
	Description string
}

Config contains configuration data required of a Box.

type Manifest

type Manifest = map[ManifestType][]ManifestItem

Manifest contains a map of ManifestItem values by their type key.

type ManifestItem

type ManifestItem struct {
	Path     string   `yaml:"path,omitempty"`
	Commands []string `yaml:"commands,omitempty"`
}

ManifestItem contains optional path and commands to use when setting up that item.

type ManifestType

type ManifestType = string

ManifestType identifies the type of ManifestItem values.

type State

type State struct {
	// Active is the ID of the active devbox context, if any.
	Active BoxID `yaml:"active"`

	// Boxes is the map of added Box items by ID.
	Boxes Boxes `yaml:"boxes"`

	// Path is the path to the state file.
	Path string `yaml:"path"`
}

State contains devbox state.

func LoadState

func LoadState(path string) (State, error)

LoadState returns State loaded from path.

func NewState

func NewState(path string) State

NewState returns a new State ready for use.

func (State) AddDevbox

func (boxes State) AddDevbox(id BoxID, box Box) error

AddDevbox adds a Box to State.

func (State) ContainsDevbox

func (boxes State) ContainsDevbox(id BoxID) bool

ContainsDevbox tests if a Box is in State.

func (State) GetDevbox

func (boxes State) GetDevbox(id BoxID) (Box, error)

GetDevbox returns Box in State.

func (State) RemoveDevbox

func (boxes State) RemoveDevbox(id BoxID) error

RemoveDevbox removes a Box from State.

func (State) Save

func (boxes State) Save(paths ...string) error

Save saves State. If no paths are provided, the path from which State was loaded will be used.

Jump to

Keyboard shortcuts

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