mirror of
https://github.com/labring/sealos.git
synced 2026-09-24 15:46:19 +08:00
feature(main): support auth build (#954)
* feature(main): sealos run repeat exec * feature(main): support auth build * feature(main): support auth build * feature(main): support auth build
This commit is contained in:
@@ -24,7 +24,7 @@ func newPruneCmd() *cobra.Command {
|
||||
Use: "prune",
|
||||
Short: "prune image ",
|
||||
Example: `sealos prune`,
|
||||
Args: cobra.ExactArgs(2),
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
registrySvc, err := image.NewImageService()
|
||||
if err != nil {
|
||||
|
||||
@@ -24,7 +24,7 @@ func newTagCmd() *cobra.Command {
|
||||
Use: "tag",
|
||||
Short: "tag a image as a new one",
|
||||
Example: `sealos tag localhost/oci-kubernetes:1.22.8 registry.cn-hongkong.aliyuncs.com/sealyun/oci-kubernetes:1.22.8`,
|
||||
Args: cobra.NoArgs,
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
registrySvc, err := image.NewImageService()
|
||||
if err != nil {
|
||||
|
||||
@@ -135,7 +135,7 @@ func (c *CreateProcessor) Join(cluster *v2.Cluster) error {
|
||||
}
|
||||
|
||||
func (c *CreateProcessor) RunGuest(cluster *v2.Cluster) error {
|
||||
return c.Guest.Apply(cluster, nil)
|
||||
return c.Guest.Apply(cluster, cluster.Spec.Image)
|
||||
}
|
||||
|
||||
func NewCreateProcessor(clusterFile clusterfile.Interface) (Interface, error) {
|
||||
|
||||
@@ -122,8 +122,11 @@ func (d *ImageService) Build(options *types.BuildOptions, contextDir, imageName
|
||||
return errors.Wrap(err, "load images list failed in this context")
|
||||
}
|
||||
images = append(images, yamlImages...)
|
||||
//TODO add auth
|
||||
is := registry.NewImageSaver(context.Background(), nil)
|
||||
auths, err := registry.GetAuthInfo()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
is := registry.NewImageSaver(context.Background(), auths)
|
||||
platform := strings.Split(options.Platform, "/")
|
||||
var platformVar v1.Platform
|
||||
if len(platform) > 2 {
|
||||
|
||||
@@ -228,7 +228,7 @@ func (is *DefaultImageSaver) saveManifestAndGetDigest(nameds []Named, repo distr
|
||||
|
||||
desc, err := repo.Tags(is.ctx).Get(is.ctx, tmpnamed.tag)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get %s tag descriptor error: %v, try \"docker login\" if you are using a private registry", tmpnamed.repo, err)
|
||||
return fmt.Errorf("get %s tag descriptor error: %v, try \"sealos login\" if you are using a private registry", tmpnamed.repo, err)
|
||||
}
|
||||
imageDigest, err := is.handleManifest(manifest, desc.Digest, platform)
|
||||
if err != nil {
|
||||
|
||||
@@ -17,6 +17,10 @@ package registry
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
fileutil "github.com/fanux/sealos/pkg/utils/file"
|
||||
"k8s.io/apimachinery/pkg/util/json"
|
||||
)
|
||||
|
||||
//this package contains some utils to handle docker image name
|
||||
@@ -87,3 +91,20 @@ func ParseNormalizedNamed(s string) (Named, error) {
|
||||
}
|
||||
return named, nil
|
||||
}
|
||||
|
||||
func GetAuthInfo() (map[string]types.AuthConfig, error) {
|
||||
authFile := "/run/user/0/containers/auth.json"
|
||||
type auths struct {
|
||||
Auths map[string]types.AuthConfig `json:"auths"`
|
||||
}
|
||||
aus := &auths{}
|
||||
data, err := fileutil.ReadAll(authFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(data, aus)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return aus.Auths, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user