Skip to content
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

[local-preview] Warn and Confirm from user before proceeding #13123

Merged
merged 1 commit into from
Sep 23, 2022
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
5 changes: 4 additions & 1 deletion install/preview/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

set -e

touch logs.txt

# Set Domain to `preview.gitpod-self-hosted.com` if not set
if [ -z "${DOMAIN}" ]; then
export DOMAIN="preview.gitpod-self-hosted.com"
Expand All @@ -14,7 +16,8 @@ USER_ID="$(od -x /dev/urandom | head -1 | awk '{OFS="-"; print $2$3,$4,$5,$6,$7$
export USER_ID

if [ "$1" != "logging" ]; then
$0 logging 2>&1 | /prettylog
$0 logging > logs.txt 2>&1 &
/prettylog
exit
fi

Expand Down
14 changes: 11 additions & 3 deletions install/preview/prettylog/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@ module github.com/gitpod-io/gitpod/install/preview/prettylog
go 1.18

require (
github.com/atomicgo/cursor v0.0.1 // indirect
github.com/gookit/color v1.5.0 // indirect
github.com/hpcloud/tail v1.0.0
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/pterm/pterm v0.12.41
github.com/pterm/pterm v0.12.42
github.com/rivo/uniseg v0.2.0 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
gopkg.in/segmentio/analytics-go.v3 v3.1.0
)

require (
atomicgo.dev/cursor v0.1.1 // indirect
atomicgo.dev/keyboard v0.2.8 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/lithammer/fuzzysearch v1.1.5 // indirect
github.com/segmentio/backo-go v1.0.1 // indirect
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/fsnotify.v1 v1.4.7 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)
32 changes: 26 additions & 6 deletions install/preview/prettylog/go.sum

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

31 changes: 21 additions & 10 deletions install/preview/prettylog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
package main

import (
"bufio"
"errors"
"fmt"
"io"
"log"
"os"
"strings"

"github.com/hpcloud/tail"
"github.com/pterm/pterm"
"gopkg.in/segmentio/analytics-go.v3"
)
Expand Down Expand Up @@ -38,21 +39,31 @@ var (
)

func main() {
dmp, err := os.OpenFile("logs.txt", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
if err != nil {
panic(err)
// Warn and wait for user approval
pterm.FgLightCyan.Println(`
Welcome to the local preview of Gitpod. Please note the following limitations:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest we change this to:

Welcome to the local preview of Gitpod. Please note the following limitations:
  - Performance is limited by the capabilities of your machine - a minimum of 4 cores and 6GB of RAM are required
  - ARM CPUs including Macs with Apple Silicon (e.g. M1) are currently not supported
  For more information about these limitation, please visit the [local preview documentation](https://www.gitpod.io/docs/self-hosted/latest/local-preview).

--> This adds a link & removes the periods at the end of the bullet points.
--> I am assuming we can do links in the CLI output here, but not sure how / if this works.

Copy link
Contributor Author

@Pothulapati Pothulapati Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2022-09-21 at 11 31 13 AM

It is rendered like this, with the http link being clickable (depends on the shell too). WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case we should likely not try to make the http link a clickable link (with the ... ) like on the web but instead have the link as full text:

Welcome to the local preview of Gitpod. Please note the following limitations:
  - Performance is limited by the capabilities of your machine - a minimum of 4 cores and 6GB of RAM are required
  - ARM CPUs including Macs with Apple Silicon (e.g. M1) are currently not supported
  For more information about these limitation, please visit the local preview documentation: https://www.gitpod.io/docs/self-hosted/latest/local-preview

Copy link
Contributor Author

@Pothulapati Pothulapati Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Will mark it ready once I test the final command out!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the input works with go run ., It does not seem to work as expected when we run it inside docker. So, Trying to make that work now!

- Performance is limited by the capabilities of your machine - a minimum of 4 cores and 6GB of RAM are required
- ARM CPUs including Macs with Apple Silicon (e.g. M1) are currently not supported
For more information about these limitation, please visit the local preview documentation: https://www.gitpod.io/docs/self-hosted/latest/local-preview`)

result, _ := pterm.DefaultInteractiveConfirm.WithDefaultText("Continue?").WithDefaultValue(true).Show()
if !result {
// send telemetry for user exit
send_telemetry("user exit")
return
}
defer dmp.Close()

r := io.TeeReader(os.Stdin, dmp)
file, err := tail.TailFile("logs.txt", tail.Config{Follow: true})
Copy link
Contributor Author

@Pothulapati Pothulapati Sep 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrsimonemms Like we discussed in our call. This was because while logs.txt gets updated, We just read at a point and are exiting prettylog as there is EOF.

Instead we need a way to continuously read logs.txt as it gets updated, and this is where the tail package comes in . By using that we are continuously reading from the latest updates, and thus updating status based on that. There seems to be a bunch of projects that are already using tail, so feels pretty standard. 👍🏼

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was also able to test that this works as expected!

if err != nil {
log.Fatal(err)
}

scan := bufio.NewScanner(r)
var msgIdx int
lastSpinner, _ := pterm.DefaultSpinner.Start(msgs[msgIdx].Msg)
// send Telemetry update for the first phase
send_telemetry(msgs[msgIdx].Status)
for scan.Scan() {
line := scan.Text()
for tailLine := range file.Lines {
line := tailLine.Text
msg := msgs[msgIdx]
var next bool
switch {
Expand All @@ -77,7 +88,7 @@ func main() {
send_telemetry(msgs[msgIdx].Status)

}
err = scan.Err()
err = file.Err()
if errors.Is(err, io.EOF) {
err = nil
}
Expand Down