github.com/robryk/drone@v0.2.1-0.20140602202253-40fe4305815d/pkg/build/docker/structs.go (about)

     1  package docker
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  	"strings"
     7  	"time"
     8  )
     9  
    10  // These are structures copied from the Docker project.
    11  // We avoid importing the libraries due to a CGO
    12  // depenency on libdevmapper that we'd like to avoid.
    13  
    14  type KeyValuePair struct {
    15  	Key   string
    16  	Value string
    17  }
    18  
    19  type HostConfig struct {
    20  	Binds           []string
    21  	ContainerIDFile string
    22  	LxcConf         []KeyValuePair
    23  	Privileged      bool
    24  	PortBindings    map[Port][]PortBinding
    25  	Links           []string
    26  	PublishAllPorts bool
    27  }
    28  
    29  type Top struct {
    30  	Titles    []string
    31  	Processes [][]string
    32  }
    33  
    34  type Containers struct {
    35  	ID         string `json:"Id"`
    36  	Image      string
    37  	Command    string
    38  	Created    int64
    39  	Status     string
    40  	Ports      []Port
    41  	SizeRw     int64
    42  	SizeRootFs int64
    43  	Names      []string
    44  }
    45  
    46  type Run struct {
    47  	ID       string   `json:"Id"`
    48  	Warnings []string `json:",omitempty"`
    49  }
    50  
    51  type Wait struct {
    52  	StatusCode int
    53  }
    54  
    55  type State struct {
    56  	Running    bool
    57  	Pid        int
    58  	ExitCode   int
    59  	StartedAt  time.Time
    60  	FinishedAt time.Time
    61  	Ghost      bool
    62  }
    63  
    64  type PortBinding struct {
    65  	HostIp   string
    66  	HostPort string
    67  }
    68  
    69  // 80/tcp
    70  type Port string
    71  
    72  func (p Port) Proto() string {
    73  	parts := strings.Split(string(p), "/")
    74  	if len(parts) == 1 {
    75  		return "tcp"
    76  	}
    77  	return parts[1]
    78  }
    79  
    80  func (p Port) Port() string {
    81  	return strings.Split(string(p), "/")[0]
    82  }
    83  
    84  func (p Port) Int() int {
    85  	i, err := parsePort(p.Port())
    86  	if err != nil {
    87  		panic(err)
    88  	}
    89  	return i
    90  }
    91  
    92  func parsePort(rawPort string) (int, error) {
    93  	port, err := strconv.ParseUint(rawPort, 10, 16)
    94  	if err != nil {
    95  		return 0, err
    96  	}
    97  	return int(port), nil
    98  }
    99  
   100  func NewPort(proto, port string) Port {
   101  	return Port(fmt.Sprintf("%s/%s", port, proto))
   102  }
   103  
   104  type PortMapping map[string]string // Deprecated
   105  
   106  type NetworkSettings struct {
   107  	IPAddress   string
   108  	IPPrefixLen int
   109  	Gateway     string
   110  	Bridge      string
   111  	PortMapping map[string]PortMapping // Deprecated
   112  	Ports       map[Port][]PortBinding
   113  }
   114  
   115  type Config struct {
   116  	Hostname        string
   117  	Domainname      string
   118  	User            string
   119  	Memory          int64 // Memory limit (in bytes)
   120  	MemorySwap      int64 // Total memory usage (memory + swap); set `-1' to disable swap
   121  	CpuShares       int64 // CPU shares (relative weight vs. other containers)
   122  	AttachStdin     bool
   123  	AttachStdout    bool
   124  	AttachStderr    bool
   125  	PortSpecs       []string // Deprecated - Can be in the format of 8080/tcp
   126  	ExposedPorts    map[Port]struct{}
   127  	Tty             bool // Attach standard streams to a tty, including stdin if it is not closed.
   128  	OpenStdin       bool // Open stdin
   129  	StdinOnce       bool // If true, close stdin after the 1 attached client disconnects.
   130  	Env             []string
   131  	Cmd             []string
   132  	Dns             []string
   133  	Image           string // Name of the image as it was passed by the operator (eg. could be symbolic)
   134  	Volumes         map[string]struct{}
   135  	VolumesFrom     string
   136  	WorkingDir      string
   137  	Entrypoint      []string
   138  	NetworkDisabled bool
   139  }
   140  
   141  type Container struct {
   142  	ID string
   143  
   144  	Created time.Time
   145  
   146  	Path string
   147  	Args []string
   148  
   149  	Config *Config
   150  	State  State
   151  	Image  string
   152  
   153  	NetworkSettings *NetworkSettings
   154  
   155  	SysInitPath    string
   156  	ResolvConfPath string
   157  	HostnamePath   string
   158  	HostsPath      string
   159  	Name           string
   160  	Driver         string
   161  
   162  	Volumes map[string]string
   163  	// Store rw/ro in a separate structure to preserve reverse-compatibility on-disk.
   164  	// Easier than migrating older container configs :)
   165  	VolumesRW map[string]bool
   166  }