deploy

package
v0.22.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeployCmd = &cobra.Command{
	Use:   "deploy <deployment>",
	Short: "Run a deployment",
	Long: `
The deploy command runs a deployment for a given deployment name.

Usage:
	hyphen deploy <deployment> [flags]

Examples:
hyphen deploy deploy-dev

Use 'hyphen deploy --help' for more information about available flags.
`,
	Args: cobra.RangeArgs(0, 1),
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		return user.ErrorIfNotAuthenticated()
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		orgId, err := flags.GetOrganizationID()
		if err != nil {
			return err
		}

		deploymentName := ""
		if len(args) > 0 {
			deploymentName = args[0]
		}

		printer = cprint.NewCPrinter(flags.VerboseFlag)

		service := Deployment.NewService()

		deployments, err := service.SearchDeployments(orgId, deploymentName, 50, 1)

		if err != nil {
			return fmt.Errorf("failed to list apps: %w", err)
		}

		selectedDeployment := deployments[0]

		if len(deployments) > 1 {
			choices := make([]prompt.Choice, len(deployments))
			for i, deployment := range deployments {
				choices[i] = prompt.Choice{
					Id:      deployment.ID,
					Display: fmt.Sprintf("%s (%s)", deployment.Name, deployment.ID),
				}
			}

			choice, err := prompt.PromptSelection(choices, "Select a deployment to run:")

			if err != nil {
				return err
			}

			if choice.Id == "" {
				printer.YellowPrint(("no choice made, canceling deploy"))
				return nil
			}

			for _, deployment := range deployments {
				if deployment.ID == choice.Id {
					selectedDeployment = deployment
					break
				}
			}
		}

		if !selectedDeployment.IsReady {
			printer.Print("❌ There are issues blocking this deployment from being run.")
			for _, issue := range selectedDeployment.ReadinessIssues {
				if issue.Cloud != "" {
					printer.Print(fmt.Sprintf("  • %s (%s)", issue.Error, issue.Cloud))
				} else {
					printer.Print(fmt.Sprintf("  • %s", issue.Error))
				}
			}
			return nil
		}

		appSources := []Deployment.AppSources{}

		if noBuild {

		} else {

			firstApp := selectedDeployment.Apps[0]

			service := build.NewService()
			result, err := service.RunBuild(cmd, printer, firstApp.DeploymentSettings.ProjectEnvironment.ID, flags.VerboseFlag, flags.DockerfileFlag)
			if err != nil {
				return err
			}
			appSources = append(appSources, Deployment.AppSources{
				AppId:    result.App.ID,
				Artifact: result.Artifact,
			},
			)
		}

		printer.Print(fmt.Sprintf("Running %s", selectedDeployment.Name))

		run, err := service.CreateRun(orgId, selectedDeployment.ID, appSources)
		if err != nil {
			return fmt.Errorf("failed to create run: %w", err)
		}

		appUrl := fmt.Sprintf("%s/%s/deploy/%s/runs/%s", apiconf.GetBaseAppUrl(), orgId, selectedDeployment.ID, run.ID)

		if shouldUseTUI() {
			runWithTUI(orgId, selectedDeployment.ID, run, appUrl, service)
		} else {
			runWithoutTUI(orgId, selectedDeployment.ID, run, appUrl, service)
		}

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL