github.com/mheon/docker@v0.11.2-0.20150922122814-44f47903a831/image/image.go (about)

     1  package image
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"regexp"
     7  	"time"
     8  
     9  	"github.com/docker/docker/runconfig"
    10  )
    11  
    12  var validHex = regexp.MustCompile(`^([a-f0-9]{64})$`)
    13  
    14  // Image stores the image configuration.
    15  type Image struct {
    16  	// ID a unique 64 character identifier of the image
    17  	ID string `json:"id"`
    18  	// Parent id of the image
    19  	Parent string `json:"parent,omitempty"`
    20  	// Comment user added comment
    21  	Comment string `json:"comment,omitempty"`
    22  	// Created timestamp when image was created
    23  	Created time.Time `json:"created"`
    24  	// Container is the id of the container used to commit
    25  	Container string `json:"container,omitempty"`
    26  	// ContainerConfig  is the configuration of the container that is committed into the image
    27  	ContainerConfig runconfig.Config `json:"container_config,omitempty"`
    28  	// DockerVersion specifies version on which image is built
    29  	DockerVersion string `json:"docker_version,omitempty"`
    30  	// Author of the image
    31  	Author string `json:"author,omitempty"`
    32  	// Config is the configuration of the container received from the client
    33  	Config *runconfig.Config `json:"config,omitempty"`
    34  	// Architecture is the hardware that the image is build and runs on
    35  	Architecture string `json:"architecture,omitempty"`
    36  	// OS is the operating system used to build and run the image
    37  	OS string `json:"os,omitempty"`
    38  	// Size is the total size of the image including all layers it is composed of
    39  	Size int64
    40  }
    41  
    42  // NewImgJSON creates an Image configuration from json.
    43  func NewImgJSON(src []byte) (*Image, error) {
    44  	ret := &Image{}
    45  
    46  	// FIXME: Is there a cleaner way to "purify" the input json?
    47  	if err := json.Unmarshal(src, ret); err != nil {
    48  		return nil, err
    49  	}
    50  	return ret, nil
    51  }
    52  
    53  // ValidateID checks whether an ID string is a valid image ID.
    54  func ValidateID(id string) error {
    55  	if ok := validHex.MatchString(id); !ok {
    56  		return fmt.Errorf("image ID '%s' is invalid", id)
    57  	}
    58  	return nil
    59  }