Skip to content

Commit

Permalink
Prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
INGE KNUDSEN authored and INGE KNUDSEN committed Dec 22, 2019
1 parent c98eb54 commit 97565f8
Show file tree
Hide file tree
Showing 6 changed files with 499 additions and 27 deletions.
12 changes: 11 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"env": {},
"args": ["build", "-a", "radix-platform", "-b", "master", "-f"]
"args": [
"--from-config",
"--cluster",
"weekly-47",
"--environment",
"qa",
"build",
"-b",
"master",
"-f"
]
}
]
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# radix-cli

NOTE: This project is currently work in progress

The command line interface for Radix, which is to enable users of Radix platform in automation around their application on the platform. This document is for developers of the Radix CLI, or anyone interested in poking around.

## How to run
Expand Down
75 changes: 51 additions & 24 deletions cmd/buildApplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd
import (
"errors"
"fmt"
"strings"
"time"

"github.com/equinor/radix-cli/generated-client/client/application"
Expand Down Expand Up @@ -47,6 +48,14 @@ var buildApplicationCmd = &cobra.Command{
appName, _ := cmd.Flags().GetString("application")
branch, _ := cmd.Flags().GetString("branch")
follow, _ := cmd.Flags().GetBool("follow")
fromConfig, _ := cmd.Flags().GetBool("from-config")

if fromConfig {
radicConfig, _ := getRadixApplicationFromFile()
if appName == "" {
appName = radicConfig.GetName()
}
}

if appName == "" || branch == "" {
return errors.New("Application name and branch are required")
Expand All @@ -69,42 +78,60 @@ var buildApplicationCmd = &cobra.Command{
}

if follow {
jobName := newJob.GetPayload().Name

jobParameters := job.NewGetApplicationJobParams()
jobParameters.SetAppName(appName)
jobParameters.SetJobName(newJob.GetPayload().Name)
jobParameters.SetJobName(jobName)

fmt.Fprintf(cmd.OutOrStdout(), "\r%s", fmt.Sprintf("Building %s on branch %s with name %s", cyan(appName), yellow(branch), yellow(jobName)))

newJobName := newJob.GetPayload().Name
m := fmt.Sprintf("Building %s on branch %s with name %s", cyan(appName), yellow(branch), yellow(newJobName))
s := `-\|/-`
i := 0
buildComplete := false

refreshApplication := time.After(deltaRefreshApplication)
tick := time.Tick(deltaRefreshOutput)
numLogLinesOutput := 0
refreshApplication := time.Tick(deltaRefreshApplication)

for {
select {
case <-refreshApplication:
respJob, _ := apiClient.Job.GetApplicationJob(jobParameters, nil)
jobSummary := respJob.Payload
if jobSummary.Status == "Succeeded" {
fmt.Fprintf(cmd.OutOrStdout(), fmt.Sprintf("%s", green("\nBuild complete\n")))
buildComplete = true
} else if jobSummary.Status == "Failed" {
fmt.Fprintf(cmd.OutOrStdout(), fmt.Sprintf("%s", red("\nBuild failed\n")))
buildComplete = true
jobLogParameters := job.NewGetApplicationJobLogsParams()
jobLogParameters.SetAppName(appName)
jobLogParameters.SetJobName(jobName)

respJobLog, _ := apiClient.Job.GetApplicationJobLogs(jobLogParameters, nil)
if respJobLog != nil {
numLogLines := 0

stepsLog := respJobLog.Payload
for _, stepLog := range stepsLog {
stepLogLines := strings.Split(strings.Replace(stepLog.Log, "\r\n", "\n", -1), "\n")

for _, stepLogLine := range stepLogLines {
if numLogLinesOutput <= numLogLines {
fmt.Fprintf(cmd.OutOrStdout(), "\r\n%s", stepLogLine)
numLogLinesOutput++
}

numLogLines++
}
}
}

if buildComplete {
return nil
respJob, _ := apiClient.Job.GetApplicationJob(jobParameters, nil)
if respJob != nil {
jobSummary := respJob.Payload
if jobSummary.Status == "Succeeded" {
fmt.Fprintf(cmd.OutOrStdout(), fmt.Sprintf("%s", green("\nBuild complete\n")))
buildComplete = true
} else if jobSummary.Status == "Failed" {
fmt.Fprintf(cmd.OutOrStdout(), fmt.Sprintf("%s", red("\nBuild failed\n")))
buildComplete = true
}

if buildComplete {
return nil
}
}

// Reset timer
refreshApplication = time.After(deltaRefreshApplication)

case <-tick:
fmt.Fprintf(cmd.OutOrStdout(), "\r%s %c", m, s[i%len(s)])
i++
}

}
Expand Down
21 changes: 21 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package cmd
import (
"fmt"
"os"
"path/filepath"

radixconfig "github.com/equinor/radix-cli/pkg/config"
v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/equinor/radix-operator/pkg/apis/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -24,9 +28,26 @@ func Execute() {
}

func init() {
rootCmd.PersistentFlags().BoolP("from-config", "", false, "Read and use radix config from file as context")
rootCmd.PersistentFlags().BoolP("token-stdin", "", false, "Take the token from stdin")
rootCmd.PersistentFlags().StringP("context", "c", "", fmt.Sprintf("Use context %s|%s|%s regardless of current context",
radixconfig.ContextProdction, radixconfig.ContextPlayground, radixconfig.ContextDevelopment))
rootCmd.PersistentFlags().StringP("cluster", "k", "", "Set cluster to override context")
rootCmd.PersistentFlags().StringP("environment", "e", "prod", "The API environment to run with")
}

func getRadixApplicationFromFile() (*v1.RadixApplication, error) {
filePath, _ := filepath.Abs("./radixconfig.yaml")
return loadConfigFromFile(filePath)
}

// LoadConfigFromFile loads radix config from appFileName
func loadConfigFromFile(appFileName string) (*v1.RadixApplication, error) {
radixApplication, err := utils.GetRadixApplication(appFileName)
if err != nil {
log.Errorf("Failed to get ra from file (%s) for app Error: %v", appFileName, err)
return nil, err
}

return radixApplication, nil
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.13

require (
contrib.go.opencensus.io/exporter/ocagent v0.6.0 // indirect
github.com/Azure/go-autorest v11.9.0+incompatible // indirect
github.com/equinor/radix-operator v1.4.1
github.com/fatih/color v1.7.0
github.com/go-openapi/errors v0.19.3
github.com/go-openapi/runtime v0.19.9
Expand All @@ -21,7 +21,6 @@ require (
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
k8s.io/apimachinery v0.0.0-20191020214737-6c8691705fc5
k8s.io/client-go v12.0.0+incompatible
k8s.io/utils v0.0.0-20191010214722-8d271d903fe4 // indirect
)

replace k8s.io/client-go => k8s.io/client-go v0.0.0-20190620085101-78d2af792bab
Loading

0 comments on commit 97565f8

Please sign in to comment.