Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/openvsx-proxy/main.go
2492 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package main
6
7
import (
8
"context"
9
"os"
10
"os/signal"
11
"syscall"
12
"time"
13
14
"github.com/gitpod-io/gitpod/common-go/log"
15
"github.com/gitpod-io/gitpod/openvsx-proxy/pkg"
16
"github.com/sirupsen/logrus"
17
)
18
19
func main() {
20
log.Init("openvsx-proxy", "", true, false)
21
22
if len(os.Args) != 2 {
23
log.Panicf("Usage: %s </path/to/config.json>", os.Args[0])
24
}
25
26
cfg, err := pkg.ReadConfig(os.Args[1])
27
if err != nil {
28
log.WithError(err).Panic("error reading config 😢")
29
}
30
31
if cfg.LogDebug {
32
log.Log.Logger.SetLevel(logrus.DebugLevel)
33
}
34
35
log.WithField("config", string(cfg.ToJson())).Info("starting OpenVSX proxy 🚀 ...")
36
37
done := make(chan os.Signal, 1)
38
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
39
40
openVSXProxy := pkg.OpenVSXProxy{
41
Config: cfg,
42
}
43
shutdown, err := openVSXProxy.Start()
44
if err != nil {
45
log.WithError(err).Panic("failed to start OpenVSX proxy 😢")
46
}
47
48
log.Info("OpenVSX proxy has been started ... listening on port 8080 ☕ ...")
49
50
<-done
51
log.Info("shutting down OpenVSX proxy ...")
52
startShutdown := time.Now()
53
54
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
55
defer func() {
56
cancel()
57
}()
58
59
if err := shutdown(ctx); err != nil {
60
log.
61
WithError(err).
62
WithField("shutdown_duration", time.Since(startShutdown).String()).
63
Error("gracefully shutting down of OpenVSX proxy failed 😢")
64
return
65
}
66
67
log.
68
WithField("shutdown_duration", time.Since(startShutdown).String()).
69
Info("OpenVSX proxy has been stopped 👋")
70
}
71
72