github.com/varun06/docker@v1.6.0-rc2/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.Labels) != len(b.Labels) ||
    23  		len(a.PortSpecs) != len(b.PortSpecs) ||
    24  		len(a.ExposedPorts) != len(b.ExposedPorts) ||
    25  		len(a.Entrypoint) != len(b.Entrypoint) ||
    26  		len(a.Volumes) != len(b.Volumes) {
    27  		return false
    28  	}
    29  
    30  	for i := 0; i < len(a.Cmd); i++ {
    31  		if a.Cmd[i] != b.Cmd[i] {
    32  			return false
    33  		}
    34  	}
    35  	for i := 0; i < len(a.Env); i++ {
    36  		if a.Env[i] != b.Env[i] {
    37  			return false
    38  		}
    39  	}
    40  	for k, v := range a.Labels {
    41  		if v != b.Labels[k] {
    42  			return false
    43  		}
    44  	}
    45  	for i := 0; i < len(a.PortSpecs); i++ {
    46  		if a.PortSpecs[i] != b.PortSpecs[i] {
    47  			return false
    48  		}
    49  	}
    50  	for k := range a.ExposedPorts {
    51  		if _, exists := b.ExposedPorts[k]; !exists {
    52  			return false
    53  		}
    54  	}
    55  	for i := 0; i < len(a.Entrypoint); i++ {
    56  		if a.Entrypoint[i] != b.Entrypoint[i] {
    57  			return false
    58  		}
    59  	}
    60  	for key := range a.Volumes {
    61  		if _, exists := b.Volumes[key]; !exists {
    62  			return false
    63  		}
    64  	}
    65  	return true
    66  }