Skip to content

Commit

Permalink
[local-preview] Warn and Confirm from user before proceeding
Browse files Browse the repository at this point in the history
Currently, For Users with ARM CPU's, `local-preview` does not
really work and its hard for the script to know as it runs inside
docker (which could be a x86 VM).

This Updates the script to warn the users on the requirements before
starting and running `local-preview`.

Signed-off-by: Tarun Pothulapati <[email protected]>
  • Loading branch information
Pothulapati authored and roboquat committed Sep 23, 2022
1 parent e6fc700 commit b767c6e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 20 deletions.
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:
- 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})
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

0 comments on commit b767c6e

Please sign in to comment.