|
1 | 1 | # Devfile registry library
|
2 | 2 |
|
3 | 3 | ## Overview
|
4 |
| -Devfile registry library is used for interacting with devfile registry, consumers can use devfile registry library to list stacks and/or samples of devfile registry, download the stack devfile and the whole stack from devfile registry. |
| 4 | +The Devfile registry library is used to interact with the devfile registry to perform the following actions: |
| 5 | + |
| 6 | +* List the indices of stacks and/or samples from a single registry or across multiple registries |
| 7 | +* Download a stack with specific media types or all supported media types |
| 8 | +* Send telemetry to the Devfile Registry service |
| 9 | +* Filter stacks based on architectures |
5 | 10 |
|
6 | 11 | ## What's included
|
7 |
| -`./library`: package `library` which contains devfile registry library constants, variables and functions, documentations can be found [here](https://pkg.go.dev/github.com/devfile/registry-support/registry-library/library) |
| 12 | +`./library`: package `library` which contains devfile registry library constants, variables and functions. Documentation can be found [here](https://pkg.go.dev/github.com/devfile/registry-support/registry-library/library) |
8 | 13 |
|
9 |
| -`./build.sh`: build script to build `registry` binary to interact with devfile registry |
| 14 | +`./build.sh`: build script to build the `registry-library` binary to interact with devfile registry |
10 | 15 |
|
11 |
| -`./registry`: `registry` binary to interact with devfile registry |
| 16 | +`./registry-library`: `registry-library` binary to interact with devfile registry |
12 | 17 |
|
13 | 18 | ## How to use it
|
14 |
| -1. Import devfile registry library |
15 |
| -```go |
16 |
| -import ( |
17 |
| - registryLibrary "github.com/devfile/registry-support/registry-library/library" |
18 |
| -) |
19 |
| -``` |
20 |
| -2. Invoke devfile registry library |
21 |
| - |
22 |
| - a. Get the index of devfile registry for various devfile types |
23 |
| - ```go |
24 |
| - registryIndex, err := registryLibrary.GetRegistryIndex(registryURL, options, StackDevfileType) |
25 |
| - if err != nil { |
26 |
| - return err |
27 |
| - } |
| 19 | +1. Import the devfile registry library and index schema |
| 20 | + ```go |
| 21 | + import ( |
| 22 | + registryLibrary "github.com/devfile/registry-support/registry-library/library" |
| 23 | + indexSchema "github.com/devfile/registry-support/index/generator/schema" |
| 24 | + ) |
| 25 | + ``` |
| 26 | + |
| 27 | +### List the indices of stacks and/or samples |
| 28 | +1. Get the index for stack devfile types from a single registry |
| 29 | + |
| 30 | + ```go |
| 31 | + registryURL := "https://registry.devfile.io" |
| 32 | + options := registryLibrary.RegistryOptions{} //leave empty if telemetry and architecture types are not relevant |
| 33 | + registryIndex, err := registryLibrary.GetRegistryIndex(registryURL, options, indexSchema.StackDevfileType) |
| 34 | + if err != nil { |
| 35 | + return err |
| 36 | + } |
28 | 37 | ```
|
29 |
| - b. Get the indices of multiple devfile registries for various devfile types |
| 38 | +2. Get the index for all devfile types from a single registry |
30 | 39 | ```go
|
31 |
| - registryList := GetMultipleRegistryIndices(registryURLs, options, StackDevfileType) |
| 40 | + devfileTypes := []indexSchema.DevfileType{indexSchema.StackDevfileType, indexSchema.SampleDevfileType} |
| 41 | + registryIndex, err := registryLibrary.GetRegistryIndex(registryURL, options, devfileTypes...) |
| 42 | + if err != nil { |
| 43 | + return err |
| 44 | + } |
32 | 45 | ```
|
33 |
| - c. Download the stack devfile from devfile registry |
| 46 | + |
| 47 | +3. Get the indices for various devfile stacks from multiple devfile registries |
34 | 48 | ```go
|
35 |
| - err := registryLibrary.PullStackByMediaTypesFromRegistry(registry, stack, registryLibrary.DevfileMediaTypeList, destDir, options) |
36 |
| - if err != nil { |
37 |
| - return err |
38 |
| - } |
| 49 | + registryList := GetMultipleRegistryIndices(registryURLs, options, indexSchema.StackDevfileType) |
39 | 50 | ```
|
40 |
| - d. Download the whole stack from devfile registry |
| 51 | +#### Download the stack |
| 52 | +Supported devfile media types can be found in the latest version of [library.go](https://github.com/devfile/registry-support/blob/main/registry-library/library/library.go) |
| 53 | +1. Download a stack devfile with a given media type from the devfile registry |
41 | 54 | ```go
|
42 |
| - err := registryLibrary.PullStackFromRegistry(registry, stack, destDir, options) |
| 55 | + stack := "java-springboot" |
| 56 | + destDir := "." |
| 57 | + err := registryLibrary.PullStackByMediaTypesFromRegistry(registryURL, stack, registryLibrary.DevfileMediaTypeList, destDir, options) |
43 | 58 | if err != nil {
|
44 |
| - return err |
45 |
| - } |
| 59 | + return err |
| 60 | + } |
46 | 61 | ```
|
47 |
| - e. Specify Options |
| 62 | +2. Download a stack with all supported media types from the devfile registry |
48 | 63 | ```go
|
49 |
| - options := RegistryOptions{ |
50 |
| - User: user, |
51 |
| - SkipTLSVerify: skipTLSVerify, |
52 |
| - Filter: RegistryFilter{ |
| 64 | + err := registryLibrary.PullStackFromRegistry(registryURL, stack, destDir, options) |
| 65 | + if err != nil { |
| 66 | + return err |
| 67 | + } |
| 68 | + ``` |
| 69 | + |
| 70 | +#### Specify Registry Options |
| 71 | +1. Test a pre-prod registry installed with self-signed certificates |
| 72 | + ```go |
| 73 | + options := registryLibrary.RegistryOptions{ |
| 74 | + SkipTLSVerify: "true", |
| 75 | + } |
| 76 | + ``` |
| 77 | +2. Filter Devfiles based on a set of architectures found in [header.go](https://github.com/devfile/api/blob/main/pkg/devfile/header.go) |
| 78 | + ```go |
| 79 | + architectures := []string{"amd64", "arm64"} |
| 80 | + options := registryLibrary.RegistryOptions{ |
| 81 | + Filter: registryLibrary.RegistryFilter{ |
53 | 82 | Architectures: architectures,
|
54 | 83 | },
|
55 | 84 | }
|
56 | 85 | ```
|
| 86 | +3. Send Telemetry data to the Devfile Registry |
| 87 | + ```go |
| 88 | + options := registryLibrary.RegistryOptions{ |
| 89 | + Telemetry: registryLibrary.TelemetryData{ |
| 90 | + User: "user-name" //this can be a generated UUID |
| 91 | + Locale: "en_US" // set the OS or browser locale |
| 92 | + Client: "client-name" //the name of the client |
| 93 | + } |
| 94 | +} |
| 95 | +
|
| 96 | +
|
0 commit comments