-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup.go
69 lines (61 loc) · 2.79 KB
/
setup.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Package setup contains common wiring/setup code used by all services
package setup
import (
"context"
"fmt"
_ "time/tzdata" // include embedded timezone data
"github.com/circleci/ex/config/o11y"
"github.com/circleci/ex/config/secret"
"github.com/circleci/ex/db"
"github.com/circleci/ex/rootcerts"
"github.com/circleci/ex/system"
)
type CLI struct {
AdminAddr string `env:"ADMIN_ADDR" default:":8001" help:"The address for the admin api to listen on"`
O11yStatsd string `name:"o11y-statsd" env:"O11Y_STATSD" default:"metrics.kube-system.svc.cluster.local:8125" help:"Address to send statsd metrics"`
O11yHoneycombEnabled bool `name:"o11y-honeycomb" env:"O11Y_HONEYCOMB" default:"true" help:"Send traces to honeycomb"`
O11yHoneycombDataset string `name:"o11y-honeycomb-dataset" env:"O11Y_HONEYCOMB_DATASET" default:"execution"`
O11yHoneycombKey secret.String `name:"o11y-honeycomb-key" env:"O11Y_HONEYCOMB_KEY"`
O11yFormat string `name:"o11y-format" env:"O11Y_FORMAT" enum:"json,color,text" default:"json" help:"Format used for stderr logging"`
O11yRollbarToken secret.String `name:"o11y-rollbar-token" env:"O11Y_ROLLBAR_TOKEN"`
O11yRollbarEnv string `name:"o11y-rollbar-env" env:"O11Y_ROLLBAR_ENV" default:"production"`
DBHost string `env:"DB_HOST" default:"ex-service-template.db.infra.circleci.com"`
DBPort int `env:"DB_PORT" default:"5432"`
DBUser string `env:"DB_USER" default:"ex-service-template"`
DBPassword secret.String `env:"DB_PASSWORD"`
DBName string `env:"DB_NAME" default:"ex-service-template"`
DBSSL bool `env:"DB_SSL" name:"db-ssl" default:"true"`
}
func init() {
err := rootcerts.UpdateDefaultTransport()
if err != nil {
panic(fmt.Errorf("failed to inject rootcerts: %w", err))
}
}
func LoadO11y(version, mode string, cli CLI) (context.Context, func(context.Context), error) {
cfg := o11y.Config{
Statsd: cli.O11yStatsd,
RollbarToken: cli.O11yRollbarToken,
RollbarEnv: cli.O11yRollbarEnv,
RollbarServerRoot: "github.com/circleci/ex-service-template",
HoneycombEnabled: cli.O11yHoneycombEnabled,
HoneycombDataset: cli.O11yHoneycombDataset,
HoneycombKey: cli.O11yHoneycombKey,
Format: cli.O11yFormat,
Version: version,
Service: "ex-service-template",
StatsNamespace: "circleci.ex-service-template.",
Mode: mode,
}
return o11y.Setup(context.Background(), cfg)
}
func LoadTxManager(ctx context.Context, cli CLI, sys *system.System) (*db.TxManager, error) {
return db.Load(ctx, "ex-service-template", "ex-service-template", db.Config{
Host: cli.DBHost,
Port: cli.DBPort,
User: cli.DBUser,
Pass: cli.DBPassword,
Name: cli.DBName,
SSL: cli.DBSSL,
}, sys)
}