ortelius / emporous-go

Emporous client libraries and CLI implementation
https://emporous.io/
Apache License 2.0
18 stars 10 forks source link

feat: modifies collection manifest to incorporate base attributes #117

Closed jpower432 closed 1 year ago

jpower432 commented 1 year ago

Description

This breaking change alters how linked collections and attributes are represented in the collection manifest. This also incorporates the new type called descriptor Properties that contain core attributes.

This also closes #67 because the list attributes functionality demonstrates the filtering on core attributes at the manifest level.

Type of change

How To Test

Before testing, please clear the UOR build cache or use an alternate location with export UOR_CACHE=myloc. This version of the client cannot process previously published collections because of a manifest spec change.

  1. Create a new directory called schemas within the exercises directory and change into this directory
mkdir -p ${UOR_CLIENT_GO_REPO}/exercises/schema
cd ${UOR_CLIENT_GO_REPO}/exercises/schema
  1. Create a schema-config.yaml file with the following contents to define the schema for the collection:
cat << EOF > schema-config.yaml
kind: SchemaConfiguration
apiVersion: client.uor-framework.io/v1alpha1
schema:
  id: myapplication
  attributeTypes:
    "name": string
    "majorVersion": integer
    "minorVersion": integer
EOF
  1. Build and push the schema to the remote registry
uor-client-go build schema schema-config.yaml localhost:5000/exercises/applicationschema:latest
uor-client-go push --plain-http localhost:5000/exercises/applicationschema:latest
  1. To demonstrate collection publish, create a leaf collection by creating a workspace directory called helloworld-workspace.
mkdir helloworld-workspace
  1. Create a simple Go application called helloworld within the workspace:
cat << EOF > main.go
package main

import "fmt"

func main() {
    fmt.Println("Hello World")
}
EOF
go build -o helloworld-workspace/helloworld main.go

Add a test file to the workspace to demonstrate filtering

echo "test" > helloworld-workspace/test.txt
  1. Create the Dataset Configuration within a file called helloworld-dataset-config.yaml with the following content:
cat << EOF > helloworld-dataset-config.yaml
kind: DataSetConfiguration
apiVersion: client.uor-framework.io/v1alpha1
collection:
  schemaAddress: localhost:5000/exercises/applicationschema:latest
  runtime:
    Cmd:
      - "./helloworld"
  files:
    - file: "*helloworld"
      attributes:
        name: "helloworld"
        majorVersion: 1
        minorVersion: 0
EOF
  1. Build and push the helloworld collection to the remote registry
uor-client-go build collection helloworld-workspace --plain-http localhost:5000/exercises/helloworld:latest --dsconfig helloworld-dataset-config.yaml
uor-client-go push --plain-http localhost:5000/exercises/helloworld:latest
  1. Pull the collection into a directory called output
uor-client-go pull --plain-http localhost:5000/exercises/helloworld:latest -o output
  1. Inspect the contents of the output directory
ls output

helloworld test.txt
  1. Pulling by attributes can also be specified when referencing collections. Create a file called application-query.yaml to content that has the attribute name=helloworld
cat << EOF > application-query.yaml
kind: AttributeQuery
apiVersion: client.uor-framework.io/v1alpha1
attributes:
  "myapplication":
     "name": "helloworld"
EOF
  1. Pull the contents from the collection using the Attribute Query into a directory called application-output:
uor-client-go pull --plain-http localhost:5000/exercises/helloworld:latest --attributes application-query.yaml -o application-output
  1. Inspect the content of the application-output directory
ls application-output

helloworld
  1. Inspecting by attributes can used to get descriptor information stored in the build cache. Create a file called core-query.yaml to content that has the attribute Cmd-./helloworld and a schema id of core-runtume (See README for schema contents)
cat << EOF > core-query.yaml
kind: AttributeQuery
apiVersion: client.uor-framework.io/v1alpha1
attributes:
  "core-runtime":
     "Cmd": 
        - "./helloworld"
EOF
  1. Inspect the contents from the collection using the Attribute Query:
uor-client-go inspect --reference localhost:5000/exercises/helloworld:latest --attributes core-query.yaml 
...
Listing matching descriptors for source:    localhost:5000/exercises/helloworld:latest
Name  Digest                                                                   Size  MediaType
None  sha256:0082a56c18edc1937ddb6a7b5ab09d9ecba99e6beaba4c91d053e321c5cd005e  994   application/vnd.oci.image.manifest.v1+json

Check the attributes:
uor-client-go inspect --reference localhost:5000/exercises/helloworld:latest --print-attributes
...
# Lists all descriptors and attributes for reference

Checklist:

afflom commented 1 year ago

Hi @jpower432, I'm not getting the expected output from the last command in the test instructions. All of the other commands complete without error,

When I run uor-client-go inspect localhost:5000/exercises/helloworld:latest --attributes core-query.yaml, I get the following error:

uor-client-go inspect localhost:5000/exercises/helloworld:latest --attributes core-query.yaml 
Error: must specify a reference with --reference

When I add --reference I get the following output:

uor-client-go inspect --reference localhost:5000/exercises/helloworld:latest --attributes core-query.yaml 
Listing matching descriptors for source:        localhost:5000/exercises/helloworld:latest
Name  Digest  Size  MediaType

Note: the code block in step 13 has an incorrect file name, but I renamed this in my testing to core-query.yaml.

jpower432 commented 1 year ago

@afflom Thanks for pointing out this bug. Please pull the changes and try this step again.