From ed10d381257e5cc2a42599ac2fd65bafd352bdcb Mon Sep 17 00:00:00 2001 From: Tarun Pothulapati Date: Thu, 16 Jun 2022 10:17:42 +0000 Subject: [PATCH] [preview-install] Add user-friendly output Part of https://github.com/gitpod-io/gitpod/issues/9075 This PR adds user friendly output to the preview install docker container by adding a new program prettylog that looks at the output of the entry-point.sh and just adds status updates and spinners. This feels easier instead of adding the same status updates in bash. The status updates are also kept as simple as possible and any additional instructions (URL, and certs) will be added to the documentation instead of here. Feel free to post here if you think it would be better to have them here in the script. Signed-off-by: Tarun Pothulapati --- install/preview/BUILD.yaml | 3 ++ install/preview/README.md | 2 +- install/preview/entrypoint.sh | 14 +++++- install/preview/leeway.Dockerfile | 7 +++ install/preview/prettylog/go.mod | 15 +++++++ install/preview/prettylog/go.sum | 64 +++++++++++++++++++++++++++ install/preview/prettylog/main.go | 73 +++++++++++++++++++++++++++++++ 7 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 install/preview/prettylog/go.mod create mode 100644 install/preview/prettylog/go.sum create mode 100644 install/preview/prettylog/main.go diff --git a/install/preview/BUILD.yaml b/install/preview/BUILD.yaml index 93fb8c1b414c2d..b22bf2b42313f9 100644 --- a/install/preview/BUILD.yaml +++ b/install/preview/BUILD.yaml @@ -8,6 +8,9 @@ packages: srcs: - "entrypoint.sh" - "manifests/*.yaml" + - "prettylog/main.go" + - "prettylog/go.sum" + - "prettylog/go.mod" config: dockerfile: leeway.Dockerfile image: diff --git a/install/preview/README.md b/install/preview/README.md index bde75075853157..600408b19869e1 100644 --- a/install/preview/README.md +++ b/install/preview/README.md @@ -7,7 +7,7 @@ simple as possible. ## Installation ```bash -docker run --privileged --name gitpod --rm -it -v /tmp/gitpod:/var/gitpod eu.gcr.io/gitpod-core-dev/build/preview-install:tar-preview-install.4 +docker run --privileged --name gitpod --rm -it -v /tmp/gitpod:/var/gitpod eu.gcr.io/gitpod-core-dev/build/preview-install:tar-preview-output.2 ``` Once the above command starts running and the pods are ready (can be checked by running `docker exec gitpod kubectl get pods`), diff --git a/install/preview/entrypoint.sh b/install/preview/entrypoint.sh index 860d5510954b13..7f173fb6727466 100755 --- a/install/preview/entrypoint.sh +++ b/install/preview/entrypoint.sh @@ -2,8 +2,12 @@ # Copyright (c) 2022 Gitpod GmbH. All rights reserved. # Licensed under the MIT License. See License-MIT.txt in the project root for license information. +set -e -set -ex +if [ "$1" != "logging" ]; then + $0 logging 2>&1 | /prettylog + exit +fi # check for minimum requirements REQUIRED_MEM_KB=$((6 * 1024 * 1024)) @@ -11,6 +15,8 @@ total_mem_kb=$(awk '/MemTotal:/ {print $2}' /proc/meminfo) if [ "${total_mem_kb}" -lt "${REQUIRED_MEM_KB}" ]; then echo "Preview installation of Gitpod requires a system with at least 6GB of memory" exit 1 +else + set -x fi REQUIRED_CORES=4 @@ -111,10 +117,16 @@ done ctr images pull "docker.io/gitpod/workspace-full:latest" >/dev/null & /gitpod-installer render --config config.yaml --output-split-files /var/lib/rancher/k3s/server/manifests/gitpod + +# store files in `gitpod.debug` for debugging purposes for f in /var/lib/rancher/k3s/server/manifests/gitpod/*.yaml; do (cat "$f"; echo) >> /var/lib/rancher/k3s/server/gitpod.debug; done +# remove NetowrkPolicy resources as they are not relevant here rm /var/lib/rancher/k3s/server/manifests/gitpod/*NetworkPolicy* +# update PersistentVolumeClaim's to use k3s's `local-path` storage class for f in /var/lib/rancher/k3s/server/manifests/gitpod/*PersistentVolumeClaim*.yaml; do yq e -i '.spec.storageClassName="local-path"' "$f"; done +# Set `volumeClassTemplate` so that each replica creates its own PVC yq eval-all -i ". as \$item ireduce ({}; . *+ \$item)" /var/lib/rancher/k3s/server/manifests/gitpod/*_StatefulSet_messagebus.yaml /app/manifests/messagebus.yaml +# update Statefulset's to use k3s's `local-path` storage class for f in /var/lib/rancher/k3s/server/manifests/gitpod/*StatefulSet*.yaml; do yq e -i '.spec.volumeClaimTemplates[0].spec.storageClassName="local-path"' "$f"; done # removing init container from ws-daemon (systemd and Ubuntu) diff --git a/install/preview/leeway.Dockerfile b/install/preview/leeway.Dockerfile index ecfcedbfde39f9..c8c50fa840d59e 100644 --- a/install/preview/leeway.Dockerfile +++ b/install/preview/leeway.Dockerfile @@ -1,6 +1,12 @@ # Copyright (c) 2022 Gitpod GmbH. All rights reserved. # Licensed under the MIT License. See License-MIT.txt in the project root for license information. +FROM golang:1.18 as prettylog + +WORKDIR /app +COPY prettylog/* ./ +RUN CGO_ENABLED=0 go build . + FROM rancher/k3s:v1.21.12-k3s1 ADD https://github.com/FiloSottile/mkcert/releases/download/v1.4.4/mkcert-v1.4.4-linux-amd64 /bin/mkcert @@ -16,6 +22,7 @@ RUN chmod +x /bin/yq COPY manifests/* /app/manifests/ COPY install-installer--app/installer /gitpod-installer +COPY --from=prettylog /app/prettylog /prettylog COPY entrypoint.sh /entrypoint.sh diff --git a/install/preview/prettylog/go.mod b/install/preview/prettylog/go.mod new file mode 100644 index 00000000000000..9fa382819ea515 --- /dev/null +++ b/install/preview/prettylog/go.mod @@ -0,0 +1,15 @@ +module github.com/gitpod-io/gitpod/olpi/prettylog + +go 1.18 + +require github.com/pterm/pterm v0.12.41 + +require ( + github.com/atomicgo/cursor v0.0.1 // indirect + github.com/gookit/color v1.5.0 // indirect + github.com/mattn/go-runewidth v0.0.13 // indirect + 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/term v0.0.0-20210927222741-03fcf44c2211 // indirect +) diff --git a/install/preview/prettylog/go.sum b/install/preview/prettylog/go.sum new file mode 100644 index 00000000000000..ad45b84a5cff10 --- /dev/null +++ b/install/preview/prettylog/go.sum @@ -0,0 +1,64 @@ +github.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs= +github.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3kkcZX4hv9Rp8= +github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII= +github.com/MarvinJWendt/testza v0.2.10/go.mod h1:pd+VWsoGUiFtq+hRKSU1Bktnn+DMCSrDrXDpX2bG66k= +github.com/MarvinJWendt/testza v0.2.12/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzXjB69adAhzZkI= +github.com/MarvinJWendt/testza v0.3.0/go.mod h1:eFcL4I0idjtIx8P9C6KkAuLgATNKpX4/2oUqKc6bF2c= +github.com/MarvinJWendt/testza v0.3.5 h1:g9krITRRlIsF1eO9sUKXtiTw670gZIIk6T08Keeo1nM= +github.com/MarvinJWendt/testza v0.3.5/go.mod h1:ExbTpWmA1z2E9HSskvrNcwApoX4F9bID692s10nuHRY= +github.com/atomicgo/cursor v0.0.1 h1:xdogsqa6YYlLfM+GyClC/Lchf7aiMerFiZQn7soTOoU= +github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= +github.com/gookit/color v1.5.0 h1:1Opow3+BWDwqor78DcJkJCIwnkviFi+rrOANki9BUFw= +github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= +github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE= +github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +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/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI= +github.com/pterm/pterm v0.12.29/go.mod h1:WI3qxgvoQFFGKGjGnJR849gU0TsEOvKn5Q8LlY1U7lg= +github.com/pterm/pterm v0.12.30/go.mod h1:MOqLIyMOgmTDz9yorcYbcw+HsgoZo3BQfg2wtl3HEFE= +github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEejaWgXU= +github.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE= +github.com/pterm/pterm v0.12.36/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5bUw8T8= +github.com/pterm/pterm v0.12.40/go.mod h1:ffwPLwlbXxP+rxT0GsgDTzS3y3rmpAO1NMjUkGTYf8s= +github.com/pterm/pterm v0.12.41 h1:e2BRfFo1H9nL8GY0S3ImbZqfZ/YimOk9XtkhoobKJVs= +github.com/pterm/pterm v0.12.41/go.mod h1:LW/G4J2A42XlTaPTAGRPvbBfF4UXvHWhC6SN7ueU4jU= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= +github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/install/preview/prettylog/main.go b/install/preview/prettylog/main.go new file mode 100644 index 00000000000000..52a723472ea72f --- /dev/null +++ b/install/preview/prettylog/main.go @@ -0,0 +1,73 @@ +// Copyright (c) 2022 Gitpod GmbH. All rights reserved. +// Licensed under the MIT License. See License-MIT.txt in the project root for license information. + +package main + +import ( + "bufio" + "errors" + "io" + "os" + "strings" + + "github.com/pterm/pterm" +) + +var msgs = []struct { + Fail string + Success string + + Msg string +}{ + {Msg: "checking prerequisites", Fail: "requires a system with at least", Success: "Gitpod Domain:"}, + {Msg: "preparing system", Success: "extracting images to download ahead"}, + {Msg: "downloading images", Success: "--output-split-files"}, + {Msg: "preparing Gitpod preview installation", Success: "rm -rf /var/lib/rancher/k3s/server/manifests/gitpod"}, + {Msg: "starting k3s", Success: "ws-proxy"}, + {Msg: "Gitpod is running"}, +} + +func main() { + dmp, err := os.OpenFile("logs.txt", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) + if err != nil { + panic(err) + } + defer dmp.Close() + + r := io.TeeReader(os.Stdin, dmp) + + scan := bufio.NewScanner(r) + var msgIdx int + lastSpinner, _ := pterm.DefaultSpinner.Start(msgs[msgIdx].Msg) + for scan.Scan() { + line := scan.Text() + msg := msgs[msgIdx] + + var next bool + switch { + case msg.Fail != "" && strings.Contains(line, msg.Fail): + lastSpinner.Fail() + next = true + case msg.Success != "" && strings.Contains(line, msg.Success): + lastSpinner.Success() + next = true + } + + if !next { + continue + } + + msgIdx++ + if msgIdx >= len(msgs) { + return + } + lastSpinner, _ = pterm.DefaultSpinner.Start(msgs[msgIdx].Msg) + } + err = scan.Err() + if errors.Is(err, io.EOF) { + err = nil + } + if err != nil { + panic(err) + } +}