mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-24 06:28:13 +01:00
* Leave default image platform empty for static provider (see FAQ doc) * Handle platform variant * Add database migration process * Switch to Open Container Specification labels as label-schema.org ones are deprecated * Remove unneeded `diun.os` and `diun.arch` docker labels Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package registry
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/containers/image/v5/manifest"
|
|
"github.com/opencontainers/go-digest"
|
|
)
|
|
|
|
// Manifest is the Docker image manifest information
|
|
type Manifest struct {
|
|
Name string
|
|
Tag string
|
|
MIMEType string
|
|
Digest digest.Digest
|
|
Created *time.Time
|
|
DockerVersion string
|
|
Labels map[string]string
|
|
Layers []string
|
|
Platform string `json:"-"`
|
|
}
|
|
|
|
// Manifest returns the manifest for a specific image
|
|
func (c *Client) Manifest(image Image) (Manifest, error) {
|
|
ctx, cancel := c.timeoutContext()
|
|
defer cancel()
|
|
|
|
imgCloser, err := c.newImage(ctx, image.String())
|
|
if err != nil {
|
|
return Manifest{}, err
|
|
}
|
|
defer imgCloser.Close()
|
|
|
|
rawManifest, _, err := imgCloser.Manifest(ctx)
|
|
if err != nil {
|
|
return Manifest{}, err
|
|
}
|
|
|
|
imgInspect, err := imgCloser.Inspect(ctx)
|
|
if err != nil {
|
|
return Manifest{}, err
|
|
}
|
|
|
|
imgDigest, err := manifest.Digest(rawManifest)
|
|
if err != nil {
|
|
return Manifest{}, err
|
|
}
|
|
|
|
imgTag := imgInspect.Tag
|
|
if imgTag == "" {
|
|
imgTag = image.Tag
|
|
}
|
|
|
|
imgPlatform := fmt.Sprintf("%s/%s", imgInspect.Os, imgInspect.Architecture)
|
|
if imgInspect.Variant != "" {
|
|
imgPlatform = fmt.Sprintf("%s/%s", imgPlatform, imgInspect.Variant)
|
|
}
|
|
|
|
return Manifest{
|
|
Name: imgCloser.Reference().DockerReference().Name(),
|
|
Tag: imgTag,
|
|
MIMEType: manifest.GuessMIMEType(rawManifest),
|
|
Digest: imgDigest,
|
|
Created: imgInspect.Created,
|
|
DockerVersion: imgInspect.DockerVersion,
|
|
Labels: imgInspect.Labels,
|
|
Layers: imgInspect.Layers,
|
|
Platform: imgPlatform,
|
|
}, nil
|
|
}
|