commands

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeployCmd = &cobra.Command{
	Use:   "deploy [repo]",
	Short: "Deploy a repository to PloyCloud server",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		repo := args[0]
		fmt.Printf("Deploying repository: %s\n", repo)

		if err := utils.CloneRepo(repo); err != nil {
			fmt.Printf("Error cloning repository: %v\n", err)
			return
		}

		fmt.Println("Deployment successful!")
	},
}
View Source
var EchoCmd = &cobra.Command{
	Use:   "echo [text]",
	Short: "Echo the input text",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		text := args[0]
		println(text)
	},
}
View Source
var ExecCmd = &cobra.Command{
	Use:   "exec",
	Short: "Execute a command in the Docker container",
	Run: func(cmd *cobra.Command, args []string) {
		composePath := utils.FindComposeFile()
		if composePath == "" {
			color.Red("No docker-compose.yml file found")
			return
		}

		if len(args) == 0 {
			color.Yellow("No command provided")
			return
		}

		composeArgs := []string{"exec"}
		if args[0] == "php" || args[0] == "nginx" || args[0] == "litespeed" {
			composeArgs = append(composeArgs, args[0])
			args = args[1:]
		} else {
			composeArgs = append(composeArgs, "php")
		}

		composeArgs = append(composeArgs, args...)

		if err := docker.RunCompose(composePath, composeArgs...); err != nil {
			color.Red("Error executing command: %v\n", err)
		}
	},
}
View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "List all deployments",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("Listing all deployments...")

	},
}
View Source
var LogsCmd = &cobra.Command{
	Use:   "logs",
	Short: "Show logs of the site in the current directory",
	Long:  `Show logs of the Docker container for the site in the current directory.`,
	Args:  cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		composePath := utils.FindComposeFile()
		if composePath == "" {
			color.Red("No docker-compose.yml file found")
			os.Exit(1)
		}

		composeArgs := []string{"logs"}
		if len(args) == 1 {
			composeArgs = append(composeArgs, args[0])
		}

		if err := docker.RunCompose(composePath, composeArgs...); err != nil {
			color.Red("Error showing logs: %v\n", err)
			os.Exit(1)
		}
	},
}
View Source
var RestartCmd = &cobra.Command{
	Use:   "restart",
	Short: "Restart the site in the current directory",
	Long:  "Restart the Docker containers for the site in the current directory.",
	Run: func(cmd *cobra.Command, args []string) {
		composePath := utils.FindComposeFile()
		if composePath == "" {
			color.Red("No docker-compose.yml file found")
			return
		}

		if err := docker.RunCompose(composePath, "restart"); err != nil {
			color.Red("Error restarting site using Docker Compose setup:", err)
		}

		color.Green("Site restarted successfully")
	},
}
View Source
var ServicesCmd = &cobra.Command{
	Use:   "services",
	Short: "Manage Global Docker Compose services",
	Long:  `Manage Global Docker Compose services including MySQL, Redis, Ofelia, and Nginx Proxy.`,
}
View Source
var SitesCmd = &cobra.Command{
	Use:   "sites",
	Short: "Manage all sites",
	Long:  `Start, stop, or restart all sites on the server.`,
}
View Source
var StartCmd = &cobra.Command{
	Use:   "start",
	Short: "Start the site in the current directory",
	Long:  "Start the Docker container for the site in the current directory",
	Run: func(cmd *cobra.Command, args []string) {
		composePath := utils.FindComposeFile()
		if composePath == "" {
			color.Red("No docker-compose.yml file found.")
			return
		}

		if err := docker.RunCompose(composePath, "up", "-d"); err != nil {
			color.Red("Error starting container:", err)
		}
	},
}
View Source
var StatusCmd = &cobra.Command{
	Use:   "status",
	Short: "Check the status of all services",
	Run: func(cmd *cobra.Command, args []string) {
		servicesDir := common.ServicesDir
		if _, err := os.Stat(servicesDir); os.IsNotExist(err) {
			color.Red(servicesDir + " directory does not exist")
		} else {
			color.Green(servicesDir + " directory exists")
		}

		globalCompose := common.GlobalCompose
		if _, err := os.Stat(globalCompose); os.IsNotExist(err) {
			color.Red(globalCompose + " does not exist")
		} else {
			color.Green(globalCompose + " exists")
		}

		provisionsDir := common.ProvisionsDir
		if _, err := os.Stat(provisionsDir); os.IsNotExist(err) {
			color.Red(provisionsDir + " directory does not exist")
		} else {
			color.Green(provisionsDir + " directory exists")
		}

		if _, err := os.Stat(common.MysqlDir); os.IsNotExist(err) {
			color.Red("MySQL directory does not exist")
		} else {
			color.Green("MySQL directory exists")
		}

		if _, err := os.Stat(common.RedisDir); os.IsNotExist(err) {
			color.Red("Redis directory does not exist")
		} else {
			color.Green("Redis directory exists")
		}

		if _, err := os.Stat(common.NginxDir); os.IsNotExist(err) {
			color.Red("Nginx directory does not exist")
		} else {
			color.Green("Nginx directory exists")
		}

		if output, err := exec.Command(
			"docker", "version", "--format", "{{.Server.Version}}",
		).CombinedOutput(); err != nil {
			color.Red("Docker is not installed")
		} else {
			color.Green("Docker is installed, version: %s", strings.TrimSpace(string(output)))
		}

		if _, err := exec.Command("docker", "version").CombinedOutput(); err != nil {
			color.Red("Docker is not running")
		} else {
			color.Green("Docker is running")
		}
	},
}
View Source
var StopCmd = &cobra.Command{
	Use:   "stop",
	Short: "Stop the site in the current directory",
	Long:  "Stop the Docker container for the site in the current directory",
	Run: func(cmd *cobra.Command, args []string) {
		composePath := utils.FindComposeFile()
		if composePath == "" {
			color.Red("No docker-compose.yml file found.")
			return
		}

		if err := docker.RunCompose(composePath, "down"); err != nil {
			color.Red("Error stopping container:", err)
		}
	},
}
View Source
var UpdateCmd = &cobra.Command{
	Use:   "update",
	Short: "Update ploy cli to the latest version",
	Run: func(cmd *cobra.Command, args []string) {
		if os.Geteuid() != 0 {
			fmt.Println("Error: The update command must be run as root.")
			fmt.Println("Please run 'sudo ploy update'")
			return
		}

		latestVersion, hasUpdate, err := utils.CheckForUpdates()
		if err != nil {
			fmt.Println("Error checking for updates:", err)
			return
		}

		if !hasUpdate {
			fmt.Println("You are already running the latest version.")
			return
		}

		fmt.Printf("New version available: %s\n", latestVersion)

		if !yesFlag {
			fmt.Print("Do you want to update? (y/n): ")
			var response string
			fmt.Scanln(&response)
			if response != "y" && response != "Y" {
				fmt.Println("Update cancelled.")
				return
			}
		}

		fmt.Println("Updating...")
		if _, err := utils.SelfUpdate(); err != nil {
			fmt.Println("Error updating:", err)
		} else {
			fmt.Println("Update successful. Please restart ploy cli.")
			os.Exit(0)
		}
	},
}
View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Print the version number of ploy cli",
	Run: func(cmd *cobra.Command, args []string) {
		println(common.CurrentCliVersion)
	},
}
View Source
var WpCmd = &cobra.Command{
	Use:   "wp",
	Short: "Execute WP-CLI commands",
	Long:  `Execute WP-CLI commands for the current WordPress site.`,
	Run: func(cmd *cobra.Command, args []string) {
		composePath := utils.FindComposeFile()
		if composePath == "" {
			color.Red("No docker-compose.yml file found.")
			return
		}

		if err := docker.RunWpCli(composePath, args); err != nil {
			color.Red("Error running wp-cli: %s", err)
		}
	},
}

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