Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: 1.23
go-version: 1.24
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v8
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.61.0
version: v2.1
109 changes: 84 additions & 25 deletions cmd/bundle.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package cmd

import (
"bufio"
"fmt"
"log"
"os"
"path/filepath"
"strings"

"github.com/massdriver-cloud/airlock/pkg/prettylogs"
"github.com/massdriver-cloud/mass/docs/helpdocs"
"github.com/massdriver-cloud/mass/pkg/api"
"github.com/massdriver-cloud/mass/pkg/bundle"
"github.com/massdriver-cloud/mass/pkg/commands"
"github.com/massdriver-cloud/mass/pkg/commands/publish"
"github.com/massdriver-cloud/mass/pkg/commands/pull"
"github.com/massdriver-cloud/mass/pkg/config"
"github.com/massdriver-cloud/mass/pkg/params"
"github.com/massdriver-cloud/mass/pkg/restclient"
"github.com/massdriver-cloud/mass/pkg/templatecache"
"github.com/massdriver-cloud/massdriver-sdk-go/massdriver/client"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -46,7 +51,7 @@ func NewCmdBundle() *cobra.Command {
Short: "Build schemas and generate IaC files from massdriver.yaml file",
RunE: runBundleBuild,
}
bundleBuildCmd.Flags().StringP("build-directory", "b", ".", "Path to a directory containing a massdriver.yaml file.")
bundleBuildCmd.Flags().StringP("bundle-directory", "b", ".", "Path to a directory containing a massdriver.yaml file.")

bundleImportCmd := &cobra.Command{
Use: "import",
Expand All @@ -55,7 +60,7 @@ func NewCmdBundle() *cobra.Command {
RunE: runBundleImport,
SilenceUsage: true,
}
bundleImportCmd.Flags().StringP("build-directory", "b", ".", "Path to a directory containing a massdriver.yaml file.")
bundleImportCmd.Flags().StringP("bundle-directory", "b", ".", "Path to a directory containing a massdriver.yaml file.")
bundleImportCmd.Flags().BoolP("all", "a", false, "Import all variables without prompting")

bundleLintCmd := &cobra.Command{
Expand All @@ -64,7 +69,7 @@ func NewCmdBundle() *cobra.Command {
SilenceUsage: true,
RunE: runBundleLint,
}
bundleLintCmd.Flags().StringP("build-directory", "b", ".", "Path to a directory containing a massdriver.yaml file.")
bundleLintCmd.Flags().StringP("bundle-directory", "b", ".", "Path to a directory containing a massdriver.yaml file.")

var bundleNewInput bundleNew

Expand All @@ -82,12 +87,23 @@ func NewCmdBundle() *cobra.Command {
bundleNewCmd.Flags().StringVarP(&bundleNewInput.paramsDir, "params-directory", "p", "", "Path with existing params to use - opentofu module directory or helm chart values.yaml")

bundlePublishCmd := &cobra.Command{
Use: "publish",
Short: "Publish bundle to Massdriver's package manager",
RunE: runBundlePublish,
Use: "publish",
Aliases: []string{"push"},
Short: "Publish bundle to Massdriver's package manager",
RunE: runBundlePublish,
}
bundlePublishCmd.Flags().String("access", "private", "Override the access, useful in CI for deploying to sandboxes.")
bundlePublishCmd.Flags().StringP("build-directory", "b", ".", "Path to a directory containing a massdriver.yaml file.")
bundlePublishCmd.Flags().StringP("bundle-directory", "b", ".", "Path to a directory containing a massdriver.yaml file.")
bundlePublishCmd.Flags().String("access", "", "(Deprecated) Only here for backwards compatibility. Will be removed in a future release.")

bundlePullCmd := &cobra.Command{
Use: "pull <bundle-name>",
Short: "Pull bundle from Massdriver to local directory",
Args: cobra.ExactArgs(1),
RunE: runBundlePull,
}
bundlePullCmd.Flags().StringP("directory", "d", "", "Directory to output the bundle. Defaults to bundle name.")
bundlePullCmd.Flags().BoolP("force", "f", false, "Force pull even if the directory already exists. This will overwrite existing files.")
bundlePullCmd.Flags().StringP("tag", "t", "latest", "Bundle tag (defaults to 'latest')")

bundleTemplateCmd := &cobra.Command{
Use: "template",
Expand All @@ -114,6 +130,7 @@ func NewCmdBundle() *cobra.Command {
bundleCmd.AddCommand(bundleLintCmd)
bundleCmd.AddCommand(bundleNewCmd)
bundleCmd.AddCommand(bundlePublishCmd)
bundleCmd.AddCommand(bundlePullCmd)
bundleCmd.AddCommand(bundleTemplateCmd)
bundleTemplateCmd.AddCommand(bundleTemplateListCmd)
bundleTemplateCmd.AddCommand(bundleTemplateRefreshCmd)
Expand Down Expand Up @@ -252,23 +269,23 @@ func runBundleNew(input *bundleNew) {
}

func runBundleBuild(cmd *cobra.Command, args []string) error {
buildDirectory, err := cmd.Flags().GetString("build-directory")
bundleDirectory, err := cmd.Flags().GetString("bundle-directory")
if err != nil {
return err
}

unmarshalledBundle, err := bundle.UnmarshalAndApplyDefaults(buildDirectory)
unmarshalledBundle, err := bundle.UnmarshalAndApplyDefaults(bundleDirectory)
if err != nil {
return err
}

c := restclient.NewClient()

return commands.BuildBundle(buildDirectory, unmarshalledBundle, c)
return commands.BuildBundle(bundleDirectory, unmarshalledBundle, c)
}

func runBundleImport(cmd *cobra.Command, args []string) error {
buildDirectory, err := cmd.Flags().GetString("build-directory")
bundleDirectory, err := cmd.Flags().GetString("bundle-directory")
if err != nil {
return err
}
Expand All @@ -277,7 +294,7 @@ func runBundleImport(cmd *cobra.Command, args []string) error {
return err
}

return commands.ImportParams(buildDirectory, skipVerify)
return commands.ImportParams(bundleDirectory, skipVerify)
}

func runBundleLint(cmd *cobra.Command, args []string) error {
Expand All @@ -286,19 +303,19 @@ func runBundleLint(cmd *cobra.Command, args []string) error {
return configErr
}

buildDirectory, err := cmd.Flags().GetString("build-directory")
bundleDirectory, err := cmd.Flags().GetString("bundle-directory")
if err != nil {
return err
}

unmarshalledBundle, err := bundle.UnmarshalAndApplyDefaults(buildDirectory)
unmarshalledBundle, err := bundle.UnmarshalAndApplyDefaults(bundleDirectory)
if err != nil {
return err
}

c := restclient.NewClient().WithAPIKey(config.APIKey)

err = unmarshalledBundle.DereferenceSchemas(buildDirectory, c)
err = unmarshalledBundle.DereferenceSchemas(bundleDirectory, c)
if err != nil {
return err
}
Expand All @@ -312,27 +329,69 @@ func runBundlePublish(cmd *cobra.Command, args []string) error {
return configErr
}

buildDirectory, err := cmd.Flags().GetString("build-directory")
if err != nil {
return err
access, _ := cmd.Flags().GetString("access")
if access != "" {
prettylogs.Orange("Warning: The --access flag is deprecated and will be removed in a future release.")
fmt.Println(prettylogs.Orange("Warning: The --access flag is deprecated and will be removed in a future release."))
}

unmarshalledBundle, err := bundle.UnmarshalAndApplyDefaults(buildDirectory)
bundleDirectory, err := cmd.Flags().GetString("bundle-directory")
if err != nil {
return err
}
tag := "latest"

access, err := cmd.Flags().GetString("access")
if err == nil {
unmarshalledBundle.Access = access
unmarshalledBundle, err := bundle.UnmarshalAndApplyDefaults(bundleDirectory)
if err != nil {
return err
}

c := restclient.NewClient().WithAPIKey(config.APIKey)

err = commands.BuildBundle(buildDirectory, unmarshalledBundle, c)
err = commands.BuildBundle(bundleDirectory, unmarshalledBundle, c)
if err != nil {
return err
}

return publish.Run(unmarshalledBundle, c, buildDirectory)
mdClient, clientErr := client.New()
if clientErr != nil {
return fmt.Errorf("error initializing massdriver client: %w", clientErr)
}

return publish.Run(unmarshalledBundle, mdClient, bundleDirectory, tag)
}

func runBundlePull(cmd *cobra.Command, args []string) error {
bundleName := args[0]
directory, _ := cmd.Flags().GetString("directory")
if directory == "" {
directory = bundleName
}
force, _ := cmd.Flags().GetBool("force")
tag, _ := cmd.Flags().GetString("tag")

// Check if bundle exists in the specified directory and if so prompt the user
mdYamlPath := filepath.Join(directory, "massdriver.yaml")
if _, err := os.Stat(mdYamlPath); err == nil && !force {
fmt.Printf("Bundle already exists at %s. Continuing will overwrite its contents. Continue? (y/N): ", mdYamlPath)
reader := bufio.NewReader(os.Stdin)
answer, _ := reader.ReadString('\n')
answer = strings.TrimSpace(strings.ToLower(answer))
if answer != "y" && answer != "yes" {
fmt.Println("Bundle pull aborted!")
return nil
}
}

mdClient, clientErr := client.New()
if clientErr != nil {
return clientErr
}

pullErr := pull.Run(mdClient, bundleName, tag, directory)
if pullErr != nil {
return fmt.Errorf("error pulling bundle: %w", pullErr)
}

return nil
}
1 change: 1 addition & 0 deletions docs/generated/mass_bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ Generate and publish bundles
* [mass bundle lint](/cli/commands/mass_bundle_lint) - Check massdriver.yaml file for common errors
* [mass bundle new](/cli/commands/mass_bundle_new) - Create a new bundle from a template
* [mass bundle publish](/cli/commands/mass_bundle_publish) - Publish bundle to Massdriver's package manager
* [mass bundle pull](/cli/commands/mass_bundle_pull) - Pull bundle from Massdriver to local directory
* [mass bundle template](/cli/commands/mass_bundle_template) - Application template development tools
4 changes: 2 additions & 2 deletions docs/generated/mass_bundle_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ mass bundle build [flags]
### Options

```
-b, --build-directory string Path to a directory containing a massdriver.yaml file. (default ".")
-h, --help help for build
-b, --bundle-directory string Path to a directory containing a massdriver.yaml file. (default ".")
-h, --help help for build
```

### SEE ALSO
Expand Down
6 changes: 3 additions & 3 deletions docs/generated/mass_bundle_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ mass bundle import [flags]
### Options

```
-a, --all Import all variables without prompting
-b, --build-directory string Path to a directory containing a massdriver.yaml file. (default ".")
-h, --help help for import
-a, --all Import all variables without prompting
-b, --bundle-directory string Path to a directory containing a massdriver.yaml file. (default ".")
-h, --help help for import
```

### SEE ALSO
Expand Down
4 changes: 2 additions & 2 deletions docs/generated/mass_bundle_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ mass bundle lint [flags]
### Options

```
-b, --build-directory string Path to a directory containing a massdriver.yaml file. (default ".")
-h, --help help for lint
-b, --bundle-directory string Path to a directory containing a massdriver.yaml file. (default ".")
-h, --help help for lint
```

### SEE ALSO
Expand Down
6 changes: 3 additions & 3 deletions docs/generated/mass_bundle_publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ mass bundle publish [flags]
### Options

```
--access string Override the access, useful in CI for deploying to sandboxes. (default "private")
-b, --build-directory string Path to a directory containing a massdriver.yaml file. (default ".")
-h, --help help for publish
--access string (Deprecated) Only here for backwards compatibility. Will be removed in a future release.
-b, --bundle-directory string Path to a directory containing a massdriver.yaml file. (default ".")
-h, --help help for publish
```

### SEE ALSO
Expand Down
26 changes: 26 additions & 0 deletions docs/generated/mass_bundle_pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
id: mass_bundle_pull.md
slug: /cli/commands/mass_bundle_pull
title: Mass Bundle Pull
sidebar_label: Mass Bundle Pull
---
## mass bundle pull

Pull bundle from Massdriver to local directory

```
mass bundle pull <bundle-name> [flags]
```

### Options

```
-d, --directory string Directory to output the bundle. Defaults to bundle name.
-f, --force Force pull even if the directory already exists. This will overwrite existing files.
-h, --help help for pull
-t, --tag string Bundle tag (defaults to 'latest') (default "latest")
```

### SEE ALSO

* [mass bundle](/cli/commands/mass_bundle) - Generate and publish bundles
Loading
Loading