Skip to content

show compose progress #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/pkg/cli/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (

const (
MiB = 1024 * 1024
ContextFileLimit = 10
ContextSizeLimit = 10 * MiB
sourceDateEpoch = 315532800 // 1980-01-01, same as nix-shell
defaultDockerIgnore = `# Default .dockerignore file for Defang
**/.DS_Store
Expand Down Expand Up @@ -394,6 +396,7 @@ func createTarball(ctx context.Context, root, dockerfile string) (*bytes.Buffer,
gzipWriter := &contextAwareWriter{ctx, gzip.NewWriter(&buf)}
tarWriter := tar.NewWriter(gzipWriter)

doProgress := term.DoColor(term.Stdout) && term.IsTerminal
err = filepath.WalkDir(root, func(path string, de os.DirEntry, err error) error {
if err != nil {
return err
Expand Down Expand Up @@ -432,7 +435,12 @@ func createTarball(ctx context.Context, root, dockerfile string) (*bytes.Buffer,
}
}

term.Debug(" - Adding", baseName)
if term.DoDebug {
term.Debug(" - Adding", baseName)
} else if doProgress {
fmt.Printf("%4d %s\r", fileCount, baseName)
defer term.Stdout.ClearLine()
}

info, err := de.Info()
if err != nil {
Expand Down Expand Up @@ -465,13 +473,13 @@ func createTarball(ctx context.Context, root, dockerfile string) (*bytes.Buffer,
defer file.Close()

fileCount++
if fileCount == 11 {
term.Warn(" ! The build context contains more than 10 files; press Ctrl+C if this is unexpected.")
if fileCount == ContextFileLimit+1 {
term.Warnf(" ! The build context contains more than %d files; use --debug or create .dockerignore", ContextFileLimit)
}

_, err = io.Copy(tarWriter, file)
if buf.Len() > 10*MiB {
return fmt.Errorf("build context is too large; this beta version is limited to 10MiB")
if buf.Len() > ContextSizeLimit {
return fmt.Errorf("build context is too large; this beta version is limited to %dMiB", ContextSizeLimit/MiB)
}
return err
})
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/github/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func StartAuthCodeFlow(ctx context.Context, clientId string) (string, error) {
authorizeUrl = "https://github.com/login/oauth/authorize?" + values.Encode()

n, _ := fmt.Printf("Please visit %s and log in. (Right click the URL or press ENTER to open browser)\r", server.URL)
defer fmt.Print(strings.Repeat(" ", n), "\r")
defer fmt.Print(strings.Repeat(" ", n), "\r") // TODO: use termenv to clear line

input := term.NewNonBlockingStdin()
defer input.Close() // abort the read
Expand Down
10 changes: 5 additions & 5 deletions src/pkg/term/colorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ var (
IsTerminal = term.IsTerminal(int(os.Stdout.Fd())) && term.IsTerminal(int(os.Stdin.Fd())) && isTerminal()
Stdout = termenv.NewOutput(os.Stdout)
Stderr = termenv.NewOutput(os.Stderr)
CanColor = doColor(Stdout)
CanColorErr = doColor(Stderr)
CanColor = DoColor(Stdout)
CanColorErr = DoColor(Stderr)
DoDebug bool
HadWarnings bool
)
Expand All @@ -28,8 +28,8 @@ const (
DebugColor = termenv.ANSIBrightBlack // Gray
)

// doColor returns true if the provided output's profile is not Ascii.
func doColor(o *termenv.Output) bool {
// DoColor returns true if the provided output's profile is not Ascii.
func DoColor(o *termenv.Output) bool {
return o.Profile != termenv.Ascii
}

Expand All @@ -47,7 +47,7 @@ func output(w *termenv.Output, c Color, msg string) (int, error) {
if len(msg) == 0 {
return 0, nil
}
if doColor(w) {
if DoColor(w) {
w.WriteString(termenv.CSI + c.Sequence(false) + "m")
defer w.Reset()
}
Expand Down