mirror of
https://github.com/foomo/gograpple.git
synced 2025-10-16 12:35:37 +00:00
36 lines
723 B
Go
36 lines
723 B
Go
package exec
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
type HelmCmd struct {
|
|
Cmd
|
|
}
|
|
|
|
func NewHelmCommand() *HelmCmd {
|
|
return &HelmCmd{*NewCommand("helm")}
|
|
}
|
|
|
|
func (c HelmCmd) Rollback(deployment string, revision int) *Cmd {
|
|
return c.Args("rollback", deployment, fmt.Sprint(revision), "--force")
|
|
}
|
|
|
|
func (c HelmCmd) GetLatestRevision(ctx context.Context, deployment string) (int, error) {
|
|
// since were piping well be using bash
|
|
out, err := NewCommand("bash").
|
|
Args("-c", fmt.Sprintf("helm history %v | tail -1 | cut -d ' ' -f1", deployment)).
|
|
Run(ctx)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
revision, err := strconv.Atoi(strings.Trim(out, "\n"))
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return revision, nil
|
|
}
|