Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
Signed-off-by: Archit Sharma <[email protected]>
  • Loading branch information
arcolife committed Nov 3, 2023
1 parent 7b99953 commit b76354f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ require (
github.com/mattn/go-isatty v0.0.19
github.com/mholt/archiver/v3 v3.5.1
github.com/microsoft/go-mssqldb v1.6.0
github.com/opencontainers/image-spec v1.1.0-rc4
github.com/oras-project/oras-credentials-go v0.3.0
github.com/pkg/errors v0.9.1
github.com/replicatedhq/termui/v3 v3.1.1-0.20200811145416-f40076d26851
Expand All @@ -48,7 +47,6 @@ require (
k8s.io/cli-runtime v0.28.2
k8s.io/client-go v0.28.2
k8s.io/klog/v2 v2.100.1
oras.land/oras-go v1.2.4-0.20230908093003-773868ab83e0
oras.land/oras-go/v2 v2.3.0
sigs.k8s.io/controller-runtime v0.16.2
sigs.k8s.io/e2e-framework v0.3.0
Expand Down Expand Up @@ -90,6 +88,7 @@ require (
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/onsi/ginkgo v1.14.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/rubenv/sql-migrate v1.3.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand Down
67 changes: 61 additions & 6 deletions pkg/oci/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ import (
"github.com/replicatedhq/troubleshoot/internal/util"
"github.com/replicatedhq/troubleshoot/pkg/version"
"k8s.io/klog/v2"
"oras.land/oras-go/pkg/auth"
dockerauth "oras.land/oras-go/pkg/auth/docker"
"oras.land/oras-go/pkg/content"
"oras.land/oras-go/pkg/oras"
"oras.land/oras-go/pkg/registry"

oras "oras.land/oras-go/v2"
"oras.land/oras-go/v2/content"
"oras.land/oras-go/v2/content/memory"
"oras.land/oras-go/v2/content/oci"
"oras.land/oras-go/v2/registry"
// "github.com/replicatedhq/troubleshoot/pkg/version"
// oras "oras.land/oras-go/v2"
Expand All @@ -35,6 +30,13 @@ import (
"oras.land/oras-go/v2/registry/remote"
"oras.land/oras-go/v2/registry/remote/auth"
// "oras.land/oras-go/v2/registry/remote/retry"
credentials "github.com/oras-project/oras-credentials-go"
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/content"
"oras.land/oras-go/v2/content/oci"
"oras.land/oras-go/v2/registry/remote"
"oras.land/oras-go/v2/registry/remote/auth"
"oras.land/oras-go/v2/registry/remote/retry"
)

const (
Expand All @@ -53,6 +55,59 @@ func PullSupportBundleFromOCI(uri string) ([]byte, error) {
return pullFromOCI(context.Background(), uri, "replicated.supportbundle.spec", "replicated-supportbundle")
}

func pullImage(uri string, mediaType string, imageName string) ([]byte, error) {

// 0. Create an OCI layout store
tempDir, err := os.MkdirTemp("", "oci-layout-root")
if err != nil {
return err
}

store, err := oci.NewLayout(tempDir)
if err != nil {
return err
}

// 1. Connect to a remote repository
ctx := context.Background()
reg := "registry.replicated.com"
repo, err := remote.NewRepository(reg + "/library/replicated")
if err != nil {
return err
}

// 2. Get credentials from the docker credential store
storeOpts := credentials.StoreOptions{}
credStore, err := credentials.NewStoreFromDocker(storeOpts)
if err != nil {
return err
}

// Prepare the auth client for the registry and credential store
repo.Client = &auth.Client{
Client: retry.DefaultClient,
Cache: auth.DefaultCache,
Credential: credentials.Credential(credStore), // Use the credential store
}

// 3. Copy from the remote repository to the OCI layout store
tag := "1.0.0-beta.10"
manifestDescriptor, err := oras.Copy(ctx, repo, tag, store, tag, oras.DefaultCopyOptions)
if err != nil {
return err
}

fmt.Println("manifest pulled:", manifestDescriptor.Digest, manifestDescriptor.MediaType)

// 3. Fetch from OCI layout store to verify
fetched, err := content.FetchAll(ctx, store, manifestDescriptor)
if err != nil {
return err
}
fmt.Printf("manifest content:\n%s", fetched)
return nil
}

// PullSpecsFromOCI pulls both the preflight and support bundle specs from the given URI
//
// The URI is expected to be the same as the one used to install your KOTS application
Expand Down

0 comments on commit b76354f

Please sign in to comment.