Skip to content

Commit

Permalink
fix: dynamic plugin should support pulling image with digest (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
susanshi authored Jan 29, 2024
1 parent 2be797d commit 82626ee
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
9 changes: 6 additions & 3 deletions pkg/common/plugin/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@ func DownloadPlugin(source PluginSource, targetPath string) error {
return fmt.Errorf("unsupported manifest media type: %s", referenceManifestDescriptor.MediaType)
}

if len(referenceManifest.Blobs) == 0 {
return fmt.Errorf("no blobs found in the manifest")
}

// download the first blob to the target path
blobReference := fmt.Sprintf("%s@%s", source, referenceManifest.Blobs[0].Digest)
logrus.Debugf("Downloading blob %s", blobReference)
_, blobReader, err := repository.Blobs().FetchReference(ctx, blobReference)
logrus.Debugf("Downloading blob %s", referenceManifest.Blobs[0].Digest.String())
_, blobReader, err := repository.Blobs().FetchReference(ctx, referenceManifest.Blobs[0].Digest.String())
if err != nil {
return err
}
Expand Down
64 changes: 41 additions & 23 deletions pkg/referrerstore/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,37 +95,55 @@ func TestCreateStoresFromConfig_PluginStores_ReturnsExpected(t *testing.T) {
func TestCreateStoresFromConfig_DynamicPluginStores_ReturnsExpected(t *testing.T) {
os.Setenv("RATIFY_EXPERIMENTAL_DYNAMIC_PLUGINS", "1")
featureflag.InitFeatureFlagsFromEnv()
storeConfig := map[string]interface{}{
"name": "plugin-store",
"source": map[string]interface{}{
"artifact": "wabbitnetworks.azurecr.io/test/sample-verifier-plugin:v1",
testCases := []struct {
name string
artifact string
}{
{
name: "image specified by tag",
artifact: "wabbitnetworks.azurecr.io/test/sample-store-plugin:v1",
},
{
name: "image specified by digest",
artifact: "wabbitnetworks.azurecr.io/test/sample-store-plugin@sha256:96ba9f9636cde32df87d62dcad4e430d055e708b9f173475c5d7468b732d6566",
},
}

storesConfig := config.StoresConfig{
Stores: []config.StorePluginConfig{storeConfig},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
storeConfig := map[string]interface{}{
"name": "plugin-store",
"source": map[string]interface{}{
"artifact": tc.artifact,
},
}

stores, err := CreateStoresFromConfig(storesConfig, "")
storesConfig := config.StoresConfig{
Stores: []config.StorePluginConfig{storeConfig},
}

if err != nil {
t.Fatalf("create stores failed with err %v", err)
}
stores, err := CreateStoresFromConfig(storesConfig, "")

if len(stores) != 1 {
t.Fatalf("expected to have %d stores, actual count %d", 1, len(stores))
}
if err != nil {
t.Fatalf("create stores failed with err %v", err)
}

if stores[0].Name() != "plugin-store" {
t.Fatalf("expected to create plugin store")
}
if len(stores) != 1 {
t.Fatalf("expected to have %d stores, actual count %d", 1, len(stores))
}

if _, ok := stores[0].(*plugin.StorePlugin); !ok {
t.Fatalf("type assertion failed expected a plugin store")
}
if stores[0].Name() != "plugin-store" {
t.Fatalf("expected to create plugin store")
}

if _, ok := stores[0].(*plugin.StorePlugin); !ok {
t.Fatalf("type assertion failed expected a plugin store")
}

pluginPath := path.Join(stores[0].GetConfig().PluginBinDirs[0], stores[0].Name())
if _, err := os.Stat(pluginPath); errors.Is(err, os.ErrNotExist) {
t.Fatalf("downloaded plugin not found in path")
pluginPath := path.Join(stores[0].GetConfig().PluginBinDirs[0], stores[0].Name())
if _, err := os.Stat(pluginPath); errors.Is(err, os.ErrNotExist) {
t.Fatalf("downloaded plugin not found in path")
}
})
}
}

0 comments on commit 82626ee

Please sign in to comment.