mirror of
https://github.com/aljazceru/nigiri.git
synced 2025-12-17 06:14:19 +01:00
supports docker compose and docker-compose (#171)
This commit is contained in:
@@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@@ -34,7 +33,7 @@ func logsAction(ctx *cli.Context) error {
|
|||||||
datadir := ctx.String("datadir")
|
datadir := ctx.String("datadir")
|
||||||
composePath := filepath.Join(datadir, config.DefaultCompose)
|
composePath := filepath.Join(datadir, config.DefaultCompose)
|
||||||
|
|
||||||
bashCmd := exec.Command("docker-compose", "-f", composePath, "logs", serviceName)
|
bashCmd := runDockerCompose(composePath, "logs", serviceName)
|
||||||
bashCmd.Stdout = os.Stdout
|
bashCmd.Stdout = os.Stdout
|
||||||
bashCmd.Stderr = os.Stderr
|
bashCmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -213,3 +214,16 @@ func cleanAndExpandPath(path string) string {
|
|||||||
// but the variables can still be expanded via POSIX-style $VARIABLE.
|
// but the variables can still be expanded via POSIX-style $VARIABLE.
|
||||||
return filepath.Clean(os.ExpandEnv(path))
|
return filepath.Clean(os.ExpandEnv(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// runDockerCompose runs docker-compose with the given arguments
|
||||||
|
func runDockerCompose(composePath string, args ...string) *exec.Cmd {
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
|
||||||
|
_, err := exec.LookPath("docker-compose")
|
||||||
|
if err != nil {
|
||||||
|
cmd = exec.Command("docker", append([]string{"compose", "-f", composePath}, args...)...)
|
||||||
|
} else {
|
||||||
|
cmd = exec.Command("docker-compose", append([]string{"-f", composePath}, args...)...)
|
||||||
|
}
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -71,10 +70,10 @@ func startAction(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
args := []string{"-f", composePath, "up", "-d"}
|
args := []string{"up", "-d"}
|
||||||
args = append(args, servicesToRun...)
|
args = append(args, servicesToRun...)
|
||||||
|
|
||||||
bashCmd := exec.Command("docker-compose", args...)
|
bashCmd := runDockerCompose(composePath, args...)
|
||||||
bashCmd.Stdout = os.Stdout
|
bashCmd.Stdout = os.Stdout
|
||||||
bashCmd.Stderr = os.Stderr
|
bashCmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -31,9 +30,9 @@ func stopAction(ctx *cli.Context) error {
|
|||||||
datadir := ctx.String("datadir")
|
datadir := ctx.String("datadir")
|
||||||
composePath := filepath.Join(datadir, config.DefaultCompose)
|
composePath := filepath.Join(datadir, config.DefaultCompose)
|
||||||
|
|
||||||
bashCmd := exec.Command("docker-compose", "-f", composePath, "stop")
|
bashCmd := runDockerCompose(composePath, "stop")
|
||||||
if delete {
|
if delete {
|
||||||
bashCmd = exec.Command("docker-compose", "-f", composePath, "down", "--volumes")
|
bashCmd = runDockerCompose(composePath, "down", "--volumes")
|
||||||
}
|
}
|
||||||
bashCmd.Stdout = os.Stdout
|
bashCmd.Stdout = os.Stdout
|
||||||
bashCmd.Stderr = os.Stderr
|
bashCmd.Stderr = os.Stderr
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@@ -19,7 +18,7 @@ func updateAction(ctx *cli.Context) error {
|
|||||||
datadir := ctx.String("datadir")
|
datadir := ctx.String("datadir")
|
||||||
composePath := filepath.Join(datadir, config.DefaultCompose)
|
composePath := filepath.Join(datadir, config.DefaultCompose)
|
||||||
|
|
||||||
bashCmd := exec.Command("docker-compose", "-f", composePath, "pull")
|
bashCmd := runDockerCompose(composePath, "pull")
|
||||||
bashCmd.Stdout = os.Stdout
|
bashCmd.Stdout = os.Stdout
|
||||||
bashCmd.Stderr = os.Stderr
|
bashCmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -6,7 +6,7 @@ require (
|
|||||||
github.com/btcsuite/btcd v0.21.0-beta // indirect
|
github.com/btcsuite/btcd v0.21.0-beta // indirect
|
||||||
github.com/btcsuite/btcutil v1.0.2
|
github.com/btcsuite/btcutil v1.0.2
|
||||||
github.com/compose-spec/compose-go v0.0.0-20210729195839-de56f4f0cb3c
|
github.com/compose-spec/compose-go v0.0.0-20210729195839-de56f4f0cb3c
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
github.com/logrusorgru/aurora v2.0.3+incompatible
|
||||||
github.com/urfave/cli/v2 v2.3.0
|
github.com/urfave/cli/v2 v2.3.0
|
||||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
|
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
|
||||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
||||||
|
|||||||
Reference in New Issue
Block a user