Skip to content

Commit

Permalink
Merge branch 'master' into add-ignore-images-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
tashima42 authored Aug 7, 2024
2 parents d012197 + 5803f67 commit fae45b7
Showing 3 changed files with 102 additions and 7 deletions.
32 changes: 32 additions & 0 deletions cmd/release/cmd/list.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import (
"errors"
"fmt"

"github.com/rancher/ecm-distro-tools/release/charts"
"github.com/rancher/ecm-distro-tools/release/rancher"
"github.com/spf13/cobra"
)
@@ -43,8 +44,39 @@ var rancherListRCDepsSubCmd = &cobra.Command{
},
}

var chartsListSubCmd = &cobra.Command{
Use: "charts [branch] [charts](optional)",
Short: "List Charts assets versions state for release process",
RunE: func(cmd *cobra.Command, args []string) error {
var branch, chart string

if len(args) < 1 {
return errors.New("expected at least one argument: [branch]")
}
branch = args[0]

if len(args) > 1 {
chart = args[1]
}

config := rootConfig.Charts
if config.Workspace == "" || config.ChartsForkURL == "" {
return errors.New("verify your config file, chart configuration not implemented correctly, you must insert workspace path and your forked repo url")
}

resp, err := charts.List(context.Background(), config, branch, chart)
if err != nil {
return err
}

fmt.Println(resp)
return nil
},
}

func init() {
rancherListSubCmd.AddCommand(rancherListRCDepsSubCmd)
listCmd.AddCommand(rancherListSubCmd)
listCmd.AddCommand(chartsListSubCmd)
rootCmd.AddCommand(listCmd)
}
20 changes: 13 additions & 7 deletions cmd/release/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"log"
"os"
"strings"
@@ -20,17 +21,19 @@ var (

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "release",
Short: "Central command to perform RKE2, K3s and Rancher Releases",
SilenceUsage: true,
Use: "release",
Short: "Central command to perform RKE2, K3s, Rancher and Chart Releases",
SilenceUsage: true,
SilenceErrors: true,
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
cobra.OnInitialize(initConfig)
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
fmt.Println("error: ", err)
os.Exit(1)
}
}

@@ -57,22 +60,25 @@ func initConfig() {
if stringConfig != "" {
conf, err = config.Read(strings.NewReader(stringConfig))
if err != nil {
panic(err)
fmt.Println(err)
os.Exit(1)
}
} else {
configFile = os.ExpandEnv(configFile)
conf, err = config.Load(configFile)
if err != nil {
log.Println("failed to load config, use 'release config gen' to create a new one at: " + configFile)
panic(err)
fmt.Println(err)
os.Exit(1)
}
}

rootConfig = conf

if !ignoreValidate {
if err := rootConfig.Validate(); err != nil {
panic(err)
fmt.Println(err)
os.Exit(1)
}
}
}
57 changes: 57 additions & 0 deletions release/charts/charts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package charts

import (
"context"
"fmt"
"os"
"os/exec"
"strings"

"github.com/rancher/ecm-distro-tools/cmd/release/config"
)

// List prints the lifecycle status of the charts
func List(ctx context.Context, c *config.ChartsRelease, branch, chart string) (string, error) {
var branchArg, chartArg string

branchArg = "--branch-version=" + branch
if chart != "" {
chartArg = "--chart=" + chart
}

output, err := runChartsBuild(c.Workspace, "lifecycle-status", branchArg, chartArg)
if err != nil {
return "", err
}

response := string(output) + fmt.Sprintf("\ngenerated log files for inspection at: \n%s\n", c.Workspace+"/logs/")
return response, nil
}

func runChartsBuild(chartsRepoPath string, args ...string) ([]byte, error) {
// save current working dir
ecmWorkDir, err := os.Getwd()
if err != nil {
return nil, err
}

// change working dir to the charts repo
if err := os.Chdir(chartsRepoPath); err != nil {
return nil, err
}

bin := strings.Join([]string{chartsRepoPath, "bin", "charts-build-scripts"}, string(os.PathSeparator))

cmd := exec.Command(bin, args...)
output, err := cmd.CombinedOutput()
if err != nil {
return nil, err
}

// Change back working dir for the caller
if err := os.Chdir(ecmWorkDir); err != nil {
return nil, err
}

return output, nil
}

0 comments on commit fae45b7

Please sign in to comment.