Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 11 additions & 1 deletion cmd/action/ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package ci

import (
"fmt"
"os"

"github.com/NVIDIA/holodeck/api/holodeck/v1alpha1"
"github.com/NVIDIA/holodeck/internal/logger"
)

Expand All @@ -40,7 +42,6 @@ func Run(log *logger.FunLogger) error {
}
} else {
if err := entrypoint(log); err != nil {
log.Error(err)
if err := cleanup(log); err != nil {
return err
}
Expand All @@ -52,3 +53,12 @@ func Run(log *logger.FunLogger) error {

return nil
}

func setCfgName(cfg *v1alpha1.Environment) {
sha := os.Getenv("GITHUB_SHA")
// short sha
if len(sha) > 8 {
sha = sha[:8]
}
cfg.Name = fmt.Sprintf("ci-%s", sha)
}
3 changes: 3 additions & 0 deletions cmd/action/ci/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func cleanup(log *logger.FunLogger) error {
return fmt.Errorf("error reading config file: %s", err)
}

// Set env name
setCfgName(&cfg)

client, err := aws.New(log, cfg, cacheFile)
if err != nil {
log.Error(err)
Expand Down
14 changes: 4 additions & 10 deletions cmd/action/ci/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,16 @@ func entrypoint(log *logger.FunLogger) error {
return fmt.Errorf("error reading config file: %s", err)
}

// Set auth.PrivateKey
cfg.Spec.Auth.PrivateKey = sshKeyFile

// If no containerruntime is specified, default to none
if cfg.Spec.ContainerRuntime.Name == "" {
cfg.Spec.ContainerRuntime.Name = v1alpha1.ContainerRuntimeNone
}

// Set env name
sha := os.Getenv("GITHUB_SHA")
// short sha
if len(sha) > 8 {
sha = sha[:8]
}
if sha == "" {
log.Error(fmt.Errorf("github sha not provided"))
os.Exit(1)
}
cfg.SetName(sha)
setCfgName(&cfg)

client, err := aws.New(log, cfg, cacheFile)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/ec2 v1.142.0
github.com/aws/aws-sdk-go-v2/service/route53 v1.36.0
github.com/aws/aws-sdk-go-v2/service/ssm v1.44.6
github.com/mattn/go-isatty v0.0.20
github.com/urfave/cli/v2 v2.27.1
golang.org/x/crypto v0.17.0
k8s.io/apimachinery v0.29.0
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -114,6 +116,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
Expand Down
45 changes: 45 additions & 0 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,23 @@ import (
"os"
"sync"
"time"

"github.com/mattn/go-isatty"
)

var (
// outFile is where Out* functions send output to. Set using SetOutFile()
outFile fdWriter
// errFile is where Err* functions send output to. Set using SetErrFile()
errFile fdWriter
)

// fdWriter is the subset of file.File that implements io.Writer and Fd()
type fdWriter interface {
io.Writer
Fd() uintptr
}

const (
// ANSI escape code to reset color
reset = "\033[0m"
Expand All @@ -39,6 +54,9 @@ const (
redXEmoji = "\u274C"
// Unicode character for the warning sign
warningSign = "\u26A0"

// Unicode character for the loading emoji
loadingEmoji = "\u231B"
)

// NewLogger creates a new instance of FunLogger.
Expand Down Expand Up @@ -111,6 +129,20 @@ func printMessage(color, emoji, message string) {
func (l *FunLogger) Loading(format string, a ...any) {
defer l.Wg.Done()
message := fmt.Sprintf(format, a...)
// if running in a non-interactive terminal, don't print the loading animation
if !isInteractiveTerminal() && isCILogs() {
// print the message with loading emoji
printMessage(yellowText, loadingEmoji, message)
for {
select {
case <-l.Done:
return
case <-l.Fail:
return
}
}
}

// if message ends with a newline, remove it
if message[len(message)-1] == '\n' {
message = message[:len(message)-1]
Expand Down Expand Up @@ -143,6 +175,19 @@ func (l *FunLogger) Loading(format string, a ...any) {
}
}

func isInteractiveTerminal() bool {
return isTerminal(os.Stdout)
}

// isTerminal returns whether we have a terminal or not
func isTerminal(w fdWriter) bool {
return isatty.IsTerminal(w.Fd())
}

func isCILogs() bool {
return os.Getenv("CI") == "true"
}

func (l *FunLogger) Exit(code int) {
// Stop the loading animation if it's running
close(l.Done)
Expand Down
2 changes: 1 addition & 1 deletion pkg/provisioner/dryrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Dryrun(log *logger.FunLogger, env v1alpha1.Environment) error {
// Resolve dependencies from top to bottom
log.Wg.Add(1)

go log.Loading("Resolving dependencies \U0001F4E6")
go log.Loading("Resolving dependencies \U0001F4E6\n")
// Kubernetes -> Container Toolkit -> Container Runtime -> NVDriver
if env.Spec.Kubernetes.Install {
// check if env.Spec.Kubernetes.KubernetesVersion is in the format of vX.Y.Z
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions vendor/github.com/mattn/go-isatty/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading