forked from toolshed/abra
		
	fix: further fixes for gracefully handling missing tag
Follows 1b37d2d5f5.
			
			
This commit is contained in:
		| @ -241,10 +241,13 @@ You may invoke this command in "wizard" mode and be prompted for input: | |||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			if upgradeTag != "skip" { | 			if upgradeTag != "skip" { | ||||||
| 				if err := recipe.UpdateTag(image, upgradeTag); err != nil { | 				ok, err := recipe.UpdateTag(image, upgradeTag) | ||||||
|  | 				if err != nil { | ||||||
| 					logrus.Fatal(err) | 					logrus.Fatal(err) | ||||||
| 				} | 				} | ||||||
| 				logrus.Infof("tag upgraded from %s to %s for %s", tag.String(), upgradeTag, image) | 				if ok { | ||||||
|  | 					logrus.Infof("tag upgraded from %s to %s for %s", tag.String(), upgradeTag, image) | ||||||
|  | 				} | ||||||
| 			} else { | 			} else { | ||||||
| 				logrus.Warnf("not upgrading %s, skipping as requested", image) | 				logrus.Warnf("not upgrading %s, skipping as requested", image) | ||||||
| 			} | 			} | ||||||
|  | |||||||
| @ -16,10 +16,10 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| // UpdateTag updates an image tag in-place on file system local compose files. | // UpdateTag updates an image tag in-place on file system local compose files. | ||||||
| func UpdateTag(pattern, image, tag, recipeName string) error { | func UpdateTag(pattern, image, tag, recipeName string) (bool, error) { | ||||||
| 	composeFiles, err := filepath.Glob(pattern) | 	composeFiles, err := filepath.Glob(pattern) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return false, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	logrus.Debugf("considering %s config(s) for tag update", strings.Join(composeFiles, ", ")) | 	logrus.Debugf("considering %s config(s) for tag update", strings.Join(composeFiles, ", ")) | ||||||
| @ -30,12 +30,12 @@ func UpdateTag(pattern, image, tag, recipeName string) error { | |||||||
| 		envSamplePath := path.Join(config.RECIPES_DIR, recipeName, ".env.sample") | 		envSamplePath := path.Join(config.RECIPES_DIR, recipeName, ".env.sample") | ||||||
| 		sampleEnv, err := config.ReadEnv(envSamplePath) | 		sampleEnv, err := config.ReadEnv(envSamplePath) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return false, err | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		compose, err := loader.LoadComposefile(opts, sampleEnv) | 		compose, err := loader.LoadComposefile(opts, sampleEnv) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return false, err | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		for _, service := range compose.Services { | 		for _, service := range compose.Services { | ||||||
| @ -45,24 +45,26 @@ func UpdateTag(pattern, image, tag, recipeName string) error { | |||||||
|  |  | ||||||
| 			img, _ := reference.ParseNormalizedNamed(service.Image) | 			img, _ := reference.ParseNormalizedNamed(service.Image) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return err | 				return false, err | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			var composeTag string | ||||||
|  | 			switch img.(type) { | ||||||
|  | 			case reference.NamedTagged: | ||||||
|  | 				composeTag = img.(reference.NamedTagged).Tag() | ||||||
|  | 			default: | ||||||
|  | 				// unable to parse, typically image missing tag | ||||||
|  | 				return false, nil | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			composeImage := reference.Path(img) | 			composeImage := reference.Path(img) | ||||||
| 			if strings.Contains(composeImage, "library") { |  | ||||||
| 				// ParseNormalizedNamed prepends 'library' to images like nginx:<tag>, |  | ||||||
| 				// postgres:<tag>, i.e. images which do not have a username in the |  | ||||||
| 				// first position of the string |  | ||||||
| 				composeImage = strings.Split(composeImage, "/")[1] |  | ||||||
| 			} |  | ||||||
| 			composeTag := img.(reference.NamedTagged).Tag() |  | ||||||
|  |  | ||||||
| 			logrus.Debugf("parsed %s from %s", composeTag, service.Image) | 			logrus.Debugf("parsed %s from %s", composeTag, service.Image) | ||||||
|  |  | ||||||
| 			if image == composeImage { | 			if image == composeImage { | ||||||
| 				bytes, err := ioutil.ReadFile(composeFile) | 				bytes, err := ioutil.ReadFile(composeFile) | ||||||
| 				if err != nil { | 				if err != nil { | ||||||
| 					return err | 					return false, err | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				old := fmt.Sprintf("%s:%s", composeImage, composeTag) | 				old := fmt.Sprintf("%s:%s", composeImage, composeTag) | ||||||
| @ -72,13 +74,13 @@ func UpdateTag(pattern, image, tag, recipeName string) error { | |||||||
| 				logrus.Debugf("updating %s to %s in %s", old, new, compose.Filename) | 				logrus.Debugf("updating %s to %s in %s", old, new, compose.Filename) | ||||||
|  |  | ||||||
| 				if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0764); err != nil { | 				if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0764); err != nil { | ||||||
| 					return err | 					return true, err | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return nil | 	return false, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // UpdateLabel updates a label in-place on file system local compose files. | // UpdateLabel updates a label in-place on file system local compose files. | ||||||
|  | |||||||
| @ -163,15 +163,17 @@ func (r Recipe) UpdateLabel(pattern, serviceName, label string) error { | |||||||
| } | } | ||||||
|  |  | ||||||
| // UpdateTag updates a recipe tag | // UpdateTag updates a recipe tag | ||||||
| func (r Recipe) UpdateTag(image, tag string) error { | func (r Recipe) UpdateTag(image, tag string) (bool, error) { | ||||||
| 	pattern := fmt.Sprintf("%s/%s/compose**yml", config.RECIPES_DIR, r.Name) | 	pattern := fmt.Sprintf("%s/%s/compose**yml", config.RECIPES_DIR, r.Name) | ||||||
|  |  | ||||||
| 	image = StripTagMeta(image) | 	image = StripTagMeta(image) | ||||||
|  |  | ||||||
| 	if err := compose.UpdateTag(pattern, image, tag, r.Name); err != nil { | 	ok, err := compose.UpdateTag(pattern, image, tag, r.Name) | ||||||
| 		return err | 	if err != nil { | ||||||
|  | 		return false, err | ||||||
| 	} | 	} | ||||||
| 	return nil |  | ||||||
|  | 	return ok, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // Tags list the recipe tags | // Tags list the recipe tags | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user