2019-12-27 23:06:32 +00:00
|
|
|
package run
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-01-16 21:50:04 +00:00
|
|
|
"github.com/pelotech/drone-helm3/internal/env"
|
2019-12-27 23:06:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DepUpdate is an execution step that calls `helm dependency update` when executed.
|
|
|
|
type DepUpdate struct {
|
2020-01-17 18:13:53 +00:00
|
|
|
*config
|
|
|
|
chart string
|
2019-12-27 23:06:32 +00:00
|
|
|
cmd cmd
|
|
|
|
}
|
|
|
|
|
2020-01-16 21:50:04 +00:00
|
|
|
// NewDepUpdate creates a DepUpdate using fields from the given Config. No validation is performed at this time.
|
|
|
|
func NewDepUpdate(cfg env.Config) *DepUpdate {
|
|
|
|
return &DepUpdate{
|
2020-01-17 18:13:53 +00:00
|
|
|
config: newConfig(cfg),
|
|
|
|
chart: cfg.Chart,
|
2020-01-16 21:50:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-27 23:06:32 +00:00
|
|
|
// Execute executes the `helm upgrade` command.
|
2020-01-16 23:30:21 +00:00
|
|
|
func (d *DepUpdate) Execute() error {
|
2019-12-27 23:06:32 +00:00
|
|
|
return d.cmd.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare gets the DepUpdate ready to execute.
|
2020-01-17 18:13:53 +00:00
|
|
|
func (d *DepUpdate) Prepare() error {
|
|
|
|
if d.chart == "" {
|
2019-12-27 23:06:32 +00:00
|
|
|
return fmt.Errorf("chart is required")
|
|
|
|
}
|
|
|
|
|
2020-01-17 19:12:53 +00:00
|
|
|
args := d.globalFlags()
|
2020-01-17 18:13:53 +00:00
|
|
|
args = append(args, "dependency", "update", d.chart)
|
2019-12-27 23:06:32 +00:00
|
|
|
|
|
|
|
d.cmd = command(helmBin, args...)
|
2020-01-17 18:13:53 +00:00
|
|
|
d.cmd.Stdout(d.stdout)
|
|
|
|
d.cmd.Stderr(d.stderr)
|
2019-12-27 23:06:32 +00:00
|
|
|
|
2020-01-17 18:13:53 +00:00
|
|
|
if d.debug {
|
|
|
|
fmt.Fprintf(d.stderr, "Generated command: '%s'\n", d.cmd.String())
|
2019-12-27 23:06:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|