github.com/fcwu/docker@v1.4.2-0.20150115145920-2a69ca89f0df/runconfig/compare.go (about)

     1  package runconfig
     2  
     3  // Compare two Config struct. Do not compare the "Image" nor "Hostname" fields
     4  // If OpenStdin is set, then it differs
     5  func Compare(a, b *Config) bool {
     6  	if a == nil || b == nil ||
     7  		a.OpenStdin || b.OpenStdin {
     8  		return false
     9  	}
    10  	if a.AttachStdout != b.AttachStdout ||
    11  		a.AttachStderr != b.AttachStderr ||
    12  		a.User != b.User ||
    13  		a.Memory != b.Memory ||
    14  		a.MemorySwap != b.MemorySwap ||
    15  		a.CpuShares != b.CpuShares ||
    16  		a.OpenStdin != b.OpenStdin ||
    17  		a.Tty != b.Tty {
    18  		return false
    19  	}
    20  	if len(a.Cmd) != len(b.Cmd) ||
    21  		len(a.Env) != len(b.Env) ||
    22  		len(a.PortSpecs) != len(b.PortSpecs) ||
    23  		len(a.ExposedPorts) != len(b.ExposedPorts) ||
    24  		len(a.Entrypoint) != len(b.Entrypoint) ||
    25  		len(a.Volumes) != len(b.Volumes) {
    26  		return false
    27  	}
    28  
    29  	for i := 0; i < len(a.Cmd); i++ {
    30  		if a.Cmd[i] != b.Cmd[i] {
    31  			return false
    32  		}
    33  	}
    34  	for i := 0; i < len(a.Env); i++ {
    35  		if a.Env[i] != b.Env[i] {
    36  			return false
    37  		}
    38  	}
    39  	for i := 0; i < len(a.PortSpecs); i++ {
    40  		if a.PortSpecs[i] != b.PortSpecs[i] {
    41  			return false
    42  		}
    43  	}
    44  	for k := range a.ExposedPorts {
    45  		if _, exists := b.ExposedPorts[k]; !exists {
    46  			return false
    47  		}
    48  	}
    49  	for i := 0; i < len(a.Entrypoint); i++ {
    50  		if a.Entrypoint[i] != b.Entrypoint[i] {
    51  			return false
    52  		}
    53  	}
    54  	for key := range a.Volumes {
    55  		if _, exists := b.Volumes[key]; !exists {
    56  			return false
    57  		}
    58  	}
    59  	return true
    60  }