Browse Source

dont restart container unless new hash

reid 2 years ago
parent
commit
fbded82573
1 changed files with 9 additions and 10 deletions
  1. 9 10
      docker/docker.go

+ 9 - 10
docker/docker.go

@@ -197,17 +197,16 @@ func StartContainer(containerName string, containerType string) (structs.Contain
 		msg := fmt.Sprintf("Started stopped container %s", containerName)
 		logger.Info(msg)
 	default:
-		// debug
+		// if container is running, check the image digest
 		currentImage := existingContainer.Image
-		tagAndDigest := strings.Split(currentImage, ":")[1] // This will give "latest@sha256"
-		currentTag := strings.Split(tagAndDigest, "@")[0]   // This will give "latest"
-	
-		logger.Info(fmt.Sprintf("Current image: %s, Current tag: %s, Desired tag: %s, Current ID: %s, Desired ID: %s", 
-			currentImage, currentTag, desiredTag, existingContainer.ImageID, desiredHash))
-	
-		//
-		// if container is running, check the image hash
-		if existingContainer.ImageID != desiredHash {
+		digestParts := strings.Split(currentImage, "@sha256:")
+		currentDigest := ""
+		if len(digestParts) > 1 {
+			currentDigest = digestParts[1]
+		}
+		logger.Info(fmt.Sprintf("Current image: %s, Current digest: %s, Desired digest: %s", 
+			currentImage, currentDigest, desiredHash))
+		if currentDigest != desiredHash {
 			// if the hashes don't match, recreate the container with the new one
 			err := cli.ContainerRemove(ctx, containerName, types.ContainerRemoveOptions{Force: true})
 			if err != nil {