contman

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2018 License: LGPL-3.0 Imports: 4 Imported by: 0

README

contman CircleCI license

Library for high-level control of container system, running commands and prepared receipts. It provides three main abstractions: Manager, Container and Receipt. Manager allow container creation and using images, Container has all basic actions of using specific container. Main and most interesting this is Receipt

Receipt

Receipt is a declarative description of running specific container and copying data from/to it. It useful to make some actions in isolated or remote environment.

type Receipt struct {
	Image            string
	Cmd              string
	Env              map[string]string
	InputCopy        map[string]string
	OutputCopy       map[string]string
	UseControlSocket bool
	OnlyCreate       bool
}

Basic usage of receipts looks like this:

package main

import (
	"log"

	"github.com/elemir/contman"
	"github.com/elemir/contman/docker"
)

var receipt = contman.Receipt{
	Image:      "alpine:latest",
	Cmd:        "sed \"s/README.md/$MD/g\" -i /README.md",
	InputCopy:  map[string]string{"README.md": "/"},
	OutputCopy: map[string]string{"/README.md": "."},
	Env:        map[string]string{"MD": "WRITEYOU.md"},
}

func main() {
	dm, err := docker.NewDockerManager()
	if err != nil {
		log.Println("Cannot create docker manager: ", err)
	}
	err = contman.RunReceipt(dm, receipt)
	if err != nil {
		log.Println("Cannot run receipt: ", err)
	}
}

This code will change all 'README.md' entrances in README.md file to 'WRITEYOU.md'

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunReceipt

func RunReceipt(cm Manager, receipt Receipt) error

Types

type Config

type Config struct {
	Image      string
	Cmd        string
	Env        map[string]string
	Mounts     []Mount
	WorkingDir string
}

type Container

type Container interface {
	Start() error
	Stop(timeout time.Duration) error
	Remove() error

	IsRunning() (bool, error)
	Wait(dumpLog bool) (int, error)

	CopyFrom(src, dest string) error
	CopyTo(src, dest string) error

	GetLogger() *log.Entry
}

type Manager

type Manager interface {
	PullImage(string) error
	HasImage(string) bool

	ContainerCreate(Config) (Container, error)
	GetSystemMounts() []Mount
}

type Mount

type Mount struct {
	Source   string
	Target   string
	ReadOnly bool
}

type Receipt

type Receipt struct {
	Image              string
	Cmd                string
	Env                map[string]string
	InputCopy          map[string]string
	OutputCopy         map[string]string
	Timeout            time.Duration
	UseControlSocket   bool
	UseLocalImage      bool
	OnlyCreate         bool
	UseImageWorkingDir bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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