feat: add update for debian release
This commit is contained in:
		
							
								
								
									
										2
									
								
								.github/workflows/debian-cache.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/debian-cache.yml
									
									
									
									
										vendored
									
									
								
							| @@ -25,7 +25,7 @@ jobs: | |||||||
|       run: go build |       run: go build | ||||||
|  |  | ||||||
|     - name: Cache |     - name: Cache | ||||||
|       run: ./out-of-tree --log-level=trace distro debian cache --refetch=0 --limit=128 |       run: ./out-of-tree --log-level=trace distro debian cache --refetch=0 --limit=128 --update-release | ||||||
|  |  | ||||||
|     - name: Install s3cmd |     - name: Install s3cmd | ||||||
|       run: sudo apt install s3cmd |       run: sudo apt install s3cmd | ||||||
|   | |||||||
							
								
								
									
										16
									
								
								distro.go
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								distro.go
									
									
									
									
									
								
							| @@ -36,9 +36,10 @@ type DebianCmd struct { | |||||||
| } | } | ||||||
|  |  | ||||||
| type DebianCacheCmd struct { | type DebianCacheCmd struct { | ||||||
| 	Path    string `help:"path to cache"` | 	Path          string `help:"path to cache"` | ||||||
| 	Refetch int    `help:"days before refetch versions without deb package" default:"7"` | 	Refetch       int    `help:"days before refetch versions without deb package" default:"7"` | ||||||
| 	Dump    bool   `help:"dump cache"` | 	UpdateRelease bool   `help:"update release data"` | ||||||
|  | 	Dump          bool   `help:"dump cache"` | ||||||
| } | } | ||||||
|  |  | ||||||
| func (cmd *DebianCacheCmd) Run(dcmd *DebianCmd) (err error) { | func (cmd *DebianCacheCmd) Run(dcmd *DebianCmd) (err error) { | ||||||
| @@ -53,7 +54,12 @@ func (cmd *DebianCacheCmd) Run(dcmd *DebianCmd) (err error) { | |||||||
| 		dcmd.Limit = math.MaxInt32 | 		dcmd.Limit = math.MaxInt32 | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	kernels, err := debian.GetKernelsWithLimit(dcmd.Limit) | 	mode := debian.NoMode | ||||||
|  | 	if cmd.UpdateRelease { | ||||||
|  | 		mode = debian.UpdateRelease | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	kernels, err := debian.GetKernelsWithLimit(dcmd.Limit, mode) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Error().Err(err).Msg("") | 		log.Error().Err(err).Msg("") | ||||||
| 		return | 		return | ||||||
| @@ -162,7 +168,7 @@ func (cmd *DebianFetchCmd) Run(dcmd *DebianCmd) (err error) { | |||||||
| 		dcmd.Limit = math.MaxInt32 | 		dcmd.Limit = math.MaxInt32 | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	kernels, err := debian.GetKernelsWithLimit(dcmd.Limit) | 	kernels, err := debian.GetKernelsWithLimit(dcmd.Limit, debian.NoMode) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Error().Err(err).Msg("") | 		log.Error().Err(err).Msg("") | ||||||
| 		return | 		return | ||||||
|   | |||||||
| @@ -261,7 +261,8 @@ func findKbuild(versions []string, kpkgver string) ( | |||||||
| } | } | ||||||
|  |  | ||||||
| func getKernelsByVersion(slog zerolog.Logger, c *Cache, toolsVersions []string, | func getKernelsByVersion(slog zerolog.Logger, c *Cache, toolsVersions []string, | ||||||
| 	version string) (kernels []DebianKernel, fromcache bool) { | 	version string, mode GetKernelsMode) (kernels []DebianKernel, | ||||||
|  | 	fromcache bool) { | ||||||
|  |  | ||||||
| 	var dk DebianKernel | 	var dk DebianKernel | ||||||
| 	dks, err := c.Get(version) | 	dks, err := c.Get(version) | ||||||
| @@ -269,6 +270,18 @@ func getKernelsByVersion(slog zerolog.Logger, c *Cache, toolsVersions []string, | |||||||
| 		dk = dks[0] | 		dk = dks[0] | ||||||
| 		if !dk.Internal.Invalid { | 		if !dk.Internal.Invalid { | ||||||
| 			slog.Trace().Msgf("found in cache") | 			slog.Trace().Msgf("found in cache") | ||||||
|  | 			if dk.Release == None && mode&UpdateRelease != 0 { | ||||||
|  | 				slog.Debug().Msg("update release") | ||||||
|  | 				dk.Release = getRelease(dk.Image) | ||||||
|  | 				if dk.Release != None { | ||||||
|  | 					slog.Debug().Msg("update cache") | ||||||
|  | 					err = c.Put([]DebianKernel{dk}) | ||||||
|  | 					if err != nil { | ||||||
|  | 						slog.Error().Err(err).Msg("") | ||||||
|  | 						return | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
| 			kernels = append(kernels, dk) | 			kernels = append(kernels, dk) | ||||||
| 			fromcache = true | 			fromcache = true | ||||||
| 			return | 			return | ||||||
| @@ -338,9 +351,18 @@ var ( | |||||||
| 	RefetchDays int = 14 | 	RefetchDays int = 14 | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | type GetKernelsMode int | ||||||
|  |  | ||||||
|  | const ( | ||||||
|  | 	NoMode GetKernelsMode = iota | ||||||
|  | 	UpdateRelease | ||||||
|  | ) | ||||||
|  |  | ||||||
| // GetKernelsWithLimit is workaround for testing and building the | // GetKernelsWithLimit is workaround for testing and building the | ||||||
| // first cache, which is heavily rate limited by snapshot.debian.org | // first cache, which is heavily rate limited by snapshot.debian.org | ||||||
| func GetKernelsWithLimit(limit int) (kernels []DebianKernel, err error) { | func GetKernelsWithLimit(limit int, mode GetKernelsMode) (kernels []DebianKernel, | ||||||
|  | 	err error) { | ||||||
|  |  | ||||||
| 	if CachePath == "" { | 	if CachePath == "" { | ||||||
| 		CachePath = config.File("debian.cache") | 		CachePath = config.File("debian.cache") | ||||||
| 		log.Debug().Msgf("Use default kernels cache path: %s", CachePath) | 		log.Debug().Msgf("Use default kernels cache path: %s", CachePath) | ||||||
| @@ -385,7 +407,7 @@ func GetKernelsWithLimit(limit int) (kernels []DebianKernel, err error) { | |||||||
| 	for i, version := range versions { | 	for i, version := range versions { | ||||||
| 		slog := log.With().Str("version", version).Logger() | 		slog := log.With().Str("version", version).Logger() | ||||||
| 		slog.Trace().Msgf("%03d/%03d", i, len(versions)) | 		slog.Trace().Msgf("%03d/%03d", i, len(versions)) | ||||||
| 		vkernels, fromcache := getKernelsByVersion(slog, c, toolsVersions, version) | 		vkernels, fromcache := getKernelsByVersion(slog, c, toolsVersions, version, mode) | ||||||
| 		kernels = append(kernels, vkernels...) | 		kernels = append(kernels, vkernels...) | ||||||
| 		if !fromcache { | 		if !fromcache { | ||||||
| 			limit-- | 			limit-- | ||||||
| @@ -399,5 +421,5 @@ func GetKernelsWithLimit(limit int) (kernels []DebianKernel, err error) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func GetKernels() (kernels []DebianKernel, err error) { | func GetKernels() (kernels []DebianKernel, err error) { | ||||||
| 	return GetKernelsWithLimit(math.MaxInt32) | 	return GetKernelsWithLimit(math.MaxInt32, NoMode) | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user