Tinkerbell.Sandbox/releases/cmd/getbinariesfromquay/docker/image.go
Jacob Weinstock 6b841fee7c This simplifies the stand-up of a sandbox:
Only 2 main Vagrant calls are now needed (`vagrant up` and `vagrant up machine1`).
This PR only updates the Vagrant Virtualbox setup. The Vagrant Libvirt and Terraform
still need to be updated.

This uses docker-compose as the entry point for standing up the stack and makes the stand-up
of the sandbox more portal. Vagrant and Terraform are only responsible for standing up infrastructure
and then running docker-compose, not for running any glue scripts.

The docker-compose calls out to single-shot services to do all the glue required to get the fully
functional Tinkerbell stack up and running. All the single-shot services are idempotent.
This increases portability and the development iteration loop. This also simplifies the required
steps needed to get a fully functioning sandbox up and running.

This is intended to help people looking to get started by getting them to a provisioned
machine quicker and more easily.

Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
2021-08-09 08:04:06 -06:00

77 lines
1.8 KiB
Go

package docker
import (
"context"
"github.com/containers/image/v5/copy"
"github.com/containers/image/v5/manifest"
"github.com/containers/image/v5/signature"
"github.com/containers/image/v5/transports/alltransports"
"github.com/containers/image/v5/types"
)
type Image struct {
src types.ImageSource
ref types.ImageReference
sys *types.SystemContext
}
func ImageFromName(ctx context.Context, sys *types.SystemContext, name string) (*Image, error) {
imageRef, err := alltransports.ParseImageName(name)
if err != nil {
return nil, err
}
src, err := imageRef.NewImageSource(ctx, sys)
if err != nil {
return nil, err
}
return &Image{
src: src,
ref: imageRef,
sys: sys,
}, nil
}
func (img *Image) GetManifest(ctx context.Context) ([]byte, string, error) {
rawManifest, _, err := img.src.GetManifest(ctx, nil)
if err != nil {
return nil, "", err
}
return rawManifest, manifest.GuessMIMEType(rawManifest), nil
}
func (img *Image) Copy(ctx context.Context, dst string) error {
destRef, err := alltransports.ParseImageName(dst)
if err != nil {
return err
}
pc, err := signature.NewPolicyContext(&signature.Policy{
Default: []signature.PolicyRequirement{
signature.NewPRInsecureAcceptAnything(),
},
})
if err != nil {
return err
}
_, err = copy.Image(ctx, pc, destRef, img.ref, &copy.Options{SourceCtx: img.sys})
if err != nil {
return err
}
return nil
}
type SchemaV2List struct {
MediaType string `json:"mediaType"`
SchemaVersion int `json:"schemaVersion"`
Manifests []struct {
MediaType string `json:"mediaType"`
Digest string `json:"digest"`
Size int `json:"size"`
Platform struct {
Architecture string `json:"architecture"`
Os string `json:"os"`
Variant string `json:"variant"`
} `json:"platform,omitempty"`
} `json:"manifests"`
}