blob: dfb23a6f3869574d966c3a2497004449692df43c [file] [log] [blame]
Serge Bazanski5de0b322021-03-20 12:04:26 +00001package main
2
3import (
4 "flag"
5 "net"
6 "net/http"
7
8 "code.hackerspace.pl/hscloud/go/mirko"
9
10 "github.com/golang/glog"
11 "github.com/minio/minio-go/v7"
12 "github.com/minio/minio-go/v7/pkg/credentials"
13)
14
15var (
16 flagListenPublic = ":8080"
17 flagObjectEndpoint = "object.ceph-waw3.hswaw.net"
18 flagObjectAccessKey = ""
19 flagObjectSecretKey = ""
20 flagObjectBucket = ""
21 flagObjectPrefix = "cache/"
22)
23
24func main() {
25 flag.StringVar(&flagListenPublic, "listen_public", flagListenPublic, "Address to listen on for Bazel HTTP caching protocol clients")
26 flag.StringVar(&flagObjectEndpoint, "object_endpoint", flagObjectEndpoint, "Object Storage endpoint name")
27 flag.StringVar(&flagObjectAccessKey, "object_access_key", flagObjectEndpoint, "Object Storage AccessKey")
28 flag.StringVar(&flagObjectSecretKey, "object_secret_key", flagObjectEndpoint, "Object Storage SecretKey")
29 flag.StringVar(&flagObjectBucket, "object_bucket", flagObjectBucket, "Object Storage bucket name")
30 flag.StringVar(&flagObjectPrefix, "object_prefix", flagObjectPrefix, "Object Storage prefix for paths")
31 flag.Parse()
32
33 if flagObjectBucket == "" {
34 glog.Exitf("object_bucket must be set")
35 }
36
37 m := mirko.New()
38 if err := m.Listen(); err != nil {
39 glog.Exitf("Listen(): %v", err)
40 }
41
42 minioClient, err := minio.New(flagObjectEndpoint, &minio.Options{
43 Creds: credentials.NewStaticV4(flagObjectAccessKey, flagObjectSecretKey, ""),
44 Secure: true,
45 })
46
47 if err != nil {
48 glog.Exitf("Failed to initialize Object Storage client: %v", err)
49 }
50
51 s := newService(minioClient, flagObjectBucket, flagObjectPrefix)
52
53 httpListen, err := net.Listen("tcp", flagListenPublic)
54 if err != nil {
55 glog.Exitf("net.Listen: %v", err)
56 }
57 httpServer := &http.Server{
58 Addr: flagListenPublic,
59 Handler: s.publicHandler,
60 }
61
62 errs := make(chan error, 0)
63 go func() {
64 glog.Infof("Public listening on %s", flagListenPublic)
65 errs <- httpServer.Serve(httpListen)
66 }()
67
68 if err := m.Serve(); err != nil {
69 glog.Exitf("Serve(): %v", err)
70 }
71
72 select {
73 case <-m.Done():
74 case err := <-errs:
75 glog.Exitf("Serve(): %v", err)
76 }
77}