Skip to content

Commit

Permalink
download-starter-projects functions added to Registry Library APIs (#…
Browse files Browse the repository at this point in the history
…126)

Signed-off-by: Michael Valdron <[email protected]>
  • Loading branch information
michael-valdron authored Jul 12, 2022
1 parent 4aa39fc commit 57e97bd
Show file tree
Hide file tree
Showing 11 changed files with 1,298 additions and 176 deletions.
42 changes: 42 additions & 0 deletions registry-library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,45 @@ Supported devfile media types can be found in the latest version of [library.go]
}
```

#### Download the starter project

1. Download starter project in-memory
```go
var bytes []byte
var err error
...
starterProject := "springbootproject"
bytes, err = registryLibrary.DownloadStarterProjectAsBytes(registryURL,
stack, starterProject, options)
if err != nil {
return err
}
```
2. Download starter project archive to filesystem path
```go
starterProject := "springbootproject"
path := fmt.Sprintf("%s.zip", starterProject)
err := registryLibrary.DownloadStarterProject(path, registryURL, stack, starterProject, options)
if err != nil {
return err
}
```

```sh
ls # => devfile.yaml springbootproject.zip
```
3. Download starter project archive and extract to filesystem path
```go
starterProject := "springbootproject"
path := "."
err := registryLibrary.DownloadStarterProjectAsDir(path, registryURL, stack, starterProject, options)
if err != nil {
return err
}
```

```sh
ls # => devfile.yaml pom.xml HELP.md mvnw mvnw.cmd src
```
30 changes: 29 additions & 1 deletion registry-library/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd
import (
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -147,7 +148,34 @@ func init() {
listCmd.Flags().BoolVar(&skipTLSVerify, "skip-tls-verify", false, "skip TLS verification")
listCmd.Flags().StringVar(&user, "user", "", "consumer name")

rootCmd.AddCommand(pullCmd, listCmd)
var downloadCmd = &cobra.Command{
Use: "download <registry name> <stack name> <starter project name>",
Short: "Downloads starter project",
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
registry, stack, starterProject := args[0], args[1], args[2]
var err error

options := library.RegistryOptions{
NewIndexSchema: newIndexSchema,
Telemetry: library.TelemetryData{
User: "user",
},
SkipTLSVerify: skipTLSVerify,
}

err = library.DownloadStarterProjectAsDir(filepath.Join(destDir, starterProject), registry, stack, starterProject, options)
if err != nil {
fmt.Printf("failed to download starter project %s: %v\n", starterProject, err)
}
},
}
downloadCmd.Flags().StringVar(&destDir, "context", ".", "destination directory that stores stack resources")
downloadCmd.Flags().BoolVar(&skipTLSVerify, "skip-tls-verify", false, "skip TLS verification")
downloadCmd.Flags().BoolVar(&newIndexSchema, "new-index-schema", false, "use new index schema")
downloadCmd.Flags().StringVar(&user, "user", "", "consumer name")

rootCmd.AddCommand(pullCmd, listCmd, downloadCmd)
}

// initConfig reads in config file and ENV variables if set.
Expand Down
2 changes: 1 addition & 1 deletion registry-library/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.14

require (
github.com/containerd/containerd v1.5.9
github.com/devfile/registry-support/index/generator v0.0.0-20220222194908-7a90a4214f3e
github.com/devfile/registry-support/index/generator v0.0.0-20220624203950-e7282a4695b6
github.com/hashicorp/go-version v1.4.0
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.2.1
Expand Down
29 changes: 29 additions & 0 deletions registry-library/go.sum

Large diffs are not rendered by default.

Loading

0 comments on commit 57e97bd

Please sign in to comment.