Feat/v3 go rewrite (#47)
ci/woodpecker/tag/docker Pipeline was successful

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)

---------

Co-authored-by: Ben Vincent <ben@unkin.net>
Reviewed-on: #47
This commit was merged in pull request #47.
This commit is contained in:
2026-06-07 19:30:35 +10:00
parent f25bf6cb29
commit b46c116f6b
160 changed files with 11448 additions and 7907 deletions
+76
View File
@@ -0,0 +1,76 @@
package client
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
)
type Client struct {
baseURL string
httpClient *http.Client
}
func New(baseURL string) *Client {
return &Client{
baseURL: baseURL,
httpClient: http.DefaultClient,
}
}
func (c *Client) get(ctx context.Context, path string, out any) error {
return c.do(ctx, http.MethodGet, path, nil, out)
}
func (c *Client) post(ctx context.Context, path string, body any, out any) error {
return c.do(ctx, http.MethodPost, path, body, out)
}
func (c *Client) put(ctx context.Context, path string, body any, out any) error {
return c.do(ctx, http.MethodPut, path, body, out)
}
func (c *Client) delete(ctx context.Context, path string) error {
return c.do(ctx, http.MethodDelete, path, nil, nil)
}
func (c *Client) do(ctx context.Context, method, path string, body any, out any) error {
var bodyReader io.Reader
if body != nil {
b, err := json.Marshal(body)
if err != nil {
return fmt.Errorf("marshal: %w", err)
}
bodyReader = bytes.NewReader(b)
}
req, err := http.NewRequestWithContext(ctx, method, c.baseURL+path, bodyReader)
if err != nil {
return fmt.Errorf("request: %w", err)
}
if body != nil {
req.Header.Set("Content-Type", "application/json")
}
resp, err := c.httpClient.Do(req)
if err != nil {
return fmt.Errorf("do: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
b, _ := io.ReadAll(resp.Body)
return fmt.Errorf("api error %d: %s", resp.StatusCode, b)
}
if out != nil && resp.StatusCode != http.StatusNoContent {
if err := json.NewDecoder(resp.Body).Decode(out); err != nil {
return fmt.Errorf("decode: %w", err)
}
}
return nil
}
+32
View File
@@ -0,0 +1,32 @@
package client
import (
"context"
"fmt"
"git.unkin.net/unkin/artifactapi/pkg/models"
)
func (c *Client) ListRemotes(ctx context.Context) ([]models.Remote, error) {
var remotes []models.Remote
err := c.get(ctx, "/api/v2/remotes", &remotes)
return remotes, err
}
func (c *Client) GetRemote(ctx context.Context, name string) (*models.Remote, error) {
var remote models.Remote
err := c.get(ctx, fmt.Sprintf("/api/v2/remotes/%s", name), &remote)
return &remote, err
}
func (c *Client) CreateRemote(ctx context.Context, r *models.Remote) error {
return c.post(ctx, "/api/v2/remotes", r, r)
}
func (c *Client) UpdateRemote(ctx context.Context, r *models.Remote) error {
return c.put(ctx, fmt.Sprintf("/api/v2/remotes/%s", r.Name), r, r)
}
func (c *Client) DeleteRemote(ctx context.Context, name string) error {
return c.delete(ctx, fmt.Sprintf("/api/v2/remotes/%s", name))
}
+30
View File
@@ -0,0 +1,30 @@
package client
import (
"context"
"fmt"
"git.unkin.net/unkin/artifactapi/pkg/models"
)
func (c *Client) Stats(ctx context.Context) (*models.OverviewStats, error) {
var stats models.OverviewStats
err := c.get(ctx, "/api/v2/stats", &stats)
return &stats, err
}
func (c *Client) Health(ctx context.Context) (*models.RemoteHealth, error) {
var health models.RemoteHealth
err := c.get(ctx, "/api/v2/health", &health)
return &health, err
}
func (c *Client) ListObjects(ctx context.Context, remote string, page, perPage int) ([]models.Artifact, error) {
var artifacts []models.Artifact
err := c.get(ctx, fmt.Sprintf("/api/v2/remotes/%s/objects?page=%d&per_page=%d", remote, page, perPage), &artifacts)
return artifacts, err
}
func (c *Client) EvictObject(ctx context.Context, remote, path string) error {
return c.delete(ctx, fmt.Sprintf("/api/v2/remotes/%s/objects/%s", remote, path))
}
+32
View File
@@ -0,0 +1,32 @@
package client
import (
"context"
"fmt"
"git.unkin.net/unkin/artifactapi/pkg/models"
)
func (c *Client) ListVirtuals(ctx context.Context) ([]models.Virtual, error) {
var virtuals []models.Virtual
err := c.get(ctx, "/api/v2/virtuals", &virtuals)
return virtuals, err
}
func (c *Client) GetVirtual(ctx context.Context, name string) (*models.Virtual, error) {
var virt models.Virtual
err := c.get(ctx, fmt.Sprintf("/api/v2/virtuals/%s", name), &virt)
return &virt, err
}
func (c *Client) CreateVirtual(ctx context.Context, v *models.Virtual) error {
return c.post(ctx, "/api/v2/virtuals", v, v)
}
func (c *Client) UpdateVirtual(ctx context.Context, v *models.Virtual) error {
return c.put(ctx, fmt.Sprintf("/api/v2/virtuals/%s", v.Name), v, v)
}
func (c *Client) DeleteVirtual(ctx context.Context, name string) error {
return c.delete(ctx, fmt.Sprintf("/api/v2/virtuals/%s", name))
}
+38
View File
@@ -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"`
}
+11
View File
@@ -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"`
}
+47
View File
@@ -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
}
+58
View File
@@ -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())
}
}
+40
View File
@@ -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"`
}
+23
View File
@@ -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"`
}
+13
View File
@@ -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"`
}