config

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config reads application config.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingBox  = errors.New("missing 'box' section in codapi.json")
	ErrMissingStep = errors.New("missing 'step' section in codapi.json")
)

Functions

This section is empty.

Types

type Box

type Box struct {
	Name    string `json:"name"`
	Image   string `json:"image"`
	Runtime string `json:"runtime"`
	Host

	Files []string `json:"files"`
}

A Box describes a specific container. There is an important difference between a "sandbox" and a "box". A box is a single container. A sandbox is an environment in which we run commands. A sandbox command can contain multiple steps, each of which runs in a separate box. So the relation sandbox -> box is 1 -> 1+.

type Command

type Command struct {
	Engine string  `json:"engine"`
	Entry  string  `json:"entry"`
	Before *Step   `json:"before"`
	Steps  []*Step `json:"steps"`
	After  *Step   `json:"after"`
}

A Command describes a specific set of actions to take when executing a command in a sandbox.

type Config

type Config struct {
	PoolSize int   `json:"pool_size"`
	Verbose  bool  `json:"verbose"`
	Box      *Box  `json:"box"`
	Step     *Step `json:"step"`
	HTTP     *HTTP `json:"http"`

	// These are the available containers ("boxes").
	Boxes map[string]*Box `json:"boxes"`

	// These are the "sandboxes". Each sandbox can contain
	// multiple commands, and each command can contain
	// multiple steps. Each step is executed in a specific box.
	Commands map[string]SandboxCommands `json:"commands"`
}

A Config describes application config.

func Read

func Read(path string) (*Config, error)

Read reads application config from JSON files.

func ReadBoxes

func ReadBoxes(cfg *Config, basePath string) (*Config, error)

ReadBoxes reads boxes config from the file system. It prefers the sandboxes dir if it exists, otherwise fallbacks to the boxes dir if it exists, and finally fallbacks to the boxes.json file.

func ReadCommands

func ReadCommands(cfg *Config, basePath string) (*Config, error)

ReadCommands reads command configs from the file system. It prefers the sandboxes dir if it exists, otherwise fallbacks to the commands dir.

func ReadConfig

func ReadConfig(basePath string) (*Config, error)

ReadConfig reads application config from a JSON file.

func (*Config) BoxNames

func (cfg *Config) BoxNames() []string

BoxNames returns configured box names.

func (*Config) CommandNames

func (cfg *Config) CommandNames() []string

CommandNames returns configured command names.

func (*Config) ToJSON

func (cfg *Config) ToJSON() string

ToJSON returns JSON-encoded config with indentation.

type HTTP

type HTTP struct {
	Hosts map[string]string `json:"hosts"`
}

An HTTP describes HTTP engine settings.

type Host

type Host struct {
	CPU      int      `json:"cpu"`
	Memory   int      `json:"memory"`
	Storage  string   `json:"storage"`
	Network  string   `json:"network"`
	Writable bool     `json:"writable"`
	Volume   string   `json:"volume"`
	Tmpfs    []string `json:"tmpfs"`
	CapAdd   []string `json:"cap_add"`
	CapDrop  []string `json:"cap_drop"`
	Ulimit   []string `json:"ulimit"`
	// do not use the ulimit nproc because it is
	// a per-user setting, not a per-container setting
	NProc int `json:"nproc"`
}

A Host describes container Host attributes.

type SandboxCommands

type SandboxCommands map[string]*Command

SandboxCommands describes all commands available for a sandbox. command name : command

type Step

type Step struct {
	Box     string   `json:"box"`
	Version string   `json:"version"`
	User    string   `json:"user"`
	Action  string   `json:"action"`
	Detach  bool     `json:"detach"`
	Stdin   bool     `json:"stdin"`
	Command []string `json:"command"`
	Timeout int      `json:"timeout"`
	NOutput int      `json:"noutput"`
}

A Step describes a single step of a command.

Jump to

Keyboard shortcuts

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