2014-03-07 20:36:47 -05:00
|
|
|
package image
|
2013-03-18 03:15:35 -04:00
|
|
|
|
|
|
|
import (
|
2015-07-20 13:57:15 -04:00
|
|
|
"encoding/json"
|
2013-03-18 03:15:35 -04:00
|
|
|
"fmt"
|
2015-03-29 17:17:23 -04:00
|
|
|
"regexp"
|
2015-07-20 13:57:15 -04:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/runconfig"
|
2013-03-18 03:15:35 -04:00
|
|
|
)
|
|
|
|
|
2015-05-13 14:42:45 -04:00
|
|
|
var validHex = regexp.MustCompile(`^([a-f0-9]{64})$`)
|
|
|
|
|
2015-07-21 01:49:27 -04:00
|
|
|
// Image stores the image configuration.
|
2015-07-20 13:57:15 -04:00
|
|
|
type Image struct {
|
2015-07-21 01:49:27 -04:00
|
|
|
// ID a unique 64 character identifier of the image
|
|
|
|
ID string `json:"id"`
|
|
|
|
// Parent id of the image
|
|
|
|
Parent string `json:"parent,omitempty"`
|
|
|
|
// Comment user added comment
|
|
|
|
Comment string `json:"comment,omitempty"`
|
|
|
|
// Created timestamp when image was created
|
|
|
|
Created time.Time `json:"created"`
|
|
|
|
// Container is the id of the container used to commit
|
|
|
|
Container string `json:"container,omitempty"`
|
|
|
|
// ContainerConfig is the configuration of the container that is committed into the image
|
|
|
|
ContainerConfig runconfig.Config `json:"container_config,omitempty"`
|
|
|
|
// DockerVersion specifies version on which image is built
|
|
|
|
DockerVersion string `json:"docker_version,omitempty"`
|
|
|
|
// Author of the image
|
|
|
|
Author string `json:"author,omitempty"`
|
|
|
|
// Config is the configuration of the container received from the client
|
|
|
|
Config *runconfig.Config `json:"config,omitempty"`
|
|
|
|
// Architecture is the hardware that the image is build and runs on
|
|
|
|
Architecture string `json:"architecture,omitempty"`
|
|
|
|
// OS is the operating system used to build and run the image
|
|
|
|
OS string `json:"os,omitempty"`
|
|
|
|
// Size is the total size of the image including all layers it is composed of
|
|
|
|
Size int64
|
2015-07-20 13:57:15 -04:00
|
|
|
}
|
|
|
|
|
2015-07-21 01:49:27 -04:00
|
|
|
// NewImgJSON creates an Image configuration from json.
|
2015-07-20 13:57:15 -04:00
|
|
|
func NewImgJSON(src []byte) (*Image, error) {
|
|
|
|
ret := &Image{}
|
|
|
|
|
|
|
|
// FIXME: Is there a cleaner way to "purify" the input json?
|
|
|
|
if err := json.Unmarshal(src, ret); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
2015-07-21 01:49:27 -04:00
|
|
|
// ValidateID checks whether an ID string is a valid image ID.
|
2015-03-29 17:17:23 -04:00
|
|
|
func ValidateID(id string) error {
|
|
|
|
if ok := validHex.MatchString(id); !ok {
|
2015-04-26 12:50:25 -04:00
|
|
|
return fmt.Errorf("image ID '%s' is invalid", id)
|
2015-03-29 17:17:23 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|