Skip to content

Commit

Permalink
Merge pull request #103 from rakshita-kaulgud/main
Browse files Browse the repository at this point in the history
Issue #93 : Changes to check for docker and docker compose status on …
  • Loading branch information
nguyer committed Oct 25, 2021
2 parents 88b6582 + 32ab1c3 commit c1cefc6
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"fmt"

"github.com/hyperledger/firefly-cli/internal/docker"
"github.com/hyperledger/firefly-cli/internal/stacks"
"github.com/spf13/cobra"
)
Expand All @@ -29,6 +30,9 @@ var infoCmd = &cobra.Command{
Long: `Get info about a stack such as each container name
and image version.`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := docker.CheckDockerConfig(); err != nil {
return err
}
stackManager := stacks.NewStackManager(logger)
if len(args) == 0 {
return fmt.Errorf("no stack specified")
Expand Down
4 changes: 4 additions & 0 deletions cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ var logsCmd = &cobra.Command{
The most recent logs can be viewed, or you can follow the
output with the -f flag.`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := docker.CheckDockerConfig(); err != nil {
return err
}

if len(args) == 0 {
return fmt.Errorf("no stack specified")
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path/filepath"

"github.com/hyperledger/firefly-cli/internal/constants"
"github.com/hyperledger/firefly-cli/internal/docker"
"github.com/hyperledger/firefly-cli/internal/stacks"
"github.com/spf13/cobra"
)
Expand All @@ -35,6 +36,9 @@ var removeCmd = &cobra.Command{
This command will completely delete a stack, including all of its data
and configuration.`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := docker.CheckDockerConfig(); err != nil {
return err
}
stackManager := stacks.NewStackManager(logger)
if len(args) == 0 {
return fmt.Errorf("no stack specified")
Expand Down
6 changes: 6 additions & 0 deletions cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"fmt"

"github.com/hyperledger/firefly-cli/internal/docker"
"github.com/hyperledger/firefly-cli/internal/stacks"
"github.com/spf13/cobra"
)
Expand All @@ -34,6 +35,11 @@ but don't want to actually recreate the resources in the stack itself.
Note: this will also stop the stack if it is running.
`,
RunE: func(cmd *cobra.Command, args []string) error {

if err := docker.CheckDockerConfig(); err != nil {
return err
}

stackManager := stacks.NewStackManager(logger)
if len(args) == 0 {
return fmt.Errorf("no stack specified")
Expand Down
6 changes: 5 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/briandowns/spinner"
"github.com/hyperledger/firefly-cli/internal/docker"
"github.com/hyperledger/firefly-cli/internal/log"
"github.com/hyperledger/firefly-cli/internal/stacks"
"github.com/spf13/cobra"
Expand All @@ -46,6 +47,10 @@ This command will start a stack and run it in the background.
}
}

if err := docker.CheckDockerConfig(); err != nil {
return err
}

stackManager := stacks.NewStackManager(logger)
if len(args) == 0 {
return errors.New("no stack specified")
Expand Down Expand Up @@ -82,6 +87,5 @@ This command will start a stack and run it in the background.

func init() {
startCmd.Flags().BoolVarP(&startOptions.NoRollback, "no-rollback", "b", false, "Do not automatically rollback changes if first time setup fails")

rootCmd.AddCommand(startCmd)
}
4 changes: 4 additions & 0 deletions cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"fmt"

"github.com/hyperledger/firefly-cli/internal/docker"
"github.com/hyperledger/firefly-cli/internal/stacks"
"github.com/spf13/cobra"
)
Expand All @@ -29,6 +30,9 @@ var stopCmd = &cobra.Command{
Short: "Stop a stack",
Long: `Stop a stack`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := docker.CheckDockerConfig(); err != nil {
return err
}
stackManager := stacks.NewStackManager(logger)
if len(args) == 0 {
return fmt.Errorf("no stack specified")
Expand Down
31 changes: 31 additions & 0 deletions internal/docker/docker_checks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package docker

import (
"fmt"
"os/exec"
)

// CheckDockerConfig is a function to check docker and docker-compose configuration on the host
func CheckDockerConfig() error {

dockerCmd := exec.Command("docker", "-v")
_, err := dockerCmd.Output()
if err != nil {
return fmt.Errorf("An error occurred while running docker. Is docker installed on your computer?")
}

dockerComposeCmd := exec.Command("docker-compose", "-v")
_, err = dockerComposeCmd.Output()

if err != nil {
return fmt.Errorf("An error occurred while running docker-compose. Is docker-compose installed on your computer?")
}

dockerDeamonCheck := exec.Command("docker", "ps")
_, err = dockerDeamonCheck.Output()
if err != nil {
return fmt.Errorf("An error occurred while running docker. Is docker running on your computer?")
}

return nil
}

0 comments on commit c1cefc6

Please sign in to comment.