Skip to content

Commit

Permalink
Merge pull request #5 from shikingram/fix_upgrade_clean
Browse files Browse the repository at this point in the history
Fix upgrade clean
  • Loading branch information
shikingram authored Sep 29, 2022
2 parents e58613e + b250957 commit ab34f21
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
4 changes: 2 additions & 2 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func addValueOptionsFlags(f *pflag.FlagSet, v *values.Options) {

func addChartPathOptionsFlags(f *pflag.FlagSet, c *action.ChartPathOptions) {
f.StringVar(&c.Version, "version", "", "specify a version constraint for the chart version to use. This constraint can be a specific tag (e.g. 1.1.1) or it may reference a valid range (e.g. ^2.0.0). If this is not specified, the latest version is used")
f.StringVar(&c.Username, "username", "", "chart repository username where to locate the requested chart")
f.StringVar(&c.Password, "password", "", "chart repository password where to locate the requested chart")
// f.StringVar(&c.Username, "username", "", "chart repository username where to locate the requested chart")
// f.StringVar(&c.Password, "password", "", "chart repository password where to locate the requested chart")
}

func bindOutputFlag(cmd *cobra.Command, varRef *output.Format) {
Expand Down
1 change: 1 addition & 0 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func addUpgradeFlags(cmd *cobra.Command, f *pflag.FlagSet, client *action.Upgrad
// f.BoolVar(&client.UseReleaseName, "release-name", false, "use release name in the output-dir path.")
f.BoolVar(&client.Force, "force", false, "force resource updates through a replacement strategy")
addValueOptionsFlags(f, valueOpts)
addChartPathOptionsFlags(f, &client.ChartPathOptions)
}

func runUpgrade(args []string, client *action.Upgrade, valueOpts *values.Options) error {
Expand Down
43 changes: 12 additions & 31 deletions pkg/deploy/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import (
"github.com/bitfield/script"
)

const ps = `docker ps --filter "label=com.docker.compose.project" -q`
const inspect = `xargs docker inspect --format='{{index .Config.Labels "com.docker.compose.project"}}'`
const dprefix = `ad-`

// start docker-compose
func Start(file, name string) error {
basefile := filepath.Base(file)
pname := basefile[7:strings.LastIndex(basefile, ".yaml")]
pname = "ad-" + name + "-" + pname
pname = dprefix + name + "-" + pname
cmd := fmt.Sprintf("docker compose -f %s -p %s up -d --remove-orphans", file, pname)
return exec(cmd)
}
Expand All @@ -36,15 +35,15 @@ func Stop(file string) error {
func Down(file, name string) error {
basefile := filepath.Base(file)
pname := basefile[7:strings.LastIndex(basefile, ".yaml")]
pname = "ad-" + name + "-" + pname
pname = dprefix + name + "-" + pname
cmd := fmt.Sprintf("docker compose -f %s -p %s down --remove-orphans", file, pname)
return exec(cmd)
}

func Restart(file, name string) error {
basefile := filepath.Base(file)
pname := basefile[7:strings.LastIndex(basefile, ".yaml")]
pname = "ad-" + name + "-" + pname
pname = dprefix + name + "-" + pname
cmd1 := fmt.Sprintf("docker compose -f %s -p %s up -d --remove-orphans", file, pname)

cmd2 := fmt.Sprintf("docker compose -f %s -p %s restart", file, pname)
Expand All @@ -58,36 +57,18 @@ func Restart(file, name string) error {
}

func CheckReleaseDeploy(name string) (int, error) {

if l, err := script.Exec(ps).CountLines(); err == nil && l > 0 {
return script.Exec(ps).
Exec(inspect).
Exec(`sort`).
Exec(`uniq`).
Match(name).
CountLines()
}

return 0, nil

return script.Exec(`docker compose ls`).Match(dprefix).Match(name).CountLines()
}

func ListRelease(name string) error {

if l, err := script.Exec(ps).CountLines(); err == nil && l > 0 {

pipe := script.Exec(ps).Exec(inspect).Exec(`sort`).Exec(`uniq`)
pipe := script.Exec(`docker compose ls`)

var e error
if len(name) > 0 {
_, e = pipe.Match(name).Stdout()
} else {
_, e = pipe.Stdout()
}
if e != nil {
return e
}
var e error
if len(name) > 0 {
_, e = pipe.Match(dprefix).Match(name).Stdout()
} else {
_, e = pipe.Match(dprefix).Stdout()
}

return nil
return e
}

0 comments on commit ab34f21

Please sign in to comment.