feat: v3 Go rewrite — full artifact proxy with web UI, TUI, and Terraform provider
Complete rewrite of ArtifactAPI from Python/FastAPI to Go as a single binary. Core engine: - 10 package providers: generic, docker, helm, pypi, npm, rpm, alpine, puppet, terraform, goproxy — each with built-in mutable patterns - Content-addressable storage (SHA256 dedup across all remotes) - Three-tier caching: Redis (TTL/locks) → S3/MinIO (blobs) → upstream - Classifier with allowlist/blocklist per-remote (empty = allow all) - Circuit breaker, conditional revalidation, stale-on-error - Background garbage collection for orphaned blobs - Access logging to PostgreSQL API: - v1 proxy endpoints (backwards compatible) - v2 management API: CRUD remotes/virtuals, object browser, stats, health, SSE events, probe/test endpoint - Virtual repos with index merging (Helm YAML + PyPI HTML) Frontend (React + Vite, separate Dockerfile): - Dashboard with stats, health indicators, top remotes - Remotes list with type filter, remote detail with config/patterns - Object browser with pagination and evict - Test Remote page: probe any remote path, see headers/size/timing - Virtuals page with expandable member lists TUI (Bubble Tea): - Dashboard, remotes list/detail, object browser, virtuals - Vim-style navigation, artifactapi tui --endpoint <url> Infrastructure: - S3 client supports MinIO, Ceph RGW, AWS S3 (minio-go) - PostgreSQL schema with migrations - Docker Compose: API + UI + Postgres 17 + Redis 7 + MinIO - Makefile with Go version check, build/test/lint/fmt/e2e targets - Distroless Docker image (~15MB) Testing: - Unit tests for models, classifier, providers, mergers - E2E tests with testcontainers-go (real Postgres/Redis/MinIO) Terraform config: - All 40 production remotes + helm virtual as HCL - Provider repo: terraform-provider-artifactapi v0.0.1 (separate)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type Blob struct {
|
||||
ContentHash string `json:"content_hash"`
|
||||
S3Key string `json:"s3_key"`
|
||||
SizeBytes int64 `json:"size_bytes"`
|
||||
ContentType string `json:"content_type"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type Artifact struct {
|
||||
ID int64 `json:"id"`
|
||||
RemoteName string `json:"remote_name"`
|
||||
Path string `json:"path"`
|
||||
ContentHash string `json:"content_hash"`
|
||||
UpstreamETag string `json:"upstream_etag,omitempty"`
|
||||
UpstreamLastModified *time.Time `json:"upstream_last_modified,omitempty"`
|
||||
FirstSeenAt time.Time `json:"first_seen_at"`
|
||||
LastFetchedAt time.Time `json:"last_fetched_at"`
|
||||
LastAccessedAt time.Time `json:"last_accessed_at"`
|
||||
FetchCount int64 `json:"fetch_count"`
|
||||
AccessCount int64 `json:"access_count"`
|
||||
SizeBytes int64 `json:"size_bytes"`
|
||||
ContentType string `json:"content_type,omitempty"`
|
||||
}
|
||||
|
||||
type AccessLogEntry struct {
|
||||
ID int64 `json:"id"`
|
||||
RemoteName string `json:"remote_name"`
|
||||
Path string `json:"path"`
|
||||
CacheHit bool `json:"cache_hit"`
|
||||
SizeBytes int64 `json:"size_bytes"`
|
||||
UpstreamMS int `json:"upstream_ms"`
|
||||
ClientIP string `json:"client_ip"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type LocalFile struct {
|
||||
ID int64 `json:"id"`
|
||||
RepoName string `json:"repo_name"`
|
||||
FilePath string `json:"file_path"`
|
||||
ContentHash string `json:"content_hash"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package models
|
||||
|
||||
import "fmt"
|
||||
|
||||
type PackageType string
|
||||
|
||||
const (
|
||||
PackageGeneric PackageType = "generic"
|
||||
PackageDocker PackageType = "docker"
|
||||
PackageHelm PackageType = "helm"
|
||||
PackagePyPI PackageType = "pypi"
|
||||
PackageNPM PackageType = "npm"
|
||||
PackageRPM PackageType = "rpm"
|
||||
PackageAlpine PackageType = "alpine"
|
||||
PackagePuppet PackageType = "puppet"
|
||||
PackageTerraform PackageType = "terraform"
|
||||
PackageGoProxy PackageType = "goproxy"
|
||||
)
|
||||
|
||||
var validPackageTypes = map[PackageType]bool{
|
||||
PackageGeneric: true,
|
||||
PackageDocker: true,
|
||||
PackageHelm: true,
|
||||
PackagePyPI: true,
|
||||
PackageNPM: true,
|
||||
PackageRPM: true,
|
||||
PackageAlpine: true,
|
||||
PackagePuppet: true,
|
||||
PackageTerraform: true,
|
||||
PackageGoProxy: true,
|
||||
}
|
||||
|
||||
func (p PackageType) Valid() bool {
|
||||
return validPackageTypes[p]
|
||||
}
|
||||
|
||||
func (p PackageType) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func ParsePackageType(s string) (PackageType, error) {
|
||||
pt := PackageType(s)
|
||||
if !pt.Valid() {
|
||||
return "", fmt.Errorf("unknown package type: %q", s)
|
||||
}
|
||||
return pt, nil
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package models_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.unkin.net/unkin/artifactapi/pkg/models"
|
||||
)
|
||||
|
||||
func TestPackageTypeValid(t *testing.T) {
|
||||
valid := []models.PackageType{
|
||||
models.PackageGeneric,
|
||||
models.PackageDocker,
|
||||
models.PackageHelm,
|
||||
models.PackagePyPI,
|
||||
models.PackageNPM,
|
||||
models.PackageRPM,
|
||||
models.PackageAlpine,
|
||||
models.PackagePuppet,
|
||||
models.PackageTerraform,
|
||||
models.PackageGoProxy,
|
||||
}
|
||||
for _, pt := range valid {
|
||||
if !pt.Valid() {
|
||||
t.Errorf("expected %q to be valid", pt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPackageTypeInvalid(t *testing.T) {
|
||||
invalid := []string{"", "bogus", "Docker", "HELM"}
|
||||
for _, s := range invalid {
|
||||
pt := models.PackageType(s)
|
||||
if pt.Valid() {
|
||||
t.Errorf("expected %q to be invalid", s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePackageType(t *testing.T) {
|
||||
pt, err := models.ParsePackageType("docker")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if pt != models.PackageDocker {
|
||||
t.Errorf("expected docker, got %q", pt)
|
||||
}
|
||||
|
||||
_, err = models.ParsePackageType("nope")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for unknown type")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPackageTypeString(t *testing.T) {
|
||||
if models.PackageGoProxy.String() != "goproxy" {
|
||||
t.Errorf("expected 'goproxy', got %q", models.PackageGoProxy.String())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type Remote struct {
|
||||
Name string `json:"name"`
|
||||
PackageType PackageType `json:"package_type"`
|
||||
BaseURL string `json:"base_url"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Username string `json:"-"`
|
||||
Password string `json:"-"`
|
||||
|
||||
ImmutableTTL int `json:"immutable_ttl"`
|
||||
MutableTTL int `json:"mutable_ttl"`
|
||||
CheckMutable bool `json:"check_mutable"`
|
||||
|
||||
Patterns []string `json:"patterns,omitempty"`
|
||||
Blocklist []string `json:"blocklist,omitempty"`
|
||||
MutablePatterns []string `json:"mutable_patterns,omitempty"`
|
||||
ImmutablePatterns []string `json:"immutable_patterns,omitempty"`
|
||||
|
||||
BanTagsEnabled bool `json:"ban_tags_enabled,omitempty"`
|
||||
BanTags []string `json:"ban_tags,omitempty"`
|
||||
|
||||
QuarantineEnabled bool `json:"quarantine_enabled,omitempty"`
|
||||
QuarantineDays int `json:"quarantine_days,omitempty"`
|
||||
|
||||
StaleOnError bool `json:"stale_on_error"`
|
||||
|
||||
ReleasesRemote string `json:"releases_remote,omitempty"`
|
||||
ManagedBy string `json:"managed_by,omitempty"`
|
||||
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type RemoteWithStats struct {
|
||||
Remote
|
||||
Stats RemoteStats `json:"stats"`
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package models
|
||||
|
||||
type RemoteStats struct {
|
||||
ObjectCount int64 `json:"object_count"`
|
||||
TotalBytes int64 `json:"total_bytes"`
|
||||
HitRate30d float64 `json:"hit_rate_30d"`
|
||||
Requests30d int64 `json:"requests_30d"`
|
||||
BandwidthSaved int64 `json:"bandwidth_saved_30d"`
|
||||
}
|
||||
|
||||
type OverviewStats struct {
|
||||
TotalRemotes int `json:"total_remotes"`
|
||||
TotalObjects int64 `json:"total_objects"`
|
||||
TotalBytes int64 `json:"total_bytes"`
|
||||
TotalBlobsDeduped int64 `json:"total_blobs_deduped"`
|
||||
BandwidthSaved30d int64 `json:"bandwidth_saved_30d"`
|
||||
}
|
||||
|
||||
type RemoteHealth struct {
|
||||
Status string `json:"status"` // healthy, degraded, down
|
||||
LastError string `json:"last_error,omitempty"`
|
||||
ConsecutiveFailures int `json:"consecutive_failures"`
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type Virtual struct {
|
||||
Name string `json:"name"`
|
||||
PackageType PackageType `json:"package_type"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Members []string `json:"members"`
|
||||
ManagedBy string `json:"managed_by,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
Reference in New Issue
Block a user