Skip to content

Commit d59c3e5

Browse files
committed
[local-preview] Warn and Confirm from user before proceeding
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]>
1 parent 0acc0b3 commit d59c3e5

File tree

4 files changed

+62
-20
lines changed

4 files changed

+62
-20
lines changed

install/preview/entrypoint.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
set -e
66

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

1618
if [ "$1" != "logging" ]; then
17-
$0 logging 2>&1 | /prettylog
19+
$0 logging > logs.txt 2>&1 &
20+
/prettylog
1821
exit
1922
fi
2023

install/preview/prettylog/go.mod

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@ module github.com/gitpod-io/gitpod/install/preview/prettylog
33
go 1.18
44

55
require (
6-
github.com/atomicgo/cursor v0.0.1 // indirect
76
github.com/gookit/color v1.5.0 // indirect
7+
github.com/hpcloud/tail v1.0.0
88
github.com/mattn/go-runewidth v0.0.13 // indirect
9-
github.com/pterm/pterm v0.12.41
9+
github.com/pterm/pterm v0.12.42
1010
github.com/rivo/uniseg v0.2.0 // indirect
1111
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
12-
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect
12+
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
1313
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
1414
gopkg.in/segmentio/analytics-go.v3 v3.1.0
1515
)
1616

1717
require (
18+
atomicgo.dev/cursor v0.1.1 // indirect
19+
atomicgo.dev/keyboard v0.2.8 // indirect
1820
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
21+
github.com/containerd/console v1.0.3 // indirect
22+
github.com/fsnotify/fsnotify v1.5.4 // indirect
23+
github.com/lithammer/fuzzysearch v1.1.5 // indirect
1924
github.com/segmentio/backo-go v1.0.1 // indirect
2025
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
26+
golang.org/x/text v0.3.7 // indirect
27+
gopkg.in/fsnotify.v1 v1.4.7 // indirect
28+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
2129
)

install/preview/prettylog/go.sum

Lines changed: 26 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/preview/prettylog/main.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
package main
55

66
import (
7-
"bufio"
87
"errors"
98
"fmt"
109
"io"
10+
"log"
1111
"os"
1212
"strings"
1313

14+
"github.com/hpcloud/tail"
1415
"github.com/pterm/pterm"
1516
"gopkg.in/segmentio/analytics-go.v3"
1617
)
@@ -38,21 +39,31 @@ var (
3839
)
3940

4041
func main() {
41-
dmp, err := os.OpenFile("logs.txt", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
42-
if err != nil {
43-
panic(err)
42+
// Warn and wait for user approval
43+
pterm.FgLightCyan.Println(`
44+
Welcome to the local preview of Gitpod. Please note the following limitations:
45+
- Performance is limited by the capabilities of your machine - a minimum of 4 cores and 6GB of RAM are required
46+
- ARM CPUs including Macs with Apple Silicon (e.g. M1) are currently not supported
47+
For more information about these limitation, please visit the local preview documentation: https://www.gitpod.io/docs/self-hosted/latest/local-preview`)
48+
49+
result, _ := pterm.DefaultInteractiveConfirm.WithDefaultText("Continue?").WithDefaultValue(true).Show()
50+
if !result {
51+
// send telemetry for user exit
52+
send_telemetry("user exit")
53+
return
4454
}
45-
defer dmp.Close()
4655

47-
r := io.TeeReader(os.Stdin, dmp)
56+
file, err := tail.TailFile("logs.txt", tail.Config{Follow: true})
57+
if err != nil {
58+
log.Fatal(err)
59+
}
4860

49-
scan := bufio.NewScanner(r)
5061
var msgIdx int
5162
lastSpinner, _ := pterm.DefaultSpinner.Start(msgs[msgIdx].Msg)
5263
// send Telemetry update for the first phase
5364
send_telemetry(msgs[msgIdx].Status)
54-
for scan.Scan() {
55-
line := scan.Text()
65+
for tailLine := range file.Lines {
66+
line := tailLine.Text
5667
msg := msgs[msgIdx]
5768
var next bool
5869
switch {
@@ -77,7 +88,7 @@ func main() {
7788
send_telemetry(msgs[msgIdx].Status)
7889

7990
}
80-
err = scan.Err()
91+
err = file.Err()
8192
if errors.Is(err, io.EOF) {
8293
err = nil
8394
}

0 commit comments

Comments
 (0)