github.com/ncdc/docker@v0.10.1-0.20160129113957-6c6729ef5b74/runconfig/compare.go (about)

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