Compare commits

...

1 commit

Author SHA1 Message Date
evanboyle 70d14e0df0 pulumi package commands 2021-06-15 23:10:07 -07:00
7 changed files with 334 additions and 1 deletions

37
pkg/cmd/pulumi/package.go Normal file
View 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
}

View file

@ -0,0 +1 @@
package main

View 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
}

View 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
}

View 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
}

View 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
}

View file

@ -19,7 +19,6 @@ import (
"bytes"
"encoding/json"
"fmt"
user "github.com/tweekmonster/luser"
"net/http"
"net/url"
"os"
@ -30,6 +29,8 @@ import (
"strings"
"time"
user "github.com/tweekmonster/luser"
"github.com/blang/semver"
"github.com/djherbis/times"
"github.com/docker/docker/pkg/term"
@ -198,6 +199,8 @@ func NewPulumiCmd() *cobra.Command {
cmd.AddCommand(newWhoAmICmd())
// - Policy Management Commands:
cmd.AddCommand(newPolicyCmd())
// - Package Commands
cmd.AddCommand(newPackageCmd())
// - Advanced Commands:
cmd.AddCommand(newCancelCmd())
cmd.AddCommand(newImportCmd())