pulumi package commands
This commit is contained in:
parent
63e129a386
commit
70d14e0df0
37
pkg/cmd/pulumi/package.go
Normal file
37
pkg/cmd/pulumi/package.go
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
// Copyright 2016-2021, Pulumi Corporation.
|
||||||
|
//
|
||||||
|
// 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 main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newPackageCmd() *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "package",
|
||||||
|
Short: "Manage, create, and develop pulumi packages.",
|
||||||
|
Long: "Manage, create, and develop pulumi packages.",
|
||||||
|
Args: cmdutil.NoArgs,
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.AddCommand(newPackageGenerateCmd())
|
||||||
|
cmd.AddCommand(newPackageInstallCmd())
|
||||||
|
cmd.AddCommand(newPackagePublishCmd())
|
||||||
|
cmd.AddCommand(newPackageNewCmd())
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
1
pkg/cmd/pulumi/package_build.go
Normal file
1
pkg/cmd/pulumi/package_build.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package main
|
158
pkg/cmd/pulumi/package_generate.go
Normal file
158
pkg/cmd/pulumi/package_generate.go
Normal file
|
@ -0,0 +1,158 @@
|
||||||
|
// Copyright 2016-2018, Pulumi Corporation.
|
||||||
|
//
|
||||||
|
// 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 main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/pulumi/pulumi/pkg/v3/backend"
|
||||||
|
"github.com/pulumi/pulumi/pkg/v3/backend/display"
|
||||||
|
"github.com/pulumi/pulumi/pkg/v3/engine"
|
||||||
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/config"
|
||||||
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
|
||||||
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Action int
|
||||||
|
|
||||||
|
const (
|
||||||
|
Generate Action = iota
|
||||||
|
Build
|
||||||
|
Publish
|
||||||
|
Install
|
||||||
|
New
|
||||||
|
)
|
||||||
|
|
||||||
|
func (a Action) String() string {
|
||||||
|
return [...]string{"generate", "build", "publish", "install", "new"}[a]
|
||||||
|
}
|
||||||
|
|
||||||
|
func doPkgUp(opts backend.UpdateOptions, action Action, version string) result.Result {
|
||||||
|
s, err := requireStack("", true, opts.Display, false /*setCurrent*/)
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ps, err := loadProjectStack(s)
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
key, err := config.ParseKey(fmt.Sprintf("pulumi-package:action"))
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
v := config.NewValue(action.String())
|
||||||
|
|
||||||
|
err = ps.Config.Set(key, v, false)
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if version != "" {
|
||||||
|
key, err := config.ParseKey(fmt.Sprintf("pulumi-package:version"))
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
v := config.NewValue(version)
|
||||||
|
|
||||||
|
err = ps.Config.Set(key, v, false)
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
proj, root, err := readProjectForUpdate("")
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
m, err := getUpdateMetadata("", root, "", "")
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(errors.Wrap(err, "gathering environment metadata"))
|
||||||
|
}
|
||||||
|
|
||||||
|
sm, err := getStackSecretsManager(s)
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(errors.Wrap(err, "getting secrets manager"))
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg, err := getStackConfiguration(s, sm)
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(errors.Wrap(err, "getting stack configuration"))
|
||||||
|
}
|
||||||
|
|
||||||
|
opts.Engine = engine.UpdateOptions{
|
||||||
|
UseLegacyDiff: useLegacyDiff(),
|
||||||
|
DisableProviderPreview: disableProviderPreview(),
|
||||||
|
DisableResourceReferences: disableResourceReferences(),
|
||||||
|
}
|
||||||
|
|
||||||
|
_, res := s.Update(commandContext(), backend.UpdateOperation{
|
||||||
|
Proj: proj,
|
||||||
|
Root: root,
|
||||||
|
M: m,
|
||||||
|
Opts: opts,
|
||||||
|
StackConfiguration: cfg,
|
||||||
|
SecretsManager: sm,
|
||||||
|
Scopes: cancellationScopes,
|
||||||
|
})
|
||||||
|
switch {
|
||||||
|
case res != nil && res.Error() == context.Canceled:
|
||||||
|
return result.FromError(errors.New("update cancelled"))
|
||||||
|
case res != nil:
|
||||||
|
return PrintEngineResult(res)
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPackageGenerateCmd() *cobra.Command {
|
||||||
|
|
||||||
|
var cmd = &cobra.Command{
|
||||||
|
Use: "generate",
|
||||||
|
Args: cmdutil.MaximumNArgs(3),
|
||||||
|
Short: "Generate SDKs for your pulumi package.",
|
||||||
|
Long: "Generate SDKs for your pulumi package.",
|
||||||
|
Run: cmdutil.RunResultFunc(func(cmd *cobra.Command, args []string) result.Result {
|
||||||
|
yes := true
|
||||||
|
skipPreview := true
|
||||||
|
interactive := cmdutil.Interactive()
|
||||||
|
|
||||||
|
opts, err := updateFlagsToOptions(interactive, skipPreview, yes)
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var displayType = display.DisplayProgress
|
||||||
|
|
||||||
|
opts.Display = display.Options{
|
||||||
|
Color: cmdutil.GetGlobalColorization(),
|
||||||
|
IsInteractive: interactive,
|
||||||
|
Type: displayType,
|
||||||
|
}
|
||||||
|
opts.Display.SuppressPermaLink = false
|
||||||
|
|
||||||
|
return doPkgUp(opts, Generate, "")
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
return cmd
|
||||||
|
}
|
41
pkg/cmd/pulumi/package_install.go
Normal file
41
pkg/cmd/pulumi/package_install.go
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/pulumi/pulumi/pkg/v3/backend/display"
|
||||||
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
|
||||||
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newPackageInstallCmd() *cobra.Command {
|
||||||
|
|
||||||
|
var cmd = &cobra.Command{
|
||||||
|
Use: "install",
|
||||||
|
Args: cmdutil.MaximumNArgs(3),
|
||||||
|
Short: "Install plugin and SDKs for development on your local machine.",
|
||||||
|
Long: "Install plugin and SDKs for development on your local machine.",
|
||||||
|
Run: cmdutil.RunResultFunc(func(cmd *cobra.Command, args []string) result.Result {
|
||||||
|
yes := true
|
||||||
|
skipPreview := true
|
||||||
|
interactive := cmdutil.Interactive()
|
||||||
|
|
||||||
|
opts, err := updateFlagsToOptions(interactive, skipPreview, yes)
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var displayType = display.DisplayProgress
|
||||||
|
|
||||||
|
opts.Display = display.Options{
|
||||||
|
Color: cmdutil.GetGlobalColorization(),
|
||||||
|
IsInteractive: interactive,
|
||||||
|
Type: displayType,
|
||||||
|
}
|
||||||
|
opts.Display.SuppressPermaLink = false
|
||||||
|
|
||||||
|
return doPkgUp(opts, Install, "")
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
return cmd
|
||||||
|
}
|
52
pkg/cmd/pulumi/package_new.go
Normal file
52
pkg/cmd/pulumi/package_new.go
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/pulumi/pulumi/pkg/v3/backend/display"
|
||||||
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
|
||||||
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newPackageNewCmd() *cobra.Command {
|
||||||
|
var cmd = &cobra.Command{
|
||||||
|
Use: "new",
|
||||||
|
Short: "Create a new pulumi package.",
|
||||||
|
Long: "Create a new pulumi package.",
|
||||||
|
Run: cmdutil.RunResultFunc(func(cmd *cobra.Command, args []string) result.Result {
|
||||||
|
pNewArgs := newArgs{
|
||||||
|
interactive: cmdutil.Interactive(),
|
||||||
|
prompt: promptForValue,
|
||||||
|
templateNameOrURL: "package-go", // TODO: add more
|
||||||
|
secretsProvider: "default",
|
||||||
|
offline: true, // hack to use my local template branch
|
||||||
|
}
|
||||||
|
|
||||||
|
err := runNew(pNewArgs)
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
yes := true
|
||||||
|
skipPreview := true
|
||||||
|
interactive := cmdutil.Interactive()
|
||||||
|
|
||||||
|
opts, err := updateFlagsToOptions(interactive, skipPreview, yes)
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var displayType = display.DisplayProgress
|
||||||
|
|
||||||
|
opts.Display = display.Options{
|
||||||
|
Color: cmdutil.GetGlobalColorization(),
|
||||||
|
IsInteractive: interactive,
|
||||||
|
Type: displayType,
|
||||||
|
}
|
||||||
|
opts.Display.SuppressPermaLink = false
|
||||||
|
|
||||||
|
return doPkgUp(opts, New, "")
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
return cmd
|
||||||
|
}
|
41
pkg/cmd/pulumi/package_publish.go
Normal file
41
pkg/cmd/pulumi/package_publish.go
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/pulumi/pulumi/pkg/v3/backend/display"
|
||||||
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
|
||||||
|
"github.com/pulumi/pulumi/sdk/v3/go/common/util/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newPackagePublishCmd() *cobra.Command {
|
||||||
|
var cmd = &cobra.Command{
|
||||||
|
Use: "publish [version]",
|
||||||
|
Args: cmdutil.ExactArgs(1),
|
||||||
|
Short: "Publish a plugin and SDKs.",
|
||||||
|
Long: "Publish a plugin and SDKs.",
|
||||||
|
Run: cmdutil.RunResultFunc(func(cmd *cobra.Command, args []string) result.Result {
|
||||||
|
version := args[0]
|
||||||
|
yes := true
|
||||||
|
skipPreview := true
|
||||||
|
interactive := cmdutil.Interactive()
|
||||||
|
|
||||||
|
opts, err := updateFlagsToOptions(interactive, skipPreview, yes)
|
||||||
|
if err != nil {
|
||||||
|
return result.FromError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var displayType = display.DisplayProgress
|
||||||
|
|
||||||
|
opts.Display = display.Options{
|
||||||
|
Color: cmdutil.GetGlobalColorization(),
|
||||||
|
IsInteractive: interactive,
|
||||||
|
Type: displayType,
|
||||||
|
}
|
||||||
|
opts.Display.SuppressPermaLink = false
|
||||||
|
|
||||||
|
return doPkgUp(opts, Publish, version)
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
return cmd
|
||||||
|
}
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
user "github.com/tweekmonster/luser"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -30,6 +29,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
user "github.com/tweekmonster/luser"
|
||||||
|
|
||||||
"github.com/blang/semver"
|
"github.com/blang/semver"
|
||||||
"github.com/djherbis/times"
|
"github.com/djherbis/times"
|
||||||
"github.com/docker/docker/pkg/term"
|
"github.com/docker/docker/pkg/term"
|
||||||
|
@ -198,6 +199,8 @@ func NewPulumiCmd() *cobra.Command {
|
||||||
cmd.AddCommand(newWhoAmICmd())
|
cmd.AddCommand(newWhoAmICmd())
|
||||||
// - Policy Management Commands:
|
// - Policy Management Commands:
|
||||||
cmd.AddCommand(newPolicyCmd())
|
cmd.AddCommand(newPolicyCmd())
|
||||||
|
// - Package Commands
|
||||||
|
cmd.AddCommand(newPackageCmd())
|
||||||
// - Advanced Commands:
|
// - Advanced Commands:
|
||||||
cmd.AddCommand(newCancelCmd())
|
cmd.AddCommand(newCancelCmd())
|
||||||
cmd.AddCommand(newImportCmd())
|
cmd.AddCommand(newImportCmd())
|
||||||
|
|
Loading…
Reference in a new issue