project

package
v1.3.1-0...-3e602c1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2023 License: GPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeployApplication = func() *cobra.Command {
	var autoConfirm bool
	var noRollback bool
	command := &cobra.Command{
		Use:     "deploy [path to project definition] [ipv4 address]",
		Example: "deploy ./my_project.yml 192.168.178.14",
		Short:   "Deploy a project onto the target server",
		Long:    `deploy will deploy the given project onto the server`,
		Args:    cobra.ExactArgs(2),
		Run: func(cmd *cobra.Command, args []string) {
			projectDefinition, err := project.LoadProjectDefinition(args[0])
			if err != nil {
				panic("unable to load project definition file. " + err.Error())
			}
			commands.PrepareContext(args[1], system.ContextActionProjectDeploy, projectDefinition)
			taskRunner := routines.TaskRunner{}

			if err := taskRunner.RunTask(routines.ValidateStackHeadVersionTask); err != nil {
				return
			}

			for _, module := range system.Context.GetModulesInOrder() {
				moduleSettings := system.GetModuleSettings(module.GetConfig().Name)
				module.Init(moduleSettings)
			}

			err = taskRunner.RunTask(routines.PrepareProjectTask(projectDefinition))
			if err != nil {
				return
			}
			err = taskRunner.RunTask(routines.CollectResourcesTask(projectDefinition))
			if err != nil {
				return
			}

			if autoConfirm {
				_ = taskRunner.RunTask(routines.CreateResources)
			} else {

				fmt.Println("\nStackHead will try to create or update the following resources:")
				for _, resourceGroup := range system.Context.Resources {
					for _, resource := range resourceGroup.Resources {
						fmt.Println(fmt.Sprintf("- %s", resource.ToString(false)))
					}
				}
				fmt.Println("")
				fmt.Print("Please confirm with \"y\" or \"yes\": ")
				if askForConfirmation() {
					_ = taskRunner.RunTask(routines.CreateResources)
				}
			}

			if !noRollback {

				_ = taskRunner.RunTask(routines.RollbackResources)
			}
		},
	}
	command.PersistentFlags().BoolVar(&autoConfirm, "autoconfirm", false, "Whether to auto-confirm resource changes")
	command.PersistentFlags().BoolVar(&noRollback, "no-rollback", false, "Do not rollback on errors")
	return command
}

DeployApplication is a command object for Cobra that provides the deploy command

View Source
var DestroyApplication = &cobra.Command{
	Use:     "destroy [path to project definition] [ipv4 address]",
	Example: "destroy ./my_project.yml 192.168.178.14",
	Short:   "Destroy a deployed project on a target server",
	Long:    `destroy will tear down the given project that has been deployed onto the server`,
	Args:    cobra.ExactArgs(2),
	Run: func(cmd *cobra.Command, args []string) {
		projectDefinition, err := project.LoadProjectDefinition(args[0])
		if err != nil {
			panic("unable to load project definition file. " + err.Error())
		}
		commands.PrepareContext(args[1], system.ContextActionProjectDeploy, projectDefinition)

		modules := system.Context.GetModulesInOrder()
		for i, j := 0, len(modules)-1; i < j; i, j = i+1, j-1 {
			modules[i], modules[j] = modules[j], modules[i]
		}

		for _, module := range modules {
			moduleSettings := system.GetModuleSettings(module.GetConfig().Name)
			module.Init(moduleSettings)
		}
		taskRunner := routines.TaskRunner{}

		subTasks := []routines.Task{}

		if hasProjectDir, _ := xfs.HasFolder("ssh://" + projectDefinition.GetDirectoryPath()); hasProjectDir {

			for _, module := range modules {
				moduleSettings := system.GetModuleSettings(module.GetConfig().Name)
				subTasks = append(subTasks, routines.Task{
					Name: "Remove module configurations for " + module.GetConfig().Name,
					Run: func(r *routines.Task) error {
						return module.Destroy(moduleSettings)
					},
					IsSubtask:           true,
					ErrorAsErrorMessage: true,
				})
			}

			subTasks = append(subTasks, routines.Task{
				Name: "Removing project directory",
				Run: func(r *routines.Task) error {
					return xfs.DeleteFolder("ssh://"+projectDefinition.GetDirectoryPath(), true)
				},
				IsSubtask:           true,
				ErrorAsErrorMessage: true,
			})
		}

		_ = taskRunner.RunTask(routines.Task{
			Name: fmt.Sprintf("Destroying project \"%s\" on server with IP \"%s\"", args[0], args[1]),
			Run: func(r *routines.Task) error {
				return nil
			},
			SubTasks: subTasks,
		})
	},
}

DestroyApplication is a command object for Cobra that provides the destroy command

Functions

func GetCommands

func GetCommands(LocalSchemas embed.FS) *cobra.Command

func Validate

func Validate(LocalSchemas embed.FS) *cobra.Command

Validate is a command object for Cobra that provides the validate command

Types

This section is empty.

Jump to

Keyboard shortcuts

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