1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-10-05 19:30:58 +00:00
forgejo/routers/api/packages
oliverpool 3de4b351a2 [v11.0/forgejo] storage test: reader should not be closed on save (#9031)
Backport of the fixes for #8529 (v11 is currently not affected because minio-client is an older version. Porting the tests should help in preventing future breakages).

- #8541: storage test (reader should not get closed)
- #8527 #8816: defer uploader.Close (most robust way)
- #8166: enable storage tests

The test can be run locally:

```
docker run --rm -e MINIO_DOMAIN=minio -e MINIO_ROOT_USER=123456 -e MINIO_ROOT_PASSWORD=12345678 -p 9000:9000  data.forgejo.org/oci/bitnami/minio:2024.8.17
```

```
TEST_MINIO_ENDPOINT=localhost:9000  go test -v -run ^TestMinioStorageIterator$ ./modules/storage
```

### Release notes

- [x] I do not want this change to show in the release notes.
- [ ] I want the title to show in the release notes with a link to this pull request.
- [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title.

Co-authored-by: Earl Warren <contact@earl-warren.org>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9031
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: oliverpool <git@olivier.pfad.fr>
Co-committed-by: oliverpool <git@olivier.pfad.fr>
2025-08-26 10:20:00 +02:00
..
alpine [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
alt [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
arch [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
cargo [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
chef [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
composer [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
conan [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
conda [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
container [v11.0/forgejo] storage test: reader should not be closed on save (#9031) 2025-08-26 10:20:00 +02:00
cran [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
debian [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
generic [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
goproxy [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
helm [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
helper [v11.0/forgejo] fix(packages): skip another stack frame from logging (#8531) 2025-07-16 20:14:09 +02:00
maven [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
npm [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
nuget [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
pub [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
pypi [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
rpm [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
rubygems [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
swift [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
vagrant [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
api.go [v11.0/forgejo] chore: branding import path (#7354) 2025-03-27 20:13:05 +00:00
README.md Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00

Gitea Package Registry

This document gives a brief overview how the package registry is organized in code.

Structure

The package registry code is divided into multiple modules to split the functionality and make code reuse possible.

Module Description
models/packages Common methods and models used by all registry types
models/packages/<type> Methods used by specific registry type. There should be no need to use type specific models.
modules/packages Common methods and types used by multiple registry types
modules/packages/<type> Registry type specific methods and types (e.g. metadata extraction of package files)
routers/api/packages Route definitions for all registry types
routers/api/packages/<type> Route implementation for a specific registry type
services/packages Helper methods used by registry types to handle common tasks like package creation and deletion in routers
services/packages/<type> Registry type specific methods used by routers and services

Models

Every package registry implementation uses the same underlying models:

Model Description
Package The root of a package providing values fixed for every version (e.g. the package name)
PackageVersion A version of a package containing metadata (e.g. the package description)
PackageFile A file of a package describing its content (e.g. file name)
PackageBlob The content of a file (may be shared by multiple files)
PackageProperty Additional properties attached to Package, PackageVersion or PackageFile (e.g. used if metadata is needed for routing)

The following diagram shows the relationship between the models:

Package <1---*> PackageVersion <1---*> PackageFile <*---1> PackageBlob

Adding a new package registry type

Before adding a new package registry type have a look at the existing implementation to get an impression of how it could work. Most registry types offer endpoints to retrieve the metadata, upload and download package files. The upload endpoint is often the heavy part because it must validate the uploaded blob, extract metadata and create the models. The methods to validate and extract the metadata should be added in the modules/packages/<type> package. If the upload is valid the methods in services/packages allow to store the upload and create the corresponding models. It depends if the registry type allows multiple files per package version which method should be called:

  • CreatePackageAndAddFile: error if package version already exists
  • CreatePackageOrAddFileToExisting: error if file already exists
  • AddFileToExistingPackage: error if package version does not exist or file already exists

services/packages also contains helper methods to download a file or to remove a package version. There are no helper methods for metadata endpoints because they are very type specific.