getporter / porter

Porter enables you to package your application artifact, client tools, configuration and deployment logic together as an installer that you can distribute, and install with a single command.
https://porter.sh
Apache License 2.0
1.23k stars 205 forks source link

Not able to install storage.porter.mongodb-docker plugin through a wrapper of porter commands #3229

Closed ujala-singh closed 1 week ago

ujala-singh commented 1 week ago

What is your question? I am building my own CLI by wrapping up the porters's capabilities as below:

package main

import (
    "fmt"
    "os"

    "get.porter.sh/porter/pkg/porter"
    "get.porter.sh/porter/pkg/portercontext"
    "github.com/spf13/cobra"
)

func main() {
    rootCmd := &cobra.Command{Use: "porter-cli"}

    // Add commands
    rootCmd.AddCommand(buildCmd)
    rootCmd.AddCommand(installCmd)
    rootCmd.AddCommand(uninstallCmd)
    rootCmd.AddCommand(listCmd)
    rootCmd.AddCommand(runCmd)
    rootCmd.AddCommand(publishCmd)

    // Execute root command
    if err := rootCmd.Execute(); err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}

var publishCmd = &cobra.Command{
    Use:   "publish",
    Short: "Publish the porter bundle",
    Run: func(cmd *cobra.Command, args []string) {
        p := porter.New()

        // Assuming porter.yaml is in the current directory
        publishOptions := porter.PublishOptions{}
        err := publishOptions.Validate(p.Config)
        if err != nil {
            fmt.Println("Error during validation:", err)
            return
        }

        // Execute publish
        err = p.Publish(cmd.Context(), publishOptions)
        if err != nil {
            fmt.Println("Error during publish:", err)
            return
        }

        fmt.Println("Bundle published successfully.")
    },
}

var buildCmd = &cobra.Command{
    Use:   "build",
    Short: "Build the porter bundle",
    Run: func(cmd *cobra.Command, args []string) {
        p := porter.New()

        // Assuming porter.yaml is in the current directory
        buildOptions := porter.BuildOptions{}
        err := buildOptions.Validate(p) // Validate the options
        if err != nil {
            fmt.Println("Error during validation:", err)
            return
        }

        // Execute build
        err = p.Build(cmd.Context(), buildOptions)
        if err != nil {
            fmt.Println("Error during build:", err)
            return
        }

        fmt.Println("Bundle built successfully.")
    },
}

var installCmd = &cobra.Command{
    Use:   "install",
    Short: "Install the porter bundle",
    Run: func(cmd *cobra.Command, args []string) {
        p := porter.New()

        // Assuming porter.yaml is in the current directory
        installOptions := porter.NewInstallOptions()
        installOptions.File = "porter.yaml"

        // Execute install
        err := p.InstallBundle(cmd.Context(), installOptions)
        if err != nil {
            fmt.Println("Error during install:", err)
            return
        }

        fmt.Println("Bundle installed successfully.")
    },
}

var listCmd = &cobra.Command{
    Use:   "list",
    Short: "List installed bundles",
    Run: func(cmd *cobra.Command, args []string) {
        p := porter.New()

        // Create ListOptions
        runListOptions := porter.RunListOptions{}
        pCtx := portercontext.New()
        err := runListOptions.Validate(args, pCtx)
        if err != nil {
            fmt.Println("Error during validation:", err)
            return
        }

        // Execute list
        printErr := p.PrintInstallationRuns(cmd.Context(), runListOptions)
        if printErr != nil {
            fmt.Println("Error during listing bundles:", printErr)
            return
        }
    },
}

var runCmd = &cobra.Command{
    Use:   "run",
    Short: "Run the porter bundle",
    Run: func(cmd *cobra.Command, args []string) {
        p := porter.New()

        // Define run options
        runOptions := porter.NewRunOptions(p.Config)
        runOptions.File = "porter.yaml"

        // Validate the run options
        err := runOptions.Validate()
        if err != nil {
            fmt.Println("Error during validation:", err)
            return
        }

        // Execute the run command
        err = p.Run(cmd.Context(), runOptions)
        if err != nil {
            fmt.Println("Error during run:", err)
            return
        }

        fmt.Println("Bundle ran successfully.")
    },
}

var uninstallCmd = &cobra.Command{
    Use:   "uninstall",
    Short: "Uninstall the porter bundle",
    Run: func(cmd *cobra.Command, args []string) {
        p := porter.New()

        // Assuming porter.yaml is in the current directory
        uninstallOptions := porter.NewUninstallOptions()
        uninstallOptions.File = "porter.yaml"

        // Execute uninstall
        err := p.UninstallBundle(cmd.Context(), uninstallOptions)
        if err != nil {
            fmt.Println("Error during uninstall:", err)
            return
        }

        fmt.Println("Bundle uninstalled successfully.")
    },
}

My build is working fine as below:

$ go build -o porter-cli

It created binary for me. and whenever I run install command, it fails with the below error:

Error during install: could not retrieve the installation record: could not read storage schema document: could not load storage plugin: could not connect to the storage.porter.mongodb-docker plugin: plugin stderr was Error: unknown command "plugin" for "porter-cli"
: Unrecognized remote plugin message: unknown command "plugin" for "porter-cli"

This usually means that the plugin is either invalid or simply
needs to be recompiled to support the latest protocol.

How can I resolve it? Please I would really appreciate it.

I have followed the guide mentioned here: https://porter.sh/docs/references/library/

ujala-singh commented 1 week ago

Also this doc https://porter.sh/plugins/mongodb-docker/ says, The MongoDB Docker Storage plugin is suitable for development and test but should not be used in production. What are the recommendations for production?

kichristensen commented 1 week ago

In order to have a single place to discuss this one, I will close this issue in favor of the discussion that also was started in #3230