This repository is currently being migrated. It's locked while the migration is in progress.
forked from grafadruid/druid-grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Magefile.go
190 lines (145 loc) · 5.26 KB
/
Magefile.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//go:build mage
// +build mage
package main
import (
"fmt"
"os"
"path/filepath"
//mage:import sdk
_ "github.com/grafana/grafana-plugin-sdk-go/build"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
const (
defaultIngestScript string = "docker/provisioning/post-index-task"
defaultIngestSpecFile string = "docker/provisioning/ingest-spec.json"
defaultCoordinatorURL string = "http://coordinator:8081"
defaultBrokerURL string = "http://broker:8082"
taskEndpoint string = "/druid/indexer/v1/task"
grafanaVersion string = "8.4.3"
)
var (
useDocker bool = os.Getenv("GRAFADRUID_USE_DOCKER") != "0"
dockerToolboxCmd []string = []string{"docker-compose", "exec", "toolbox"}
)
func runToolboxCmd(cmd ...string) error {
if useDocker {
cmd = append(dockerToolboxCmd, cmd...)
}
return sh.RunV(cmd[0], cmd[1:]...)
}
type Env mg.Namespace
// UpdateMage mage compiles mage in order to avoid Mage dependency on the host
func (e Env) UpdateMage() error { return sh.Run("mage", "-compile", "./mage") }
// Fmt formats the backend code (gofumpt)
func (e Env) Fmt() error {
goFiles, err := filepath.Glob("**/*.go")
if err != nil {
return err
}
if err := sh.RunV(
"gofumpt", append([]string{"-w", "Magefile.go"}, goFiles...)...,
); err != nil {
return err
}
return sh.RunV("yarn", "fmt")
}
// Start starts the development environment
func (e Env) Start() error {
if err := sh.RunV("docker-compose", "up", "-d"); err != nil {
return err
}
if err := e.Provision(); err != nil {
return err
}
fmt.Printf("\nDruid: http://localhost:8888")
fmt.Println("\nGrafana: http://localhost:3000 (use druid/druid to login)")
return nil
}
// Stop stops the development environment
func (e Env) Stop(removeVolumes bool) error {
cmd := []string{"docker-compose", "down"}
if removeVolumes {
cmd = append(cmd, "-v")
}
return sh.RunV(cmd[0], cmd[1:]...)
}
// Rebuild rebuilds container images from Dockerfiles
func (e Env) Rebuild() error { return sh.RunV("docker-compose", "build") }
// Provision provisions example data in Druid
func (e Env) Provision() error {
fmt.Println("\nIngesting example data into Druid")
return runToolboxCmd(
defaultIngestScript,
"--file",
defaultIngestSpecFile,
"--url",
defaultCoordinatorURL,
"--complete-timeout",
"1200",
"--coordinator-url",
defaultCoordinatorURL,
"--broker-url",
defaultBrokerURL,
)
}
// Restart stops and start the development environment
func (e Env) Restart() error {
if err := e.Stop(false); err != nil {
return err
}
return e.Start()
}
type Frontend mg.Namespace
// Build builds the frontend plugin
func (Frontend) Build() error {
err := runToolboxCmd("yarn", "install")
if err != nil {
return err
}
return runToolboxCmd("npx", "@grafana/toolkit@"+grafanaVersion, "plugin:build")
//return runToolboxCmd("npx", "@grafana/toolkit", "plugin:build", "--preserveConsole")
}
// Test runs frontend tests
func (Frontend) Test() error {
return runToolboxCmd("npx", "@grafana/toolkit@"+grafanaVersion, "plugin:test")
}
// Dev runs frontend in development mode
func (Frontend) Dev() error {
return runToolboxCmd("npx", "@grafana/toolkit@"+grafanaVersion, "plugin:dev")
}
// Watch runs frontend in development mode + autoreload on changes
func (Frontend) Watch() error {
return runToolboxCmd("npx", "@grafana/toolkit@"+grafanaVersion, "plugin:dev", "--watch")
}
type Backend mg.Namespace
// Build creates a release build of the backend plugin for all platforms
func (Backend) Build() error { return runToolboxCmd("./mage", "sdk:build:backend") }
// Linux creates a release build of the backend plugin for Linux
func (Backend) Linux() error { return runToolboxCmd("./mage", "sdk:build:linux") }
// Darwin creates a release build of the backend plugin for macOS
func (Backend) Darwin() error { return runToolboxCmd("./mage", "sdk:build:darwin") }
// Windows creates a relese build of the backend plugin for Windows
func (Backend) Windows() error { return runToolboxCmd("./mage", "sdk:build:windows") }
// Debug creates a debug build of the backend plugin for the current platform
func (Backend) Debug() error { return runToolboxCmd("./mage", "sdk:build:debug") }
// BuildAll creates release build of all plugin components
func (Backend) BuildAll() error { return runToolboxCmd("./mage", "sdk:buildAll") }
// Clean cleans build artifacts (by deleting the dist directory)
func (Backend) Clean() error { return runToolboxCmd("./mage", "sdk:clean") }
// Coverage rune backend tests and make a coverage report
func (Backend) Coverage() error { return runToolboxCmd("./mage", "sdk:coverage") }
// Format formats the sources
func (Backend) Format() error { return runToolboxCmd("./mage", "sdk:format") }
// Lint audits the source style
func (Backend) Lint() error { return runToolboxCmd("./mage", "sdk:lint") }
// ReloadPlugin kills any running instances and wait for Grafana to reload the plugin
func (Backend) ReloadPlugin() error {
return sh.RunV("docker-compose", "restart", "grafana")
}
// Test runs backend tests
func (Backend) Test() error { return runToolboxCmd("./mage", "sdk:test") }
// BuildAll builds the plugin (both frontend and backend)
func BuildAll() { mg.Deps(Backend{}.BuildAll, Frontend{}.Build) }
// Default configures the default target (build all plugin components)
var Default = BuildAll