util

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RepositoryUrl = "https://github.com/camerondurham/ch"
	Repository    = "camerondurham/ch"
	ApiPath       = "https://api.github.com/repos/%s/releases/latest"
)

Variables

View Source
var (
	ErrDoesNotExist = errors.New("does not exist")
)

Functions

func CheckLatestVersion added in v0.3.1

func CheckLatestVersion()

func DebugPrint

func DebugPrint(msg string)

DebugPrint if DEBUG environment variable is set

func GetConfigOpts added in v0.2.5

func GetConfigOpts() (opts map[string]*CliOpts, err error)

GetConfigOpts retrieves optional settings from ~/.ch.yaml

func GetEnvs

func GetEnvs() (envs map[string]*ContainerOpts, err error)

GetEnvs retrieves the environments managed by ch from ~/.ch.yaml

func GetLatestVersion added in v0.2.3

func GetLatestVersion(getRequest callback) (string, error)

func GetRequest added in v0.2.3

func GetRequest(url string) (map[string]interface{}, error)

func LatestVersion added in v0.2.3

func LatestVersion(repository string) string

func MonitorTtySize

func MonitorTtySize(ctx context.Context, cli ContainerClient, id string, isExec bool) error

MonitorTtySize updates the container tty size when the terminal tty changes size

func PrintConfig

func PrintConfig(envName string, opts *ContainerOpts)

func PrintEnvNotFoundMsg

func PrintEnvNotFoundMsg(envName string)

func PrintStartHelpMessage

func PrintStartHelpMessage(envName string)

func SetEnvs

func SetEnvs(envs map[string]*ContainerOpts)

Types

type BuildOpts

type BuildOpts struct {
	DockerfilePath string
	Context        string
	Tag            string
}

type Cli

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

Cli TODO: add config/env settings to use Cli in other commands

func NewCliClient

func NewCliClient() (*Cli, error)

func NewCliClientWithDockerService

func NewCliClientWithDockerService(dockerClient DockerClient, dockerService *DockerService) *Cli

func (*Cli) ApiClient

func (cli *Cli) ApiClient() *DockerAPIService

func (*Cli) Container

func (cli *Cli) Container(envName string) (*types.Container, error)

func (*Cli) ContainerIsRunning

func (cli *Cli) ContainerIsRunning(envName string) bool

func (*Cli) Containers

func (cli *Cli) Containers() map[string]*ContainerOpts

func (*Cli) DockerClient

func (cli *Cli) DockerClient() *DockerService

func (*Cli) Err

func (cli *Cli) Err() io.Writer

func (*Cli) In

func (cli *Cli) In() *streams.In

func (*Cli) Out

func (cli *Cli) Out() *streams.Out

func (*Cli) Validator

func (cli *Cli) Validator() *Validator

type CliOpts added in v0.3.0

type CliOpts struct {
	CheckVersion bool
}

type ContainerClient

type ContainerClient interface {
	ApiClient() *DockerAPIService
	DockerClient() *DockerService
	Out() *streams.Out
	In() *streams.In
	Err() io.Writer
	Containers() map[string]*ContainerOpts
	Container(envName string) (*types.Container, error)
	ContainerIsRunning(envName string) bool
	Validator() *Validator
}

type ContainerOpts

type ContainerOpts struct {
	BuildOpts  *BuildOpts
	PullOpts   *PullOpts
	HostConfig *HostConfig
	Shell      string
}

type DockerAPI

type DockerAPI interface {
	ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error)
	ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
	ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error
	ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
	ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
	ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error
	ContainerResize(ctx context.Context, containerID string, options types.ResizeOptions) error
}

type DockerAPIService

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

func NewDockerAPIService

func NewDockerAPIService(client DockerService) *DockerAPIService

func (*DockerAPIService) ContainerExecAttach

func (d *DockerAPIService) ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)

func (*DockerAPIService) ContainerExecCreate

func (d *DockerAPIService) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)

func (*DockerAPIService) ContainerExecInspect

func (d *DockerAPIService) ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)

func (*DockerAPIService) ContainerExecResize

func (d *DockerAPIService) ContainerExecResize(ctx context.Context, id string, options types.ResizeOptions) error

func (*DockerAPIService) ContainerExecStart

func (d *DockerAPIService) ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error

func (*DockerAPIService) ContainerInspect

func (d *DockerAPIService) ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error)

func (*DockerAPIService) ContainerResize

func (d *DockerAPIService) ContainerResize(ctx context.Context, id string, options types.ResizeOptions) error

func (*DockerAPIService) CreateExecInteractive

func (d *DockerAPIService) CreateExecInteractive(ctx context.Context, cliClient ContainerClient, container string, config types.ExecConfig) error

CreateExecInteractive creates an exec config to run an exec process

func (*DockerAPIService) InteractiveExec

func (d *DockerAPIService) InteractiveExec(ctx context.Context, cliClient ContainerClient, execConfig *types.ExecConfig, execID string) error

type DockerClient

type DockerClient interface {
	ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
	ImagePull(ctx context.Context, refStr string, options types.ImagePullOptions) (io.ReadCloser, error)
	ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
	ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (container.ContainerCreateCreatedBody, error)
	ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error
	ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error
	ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error
}

type DockerService

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

func NewDockerService

func NewDockerService() (*DockerService, error)

func NewDockerServiceFromClient

func NewDockerServiceFromClient(cli DockerClient) *DockerService

func (*DockerService) BuildImageWithContext

func (d *DockerService) BuildImageWithContext(ctx context.Context, out *streams.Out, contextDirPath string, imageTagName string, dockerfile string) (err error)

BuildImageWithContext accepts a build context path and relative Dockerfile path

func (*DockerService) ContainerCreate

func (d *DockerService) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (container.ContainerCreateCreatedBody, error)

func (*DockerService) ContainerList

func (d *DockerService) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)

func (*DockerService) ContainerRemove

func (d *DockerService) ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error

func (*DockerService) ContainerStart

func (d *DockerService) ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error

func (*DockerService) ContainerStop

func (d *DockerService) ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error

func (*DockerService) CreateContainer

func (d *DockerService) CreateContainer(ctx context.Context, config *container.Config, containerName string, hostConfig *container.HostConfig) (container.ContainerCreateCreatedBody, error)

CreateContainer create container with name

func (*DockerService) GetRunning

func (d *DockerService) GetRunning(filters filters.Args, print bool) ([]types.Container, error)

GetRunning lists running containers like docker ps

func (*DockerService) ImageBuild

func (d *DockerService) ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)

func (*DockerService) ImagePull

func (d *DockerService) ImagePull(ctx context.Context, refStr string, options types.ImagePullOptions) (io.ReadCloser, error)

func (*DockerService) PullImage

func (d *DockerService) PullImage(ctx context.Context, out *streams.Out, imageName string) error

PullImage downloads a Docker image from Docker Hub

func (*DockerService) RemoveContainer

func (d *DockerService) RemoveContainer(ctx context.Context, containerName string) error

RemoveContainer delete container

func (*DockerService) StartContainer

func (d *DockerService) StartContainer(ctx context.Context, containerID string) error

StartContainer with given name

func (*DockerService) StopContainer

func (d *DockerService) StopContainer(ctx context.Context, containerID string, timeout *time.Duration) error

StopContainer from running

type ErrorDetail

type ErrorDetail struct {
	Code    int    `json:",string"`
	Message string `json:"message"`
}

ErrorDetail Docker Build Response

type HostConfig

type HostConfig struct {
	Binds        []string          // List of volume bindings for this container
	SecurityOpt  []string          // List of string values to customize labels for MLS systems, such as SELinux.
	PortBindings nat.PortMap       // Map of host to container ports
	Privileged   bool              // Is the container in privileged mode
	CapAdd       strslice.StrSlice // List of kernel capabilities to add to the container
}

type PullOpts

type PullOpts struct {
	ImageName string
}

type Validate

type Validate interface {
	GetAbs(string) string
	ValidPath(string) bool
}

type Validator

type Validator struct{}

func (*Validator) GetAbs

func (v *Validator) GetAbs(path string) (absPath string)

func (*Validator) ValidPath

func (v *Validator) ValidPath(path string) bool

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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