Skip to content

Commit

Permalink
Merge pull request meshery#10365 from meshery/leecalcote/mesheryctl/r…
Browse files Browse the repository at this point in the history
…egistry-generate

[chore] mesheryctl: rename registry import to registry generate
  • Loading branch information
leecalcote authored Feb 21, 2024
2 parents 3842cd7 + 098e501 commit 7d3eeef
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 39 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/model-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fetch-depth: 1

- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.21"

Expand All @@ -27,10 +27,10 @@ jobs:
- name: Generate Models and Components
run: |
cd mesheryctl;
./mesheryctl registry import --spreadsheet_id "1DZHnzxYWOlJ69Oguz4LkRVTFM79kC2tuvdwizOJmeMw" --spreadsheet_cred "${{ secrets.INTEGRATION_SPREADSHEET_CRED }}"
./mesheryctl registry generate --spreadsheet-id "1DZHnzxYWOlJ69Oguz4LkRVTFM79kC2tuvdwizOJmeMw" --spreadsheet-cred "${{ secrets.INTEGRATION_SPREADSHEET_CRED }}"
- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: generate-logs
path: ~/.meshery/logs/
Expand Down Expand Up @@ -67,13 +67,13 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_ACCESS_TOKEN }}
fetch-depth: 1

- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Pull changes from remote
Expand All @@ -84,7 +84,7 @@ jobs:
- name: Run Model Updater
run: |
cd mesheryctl;
./mesheryctl registry update -i ../server/meshmodel --spreadsheet_id "1DZHnzxYWOlJ69Oguz4LkRVTFM79kC2tuvdwizOJmeMw" --spreadsheet_cred "${{ secrets.INTEGRATION_SPREADSHEET_CRED }}"
./mesheryctl registry update -i ../server/meshmodel --spreadsheet-id "1DZHnzxYWOlJ69Oguz4LkRVTFM79kC2tuvdwizOJmeMw" --spreadsheet_cred "${{ secrets.INTEGRATION_SPREADSHEET_CRED }}"
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
Expand Down
5 changes: 2 additions & 3 deletions mesheryctl/internal/cli/root/experimental/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package experimental
import (
"fmt"

"github.com/layer5io/meshery/mesheryctl/internal/cli/root/registry"
"github.com/layer5io/meshery/mesheryctl/internal/cli/root/system"
"github.com/layer5io/meshery/mesheryctl/pkg/utils"
"github.com/pkg/errors"
Expand All @@ -32,7 +31,7 @@ var (
var ExpCmd = &cobra.Command{
Use: "exp",
Short: "Experimental commands for mesheryctl",
Long: `List of experimental commands for testing and evaluation purpose.`,
Long: `Commands under the Experimental group are for testing and evaluation prior to promotion to general availability. Experimental commands are subject to change.`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return cmd.Help()
Expand All @@ -45,6 +44,6 @@ var ExpCmd = &cobra.Command{
}

func init() {
availableSubcommands = append(availableSubcommands, system.ModelCmd, registry.RegistryCmd, system.ComponentsCmd)
availableSubcommands = append(availableSubcommands, system.ModelCmd, system.ComponentsCmd)
ExpCmd.AddCommand(availableSubcommands...)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// # Copyright Meshery Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package registry

import (
Expand Down Expand Up @@ -27,8 +41,8 @@ var (
GoogleSpreadSheetURL = "https://docs.google.com/spreadsheets/d/"
srv *sheets.Service

// Tracks the indexed mapping between component spreadsheet columns.
// Used when generating component definition from spreadsheet itself, for eg: Compnent of Meshery core model.
// Maps the relationship between the Models sheet and Components sheet of the Meshery Integration spreadsheet columns.
// Used when generating Component definition from spreadsheet itself, for eg: Component of Meshery core model.
// The GoogleSpreadsheetAPI doesn't return column names, hence when invoking generation columns names are retrived by dumoing the sheet in CSV format then extrcting the columns (ComponentCSVHelper)
componentSpreadsheetCols []string

Expand All @@ -39,18 +53,22 @@ var (
totalAggregateModel int
)

var importCmd = &cobra.Command{
Use: "import",
Short: "Import Models",
Long: "Import models from spreadsheet, GitHub or ArtifactHub repositories",
var generateCmd = &cobra.Command{
Use: "generate",
Short: "Generate Models",
Long: "Prerequisite: Excecute this command from the root of a meshery/meshery repo fork.\n\nGiven a Google Sheet with a list of model names and source locations, generate models and components any Registrant (e.g. GitHub, Artifact Hub) repositories.\n\nGenerated Model files are written to local filesystem under `/server/models/<model-name>`.",
Example: `
// Import models from Meshery Integration Spreadsheet
mesheryctl registry import --spreadsheet_url <url> --spreadsheet_cred <base64 encoded spreadsheet credential>
// Directly import models from one of the supported registrants by using Registrant Connection Definition and (optional) Registrant Credential Definition
mesheryctl registry import --registrant_def <path to connection definition> --registrant_cred <path to credential definition>
// Generate Meshery Models from a Google Spreadsheet (i.e. "Meshery Integrations" spreadsheet).
mesheryctl registry generate --spreadsheet-id <id> --spreadsheet-cred <base64 encoded spreadsheet credential>
# Example: mesheryctl registry generate --spreadsheet-id "1DZHnzxYWOlJ69Oguz4LkRVTFM79kC2tuvdwizOJmeMw" --spreadsheet-cred
// Directly generate models from one of the supported registrants by using Registrant Connection Definition and (optional) Registrant Credential Definition
mesheryctl registry generate --registrant-def <path to connection definition> --registrant-cred <path to credential definition>
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
// Prerequisite check is needed - https://github.com/meshery/meshery/issues/10369
// TODO: Include a prerequisite check to confirm that this command IS being the executED from within a fork of the Meshery repo, and is being executed at the root of that fork.
//

err := os.MkdirAll(logDirPath, 0755)
if err != nil {
return ErrUpdateRegistry(err, modelLocation)
Expand All @@ -70,7 +88,7 @@ var importCmd = &cobra.Command{
registryLocation = filepath.Join(cwd, outputLocation)

if pathToRegistrantConnDefinition != "" {
utils.Log.Info("Model Generation from registrant definitions not yet supproted.")
utils.Log.Info("Model generation from Registrant definitions not yet supported.")
return nil
}
var err error
Expand All @@ -88,7 +106,9 @@ var importCmd = &cobra.Command{
return err
}

// Collect list of Models by name from spreadsheet
sheetGID = GetSheetIDFromTitle(resp, "Models")
// Collect list of corresponding Components by name from spreadsheet
componentSpredsheetGID = GetSheetIDFromTitle(resp, "Components")

err = InvokeGenerationFromSheet()
Expand Down Expand Up @@ -116,9 +136,9 @@ func InvokeGenerationFromSheet() error {
defer func() {
_ = logFile.Close()
utils.Log.UpdateLogOutput(os.Stdout)
utils.Log.Info(fmt.Sprintf("Generated %d models and %d components", totalAggregateModel, totalAggregateComponents))
utils.Log.Info(fmt.Sprintf("Summary: %d models, %d components generated.", totalAggregateModel, totalAggregateComponents))

utils.Log.Info("refer ", logDirPath, " for detailed registry generate logs")
utils.Log.Info("See ", logDirPath, " for detailed logs.")

totalAggregateModel = 0
totalAggregateComponents = 0
Expand Down Expand Up @@ -318,18 +338,18 @@ func logModelGenerationSummary(modelToCompGenerateTracker *store.GenerticThreadS
}

func init() {
importCmd.PersistentFlags().StringVar(&spreadsheeetID, "spreadsheet_id", "", "spreadsheet it for the integration spreadsheet")
importCmd.PersistentFlags().StringVar(&spreadsheeetCred, "spreadsheet_cred", "", "base64 encoded credential to download the spreadsheet")
generateCmd.PersistentFlags().StringVar(&spreadsheeetID, "spreadsheet-id", "", "spreadsheet it for the integration spreadsheet")
generateCmd.PersistentFlags().StringVar(&spreadsheeetCred, "spreadsheet-cred", "", "base64 encoded credential to download the spreadsheet")

importCmd.MarkFlagsRequiredTogether("spreadsheet_id", "spreadsheet_cred")
generateCmd.MarkFlagsRequiredTogether("spreadsheet-id", "spreadsheet-cred")

importCmd.PersistentFlags().StringVar(&pathToRegistrantConnDefinition, "registrant_def", "", "path pointing to the registrant connection definition")
importCmd.PersistentFlags().StringVar(&pathToRegistrantCredDefinition, "registrant_cred", "", "path pointing to the registrant credetial definition")
generateCmd.PersistentFlags().StringVar(&pathToRegistrantConnDefinition, "registrant-def", "", "path pointing to the registrant connection definition")
generateCmd.PersistentFlags().StringVar(&pathToRegistrantCredDefinition, "registrant-cred", "", "path pointing to the registrant credetial definition")

importCmd.MarkFlagsRequiredTogether("registrant_def", "registrant_cred")
generateCmd.MarkFlagsRequiredTogether("registrant-def", "registrant-cred")

importCmd.MarkFlagsMutuallyExclusive("spreadsheet_id", "registrant_def")
importCmd.MarkFlagsMutuallyExclusive("spreadsheet_cred", "registrant_cred")
generateCmd.MarkFlagsMutuallyExclusive("spreadsheet-id", "registrant-def")
generateCmd.MarkFlagsMutuallyExclusive("spreadsheet-cred", "registrant-cred")

importCmd.PersistentFlags().StringVarP(&outputLocation, "output", "o", "../server/meshmodel", "location to output generated models, defaults to ../server/meshmodels")
generateCmd.PersistentFlags().StringVarP(&outputLocation, "output", "o", "../server/meshmodel", "location to output generated models, defaults to ../server/meshmodels")
}
5 changes: 3 additions & 2 deletions mesheryctl/internal/cli/root/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import (
"fmt"

"errors"

"github.com/layer5io/meshery/mesheryctl/pkg/utils"
"github.com/spf13/cobra"
)

var (
availableSubcommands = []*cobra.Command{importCmd, publishCmd, updateCmd}
availableSubcommands = []*cobra.Command{generateCmd, publishCmd, updateCmd}

spreadsheeetID string
spreadsheeetCred string
Expand All @@ -33,7 +34,7 @@ var (
var RegistryCmd = &cobra.Command{
Use: "registry",
Short: "Meshery Registry Management",
Long: `Manage the state and configuration of Meshery Registry.`,
Long: `Manage the state and contents of Meshery's internal registry of capabilities.`,
Example: `
mesheryctl registry [subcommand]
`,
Expand Down
10 changes: 5 additions & 5 deletions mesheryctl/internal/cli/root/registry/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ var updateCmd = &cobra.Command{
Long: "`Updates the component metadata (SVGs, shapes, styles and other) by referring from a Google Spreadsheet.`",
Example: `
// Update models from Meshery Integration Spreadsheet
mesheryctl registry update --spreadsheet_id <id> --spreadsheet_cred <base64 encoded spreadsheet credential> -i [path to the directory containing models].
mesheryctl registry update --spreadsheet-id <id> --spreadsheet-cred <base64 encoded spreadsheet credential> -i [path to the directory containing models].
// Updating models in the meshery/meshery repo
mesheryctl registry update --spreadsheet_id 1DZHnzxYWOlJ69Oguz4LkRVTFM79kC2tuvdwizOJmeMw --spreadsheet_cred $CRED
mesheryctl registry update --spreadsheet-id 1DZHnzxYWOlJ69Oguz4LkRVTFM79kC2tuvdwizOJmeMw --spreadsheet-cred $CRED
`,
PreRunE: func(cmd *cobra.Command, args []string) error {

Expand Down Expand Up @@ -228,9 +228,9 @@ func init() {
updateCmd.PersistentFlags().StringVarP(&modelLocation, "input", "i", "../server/meshmodel", "relative or absolute input path to the models directory")
_ = updateCmd.MarkPersistentFlagRequired("path")

updateCmd.PersistentFlags().StringVar(&spreadsheeetID, "spreadsheet_id", "", "spreadsheet it for the integration spreadsheet")
updateCmd.PersistentFlags().StringVar(&spreadsheeetCred, "spreadsheet_cred", "", "base64 encoded credential to download the spreadsheet")
updateCmd.PersistentFlags().StringVar(&spreadsheeetID, "spreadsheet-id", "", "spreadsheet it for the integration spreadsheet")
updateCmd.PersistentFlags().StringVar(&spreadsheeetCred, "spreadsheet-cred", "", "base64 encoded credential to download the spreadsheet")

updateCmd.MarkFlagsRequiredTogether("spreadsheet_id", "spreadsheet_cred")
updateCmd.MarkFlagsRequiredTogether("spreadsheet-id", "spreadsheet-cred")

}

0 comments on commit 7d3eeef

Please sign in to comment.