This repository was archived by the owner on Jul 27, 2023. It is now read-only.
forked from imranismail/drone-registry-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (42 loc) · 1.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2018 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
package main
import (
"net/http"
"github.com/drone/drone-go/plugin/registry"
"github.com/drone/drone-registry-plugin/plugin"
_ "github.com/joho/godotenv/autoload"
"github.com/kelseyhightower/envconfig"
"github.com/sirupsen/logrus"
)
type spec struct {
Debug bool `envconfig:"DRONE_DEBUG"`
Address string `envconfig:"DRONE_ADDRESS" default:":3000"`
Secret string `envconfig:"DRONE_SECRET" required:"true"`
Config string `envconfig:"DRONE_CONFIG_FILE" required:"true"`
}
func healthzHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
}
func main() {
spec := new(spec)
err := envconfig.Process("", spec)
if err != nil {
logrus.WithError(err).Fatalln("invalid configuration")
}
if spec.Debug {
logrus.SetLevel(logrus.DebugLevel)
}
plugin, err := plugin.Load(spec.Config)
if err != nil {
logrus.WithError(err).Fatalln("cannot load configuration")
}
handler := registry.Handler(
spec.Secret, plugin, logrus.StandardLogger())
logrus.Infof("server listening on address %s", spec.Address)
http.Handle("/", handler)
http.HandleFunc("/healthz", healthzHandler)
logrus.Fatal(http.ListenAndServe(spec.Address, nil))
}