58a24a15dd
The alpine provider hosted only remote (proxy) repos; there was no way to publish first-party .apk packages the way rpm-local and deb-local already allow. This extends the existing alpine provider into a real apk repository: uploaded .apk files are parsed in pure Go and a per-arch APKINDEX.tar.gz is generated on demand, at parity with rpm repodata and deb Packages generation. - Implement LocalUploader/LocalIndexer/PostUploadHook/PostDeleteHook on the alpine provider, keeping the remote proxy methods intact. - Parse .apk (concatenated gzipped tar streams) in pure Go: read .PKGINFO from the control stream and compute the apk pull checksum C: = Q1+base64(sha1) over the raw control gzip stream (not the whole file). - Generate an unsigned per-arch APKINDEX.tar.gz (clients use --allow-untrusted), applying the same dot-segment normalization as deb for ./<arch>/... requests. - Add AlpineMetadata plus separate Alpine store/reader/deleter interfaces so the rpm/deb metadata interfaces are not widened. - Add the alpine_metadata table and its Insert/Delete/List DB methods. - Add testsupport.MinimalApk plus unit tests (parse, Q1 checksum, per-arch filtering, dot-segment handling, validate) and a dockere2e index test.
71 lines
2.4 KiB
Go
71 lines
2.4 KiB
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"git.unkin.net/unkin/artifactapi/internal/provider"
|
|
)
|
|
|
|
func (db *DB) InsertAlpineMetadata(ctx context.Context, meta *provider.AlpineMetadata) error {
|
|
_, err := db.Pool.Exec(ctx, `
|
|
INSERT INTO alpine_metadata (
|
|
repo_name, file_path, content_hash, checksum,
|
|
name, version, arch, download_size, installed_size,
|
|
description, url, license, origin, maintainer,
|
|
build_time, commit_hash, provider_priority,
|
|
depends, provides, install_if
|
|
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20)
|
|
ON CONFLICT (repo_name, file_path) DO NOTHING
|
|
`,
|
|
meta.RepoName, meta.FilePath, meta.ContentHash, meta.Checksum,
|
|
meta.Name, meta.Version, meta.Arch, meta.DownloadSize, meta.InstalledSize,
|
|
meta.Description, meta.URL, meta.License, meta.Origin, meta.Maintainer,
|
|
meta.BuildTime, meta.Commit, meta.ProviderPriority,
|
|
strings.Join(meta.Depends, " "), strings.Join(meta.Provides, " "), strings.Join(meta.InstallIf, " "),
|
|
)
|
|
return err
|
|
}
|
|
|
|
func (db *DB) DeleteAlpineMetadata(ctx context.Context, repoName, filePath string) error {
|
|
_, err := db.Pool.Exec(ctx, `DELETE FROM alpine_metadata WHERE repo_name = $1 AND file_path = $2`, repoName, filePath)
|
|
return err
|
|
}
|
|
|
|
func (db *DB) ListAlpineMetadataEntries(ctx context.Context, repoName string) ([]provider.AlpineMetadata, error) {
|
|
rows, err := db.Pool.Query(ctx, `
|
|
SELECT repo_name, file_path, content_hash, checksum,
|
|
name, version, arch, download_size, installed_size,
|
|
description, url, license, origin, maintainer,
|
|
build_time, commit_hash, provider_priority,
|
|
depends, provides, install_if
|
|
FROM alpine_metadata
|
|
WHERE repo_name = $1
|
|
ORDER BY name, version, arch
|
|
`, repoName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
|
|
var result []provider.AlpineMetadata
|
|
for rows.Next() {
|
|
var m provider.AlpineMetadata
|
|
var depends, provides, installIf string
|
|
if err := rows.Scan(
|
|
&m.RepoName, &m.FilePath, &m.ContentHash, &m.Checksum,
|
|
&m.Name, &m.Version, &m.Arch, &m.DownloadSize, &m.InstalledSize,
|
|
&m.Description, &m.URL, &m.License, &m.Origin, &m.Maintainer,
|
|
&m.BuildTime, &m.Commit, &m.ProviderPriority,
|
|
&depends, &provides, &installIf,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
m.Depends = strings.Fields(depends)
|
|
m.Provides = strings.Fields(provides)
|
|
m.InstallIf = strings.Fields(installIf)
|
|
result = append(result, m)
|
|
}
|
|
return result, rows.Err()
|
|
}
|