fix: do not aggressively clean up when using the docker-local scheduler

This commit is contained in:
Jose Diaz-Gonzalez committed 2021-08-05 04:17:37 -04:00
1 parent 30a15aaa7a
commit 0a08911800
1 file changed
+10 -5
+10 -5
View File
@@ -78,9 +78,15 @@ func pushToRegistry(appName string, tag int, imageID string, imageRepo string) e
return errors.New("Unable to push image") return errors.New("Unable to push image")
} }
common.LogVerboseQuiet("Cleaning up") // Only clean up when the scheduler is not docker-local
imageCleanup(appName, fmt.Sprintf("%s%s", registryServer, imageRepo), imageTag, tag) // other schedulers do not retire local images
imageCleanup(appName, imageRepo, imageTag, tag) if common.GetAppScheduler(appName) != "docker-local" {
common.LogVerboseQuiet("Cleaning up")
imageCleanup(appName, fmt.Sprintf("%s%s", registryServer, imageRepo), imageTag, tag)
if fmt.Sprintf("%s%s", registryServer, imageRepo) != imageRepo {
imageCleanup(appName, imageRepo, imageTag, tag)
}
}
common.LogVerboseQuiet(fmt.Sprintf("Image %s pushed", fullImage)) common.LogVerboseQuiet(fmt.Sprintf("Image %s pushed", fullImage))
return nil return nil
@@ -110,12 +116,11 @@ func dockerPush(imageTag string) bool {
func imageCleanup(appName string, imageRepo string, imageTag string, tag int) { func imageCleanup(appName string, imageRepo string, imageTag string, tag int) {
// # keep last two images in place // # keep last two images in place
oldTag := tag - 1 oldTag := tag - 2
tenImagesAgoTag := tag - 12 tenImagesAgoTag := tag - 12
imagesToRemove := []string{} imagesToRemove := []string{}
for oldTag > 0 { for oldTag > 0 {
common.LogInfo1(fmt.Sprintf("Removing image: %s:%d", imageRepo, oldTag))
imagesToRemove = append(imagesToRemove, fmt.Sprintf("%s:%d", imageRepo, oldTag)) imagesToRemove = append(imagesToRemove, fmt.Sprintf("%s:%d", imageRepo, oldTag))
oldTag = oldTag - 1 oldTag = oldTag - 1
if tenImagesAgoTag == oldTag { if tenImagesAgoTag == oldTag {