imagelife

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package imagelife builds the image inventory of a node, decides which images retention may free, and verifies image signatures. Nothing here talks to Docker: callers pass records in and execute the plans.

Index

Constants

View Source
const (
	RoleLive           = "live"
	RoleRollbackTarget = "rollback_target"
	RoleRecent         = "recent"
	RoleHistory        = "history"
)

Roles an app can have for an image.

Variables

View Source
var ErrNoSignature = errors.New("no signature found for this image")

ErrNoSignature means the registry holds no signature for the image.

Functions

func DigestOfRecord

func DigestOfRecord(r docker.ImageRecord) string

DigestOfRecord returns the registry digest of r, or "" for a local build.

func ParsePublicKey

func ParsePublicKey(pemData []byte) (*ecdsa.PublicKey, error)

ParsePublicKey reads a PEM encoded ECDSA public key.

func RemoveRefs

func RemoveRefs(e Entry) []string

RemoveRefs returns the references to delete, in order, to free e: each tag, or the ID for an untagged image.

func SignPayload

func SignPayload(priv *ecdsa.PrivateKey, repo, digest string) (payload []byte, sigB64 string, err error)

SignPayload builds the signed payload and signature for digest. It exists so tests and tooling can produce what Verify consumes.

Types

type AppState

type AppState struct {
	Name        string
	LiveImage   string
	LiveImageID string
	// Attempts is newest first.
	Attempts []Attempt
	Pins     []Pin
}

AppState is what one app contributes to the inventory.

type AppUse

type AppUse struct {
	App       string    `json:"app"`
	Role      string    `json:"role"`
	DeployID  string    `json:"deploy_id,omitempty"`
	Source    string    `json:"source,omitempty"`
	CommitSHA string    `json:"commit_sha,omitempty"`
	Branch    string    `json:"branch,omitempty"`
	At        time.Time `json:"at,omitempty"`
}

AppUse says how an app relates to one image.

type Attempt

type Attempt struct {
	ID        string
	Image     string
	Digest    string
	Source    string
	CommitSHA string
	Branch    string
	Status    string
	StartedAt time.Time
}

Attempt is the slice of a deploy attempt the inventory needs.

type Credentials

type Credentials struct{ Username, Password string }

Credentials authenticate registry reads.

type Entry

type Entry struct {
	ID            string    `json:"id"`
	Digest        string    `json:"digest,omitempty"`
	Tags          []string  `json:"tags"`
	SizeBytes     int64     `json:"size_bytes"`
	SharedBytes   int64     `json:"shared_bytes"`
	Containers    int64     `json:"containers"`
	CreatedAt     time.Time `json:"created_at"`
	Apps          []AppUse  `json:"apps"`
	Protected     bool      `json:"protected"`
	ProtectReason string    `json:"protect_reason,omitempty"`
}

Entry is one image with its owners and retention status.

func Build

func Build(records []docker.ImageRecord, apps []AppState, keepPerApp int, minAge time.Duration, now time.Time) []Entry

Build joins image records with app deploy history. keepPerApp is how many newest succeeded deploys per app count as "recent" and stay protected. Entries come back biggest first.

type Pin

type Pin struct {
	DeployID string
	Image    string
	ImageID  string
	PinRef   string
}

Pin is a rollback pin: an image kept alive as a rollback target.

type Plan

type Plan struct {
	Remove       []Entry `json:"remove"`
	ReclaimBytes int64   `json:"reclaim_bytes"`
	KeptCount    int     `json:"kept_count"`
}

Plan is the outcome of retention: what would be freed and what is kept.

func PlanGC

func PlanGC(entries []Entry) Plan

PlanGC selects every unprotected entry. Protected images are never in Remove, whatever the policy says.

type Verifier

type Verifier struct {
	HTTP *http.Client
}

Verifier checks cosign key-based signatures (ECDSA P-256) stored beside the image in its registry as a sha256-<digest>.sig tag.

func NewVerifier

func NewVerifier() *Verifier

NewVerifier returns a Verifier with a bounded HTTP timeout.

func (*Verifier) Verify

func (v *Verifier) Verify(ctx context.Context, ref string, pub *ecdsa.PublicKey, creds Credentials) error

Verify checks that ref (repo@sha256:...) carries a signature made by pub.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL