Conversation
Considered Alternative ApproachI considered another way to handle Maven snapshot cleanup that uses the This method would need a database migration to work, so it's a bit more complicated. I have the code ready for this alternative if we think it's worth the extra steps later on. |
|
Note to any reviewer: Review this PR carefully. |
|
A remark: Yes, it's true that I used ChatGPT for help since I'm not an experienced Go developer, but I handled the core logic and testing myself. I'd appreciate any comments or critiques to help us improve this, as we really need the feature :)
|
| } | ||
|
|
||
| // ParseMavenMetadata parses the Maven metadata XML to extract the build number. | ||
| func ParseMavenMetaData(r io.Reader) (string, error) { |
There was a problem hiding this comment.
I am thoroughly confused by this method signature and docs: Nothing indicates to me that this method parses the entire XML, and throws the result except for the build number away.
There was a problem hiding this comment.
I've changed the signature and added a new snapshotMetadata type which can be extended later, does it make it more readable?
|
The feature is tested, but few adjustments need to be done:
Will be happy to hear any suggestions! |
|
All considerable maven repositories offer a clean-up function, since it's common to have a lot of builds using a snapshot version, until the new version is finished. Therefore, it's essential to get this PR merged now @delvh and @lunny. Otherwise, snapshot versions pile up and use a lot of unnecessary disk space. |
|
Some adjustments are still required to get the CI passing. |
feec06e to
0a87583
Compare
c630dc2 to
2b11911
Compare
|
The test for cleanup snapshot versions and code are working, the tests are failing due to: services/packages/cleanup/cleanup.go:28:6: exported: func name will be used as cleanup.CleanupTask by other packages, and that stutters; consider calling this Task (revive)
func CleanupTask(ctx context.Context, olderThan time.Duration) error {
^
services/packages/cleanup/cleanup.go:168:6: exported: func name will be used as cleanup.CleanupExpiredData by other packages, and that stutters; consider calling this ExpiredData (revive)
func CleanupExpiredData(ctx context.Context, olderThan time.Duration)@lunny as this is code was introduced earlier, should I still adapt it to make the tests pass? |
Yes. We have to fix all the lint errors before merge. |
50c605b to
adbe41c
Compare
|
This feature would be very helpful and save a lot of space, reducing snapshot sizes by around a factor of 5. |
Hi @HoffmannTom ! Thank you for the interest :) Yes, I'll solve lint problem in the next commit, just need a bit more testing time as it will be bundled with "rebuild metadata" feature. |
|
Hi @dianaStr7 Ein Servus nach Minga 👋 |
4666eff to
0443d70
Compare
Add configurable retention and dry-run settings for Maven snapshot artifacts.
|
I have to apply this PR since 1.5 years to all new gitea versions. It runs perfectly. Any chance to merge it now @lunny? |
|
Yes - please! |
|
ping @delvh |
Move Maven specific parsing out of models, run the cleanup outside the shared cleanup transaction, derive retained builds from stored files, protect files referenced by maven-metadata.xml including signatures and drop the DEBUG_MAVEN_CLEANUP setting.
|
I pushed a cleanup of the snapshot retention logic:
|
| } | ||
|
|
||
| func CleanupExpiredData(ctx context.Context, olderThan time.Duration) error { | ||
| if err := maven_service.CleanupSnapshotVersions(ctx); err != nil { |
There was a problem hiding this comment.
Hmm… Should that be a part of the overall transaction, or should it be a separate command?
No idea which is better.
| {"test-project-1.0-20230101.000000-3-sources.jar", true}, | ||
| {"test-project-1.0-20230101.000000-3-sources.jar.asc", true}, |
There was a problem hiding this comment.
Wait, why are the sources kept?
Shouldn't they be deleted too?
|
|
||
| pvs, _, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{ | ||
| Type: packages_model.TypeMaven, | ||
| Version: packages_model.SearchValue{Value: "%-snapshot"}, |
| return !ok || build > threshold || slices.ContainsFunc(referenced, func(v maven_module.SnapshotVersion) bool { | ||
| name := v.FileName(metadata.ArtifactID) | ||
| return pf.Name == name || strings.HasPrefix(pf.Name, name+".") // keep signatures like .asc | ||
| }) |
There was a problem hiding this comment.
I don't quite understand this retain.
Conceptually, the retain condition is ok && build < threshold, right?
Why would we want to keep signatures? And what's up with the filename check?
Pull Request: Implement Cleanup Function for Maven Snapshot Versions
Overview
This pull request introduces a cleanup function for Maven snapshot versions in Gitea, enabling more efficient management of package storage. The new feature allows users to specify how many of the most recent Maven snapshot builds to retain, optimizing storage by automatically removing older files.
Features
RETAIN_MAVEN_SNAPSHOT_BUILDSallows setting the number of Maven snapshot builds to keep.-1, which keeps all builds.Implementation
The feature extends the existing cleanup job to include files from Maven snapshot versions based on the specified retention policy set in
app.ini. It checks against the highest build number from the Maven metadata file to determine which files to retain.Impact
This enhancement helps manage disk space more effectively by providing control over how many builds of Maven snapshots are retained, potentially reducing storage requirements for projects using Maven within Gitea.