OLD | NEW |
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "encoding/json" | 4 "encoding/json" |
5 "flag" | 5 "flag" |
6 "fmt" | 6 "fmt" |
7 "net/http" | 7 "net/http" |
8 "path/filepath" | 8 "path/filepath" |
9 "time" | 9 "time" |
10 | 10 |
11 "github.com/golang/glog" | 11 "github.com/golang/glog" |
12 "github.com/gorilla/mux" | 12 "github.com/gorilla/mux" |
13 "skia.googlesource.com/buildbot.git/go/auth" | 13 "skia.googlesource.com/buildbot.git/go/auth" |
14 "skia.googlesource.com/buildbot.git/go/common" | 14 "skia.googlesource.com/buildbot.git/go/common" |
15 "skia.googlesource.com/buildbot.git/go/database" | 15 "skia.googlesource.com/buildbot.git/go/database" |
16 "skia.googlesource.com/buildbot.git/go/login" | 16 "skia.googlesource.com/buildbot.git/go/login" |
17 "skia.googlesource.com/buildbot.git/go/metadata" | 17 "skia.googlesource.com/buildbot.git/go/metadata" |
18 "skia.googlesource.com/buildbot.git/golden/go/analysis" | 18 "skia.googlesource.com/buildbot.git/golden/go/analysis" |
19 "skia.googlesource.com/buildbot.git/golden/go/db" | 19 "skia.googlesource.com/buildbot.git/golden/go/db" |
20 "skia.googlesource.com/buildbot.git/golden/go/expstorage" | 20 "skia.googlesource.com/buildbot.git/golden/go/expstorage" |
21 "skia.googlesource.com/buildbot.git/golden/go/filediffstore" | 21 "skia.googlesource.com/buildbot.git/golden/go/filediffstore" |
22 "skia.googlesource.com/buildbot.git/golden/go/types" | 22 "skia.googlesource.com/buildbot.git/golden/go/types" |
23 "skia.googlesource.com/buildbot.git/perf/go/filetilestore" | 23 "skia.googlesource.com/buildbot.git/perf/go/filetilestore" |
24 ) | 24 ) |
25 | 25 |
26 // Command line flags. | 26 // Command line flags. |
27 var ( | 27 var ( |
28 // Get the default connection string suitable for production. | |
29 defaultDbConnStr = db.GetConnectionString("readwrite", "", "", "") | |
30 | |
31 graphiteServer = flag.String("graphite_server", "skia-monitoring:2003",
"Where is Graphite metrics ingestion server running.") | 28 graphiteServer = flag.String("graphite_server", "skia-monitoring:2003",
"Where is Graphite metrics ingestion server running.") |
32 port = flag.String("port", ":9000", "HTTP service address (e.g
., ':9000')") | 29 port = flag.String("port", ":9000", "HTTP service address (e.g
., ':9000')") |
33 local = flag.Bool("local", false, "Running locally if true. As
opposed to in production.") | 30 local = flag.Bool("local", false, "Running locally if true. As
opposed to in production.") |
34 staticDir = flag.String("static_dir", "./app", "Directory with stat
ic content to serve") | 31 staticDir = flag.String("static_dir", "./app", "Directory with stat
ic content to serve") |
35 tileStoreDir = flag.String("tile_store_dir", "/tmp/tileStore", "What d
irectory to look for tiles in.") | 32 tileStoreDir = flag.String("tile_store_dir", "/tmp/tileStore", "What d
irectory to look for tiles in.") |
36 imageDir = flag.String("image_dir", "/tmp/imagedir", "What directo
ry to store test and diff images in.") | 33 imageDir = flag.String("image_dir", "/tmp/imagedir", "What directo
ry to store test and diff images in.") |
37 gsBucketName = flag.String("gs_bucket", "chromium-skia-gm", "Name of t
he google storage bucket that holds uploaded images.") | 34 gsBucketName = flag.String("gs_bucket", "chromium-skia-gm", "Name of t
he google storage bucket that holds uploaded images.") |
38 dbConnStr = flag.String("db_conn_string", defaultDbConnStr, "MySQL
connection string for backend database. If 'local' is false the password in this
string will be substituted via the metadata server.") | |
39 sqlitePath = flag.String("sqlite_path", "./golden.db", "Filepath of
the embedded SQLite database. Requires 'local' to be set to true and 'mysql_conn
' to be empty to take effect.") | |
40 doOauth = flag.Bool("oauth", true, "Run through the OAuth 2.0 flo
w on startup, otherwise use a GCE service account.") | 35 doOauth = flag.Bool("oauth", true, "Run through the OAuth 2.0 flo
w on startup, otherwise use a GCE service account.") |
41 oauthCacheFile = flag.String("oauth_cache_file", "/home/perf/google_stor
age_token.data", "Path to the file where to cache cache the oauth credentials.") | 36 oauthCacheFile = flag.String("oauth_cache_file", "/home/perf/google_stor
age_token.data", "Path to the file where to cache cache the oauth credentials.") |
42 ) | 37 ) |
43 | 38 |
44 const ( | 39 const ( |
45 IMAGE_URL_PREFIX = "/img/" | 40 IMAGE_URL_PREFIX = "/img/" |
46 ) | 41 ) |
47 | 42 |
48 // TODO (stephana): Factor out to "go/login/login.go" | 43 // TODO (stephana): Factor out to "go/login/login.go" |
49 const ( | 44 const ( |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 client, err := auth.RunFlow(config) | 202 client, err := auth.RunFlow(config) |
208 if err != nil { | 203 if err != nil { |
209 glog.Fatalf("Failed to auth: %s", err) | 204 glog.Fatalf("Failed to auth: %s", err) |
210 } | 205 } |
211 return client | 206 return client |
212 } | 207 } |
213 return nil | 208 return nil |
214 } | 209 } |
215 | 210 |
216 func main() { | 211 func main() { |
| 212 // Setup DB flags. |
| 213 database.SetupFlags(db.PROD_DB_HOST, db.PROD_DB_PORT, database.USER_RW,
db.PROD_DB_NAME) |
| 214 |
217 // Global init to initialize | 215 // Global init to initialize |
218 common.InitWithMetrics("skiacorrectness", *graphiteServer) | 216 common.InitWithMetrics("skiacorrectness", *graphiteServer) |
219 | 217 |
220 // Initialize submodules. | 218 // Initialize submodules. |
221 filediffstore.Init() | 219 filediffstore.Init() |
222 | 220 |
223 // Set up login | 221 // Set up login |
224 // TODO (stephana): Factor out to go/login/login.go and removed hard cod
ed | 222 // TODO (stephana): Factor out to go/login/login.go and removed hard cod
ed |
225 // values. | 223 // values. |
226 var cookieSalt = "notverysecret" | 224 var cookieSalt = "notverysecret" |
227 var clientID = "31977622648-ubjke2f3staq6ouas64r31h8f8tcbiqp.apps.google
usercontent.com" | 225 var clientID = "31977622648-ubjke2f3staq6ouas64r31h8f8tcbiqp.apps.google
usercontent.com" |
228 var clientSecret = "rK-kRY71CXmcg0v9I9KIgWci" | 226 var clientSecret = "rK-kRY71CXmcg0v9I9KIgWci" |
229 var redirectURL = fmt.Sprintf("http://localhost%s/oauth2callback/", *por
t) | 227 var redirectURL = fmt.Sprintf("http://localhost%s/oauth2callback/", *por
t) |
230 if !*local { | 228 if !*local { |
231 cookieSalt = metadata.MustGet(COOKIESALT_METADATA_KEY) | 229 cookieSalt = metadata.MustGet(COOKIESALT_METADATA_KEY) |
232 clientID = metadata.MustGet(CLIENT_ID_METADATA_KEY) | 230 clientID = metadata.MustGet(CLIENT_ID_METADATA_KEY) |
233 clientSecret = metadata.MustGet(CLIENT_SECRET_METADATA_KEY) | 231 clientSecret = metadata.MustGet(CLIENT_SECRET_METADATA_KEY) |
234 redirectURL = "https://skiagold.com/oauth2callback/" | 232 redirectURL = "https://skiagold.com/oauth2callback/" |
235 } | 233 } |
236 login.Init(clientID, clientSecret, redirectURL, cookieSalt) | 234 login.Init(clientID, clientSecret, redirectURL, cookieSalt) |
237 | 235 |
238 // get the Oauthclient if necessary. | 236 // get the Oauthclient if necessary. |
239 client := getOAuthClient(*doOauth, *oauthCacheFile) | 237 client := getOAuthClient(*doOauth, *oauthCacheFile) |
240 | 238 |
241 // Get the expecations storage, the filediff storage and the tilestore. | 239 // Get the expecations storage, the filediff storage and the tilestore. |
242 diffStore := filediffstore.NewFileDiffStore(client, *imageDir, *gsBucket
Name, filediffstore.DEFAULT_GS_IMG_DIR_NAME, filediffstore.RECOMMENDED_WORKER_PO
OL_SIZE) | 240 diffStore := filediffstore.NewFileDiffStore(client, *imageDir, *gsBucket
Name, filediffstore.DEFAULT_GS_IMG_DIR_NAME, filediffstore.RECOMMENDED_WORKER_PO
OL_SIZE) |
243 » vdb := database.NewVersionedDB(db.GetConfig(*dbConnStr, *sqlitePath, *lo
cal)) | 241 » conf, err := database.ConfigFromFlagsAndMetadata(*local, db.MigrationSte
ps()) |
| 242 » if err != nil { |
| 243 » » glog.Fatal(err) |
| 244 » } |
| 245 » vdb := database.NewVersionedDB(conf) |
244 expStore := expstorage.NewCachingExpectationStore(expstorage.NewSQLExpec
tationStore(vdb)) | 246 expStore := expstorage.NewCachingExpectationStore(expstorage.NewSQLExpec
tationStore(vdb)) |
245 tileStore := filetilestore.NewFileTileStore(*tileStoreDir, "golden", -1) | 247 tileStore := filetilestore.NewFileTileStore(*tileStoreDir, "golden", -1) |
246 | 248 |
247 // Initialize the Analyzer | 249 // Initialize the Analyzer |
248 imgFS := NewURLAwareFileServer(*imageDir, IMAGE_URL_PREFIX) | 250 imgFS := NewURLAwareFileServer(*imageDir, IMAGE_URL_PREFIX) |
249 analyzer = analysis.NewAnalyzer(expStore, tileStore, diffStore, imgFS.Ge
tURL, 5*time.Minute) | 251 analyzer = analysis.NewAnalyzer(expStore, tileStore, diffStore, imgFS.Ge
tURL, 5*time.Minute) |
250 | 252 |
251 router := mux.NewRouter() | 253 router := mux.NewRouter() |
252 | 254 |
253 // Wire up the resources. We use the 'rest' prefix to avoid any name | 255 // Wire up the resources. We use the 'rest' prefix to avoid any name |
(...skipping 16 matching lines...) Expand all Loading... |
270 // Everything else is served out of the static directory. | 272 // Everything else is served out of the static directory. |
271 router.PathPrefix("/").Handler(http.FileServer(http.Dir(*staticDir))) | 273 router.PathPrefix("/").Handler(http.FileServer(http.Dir(*staticDir))) |
272 | 274 |
273 // Send all requests to the router | 275 // Send all requests to the router |
274 http.Handle("/", router) | 276 http.Handle("/", router) |
275 | 277 |
276 // Start the server | 278 // Start the server |
277 glog.Infoln("Serving on http://127.0.0.1" + *port) | 279 glog.Infoln("Serving on http://127.0.0.1" + *port) |
278 glog.Fatal(http.ListenAndServe(*port, nil)) | 280 glog.Fatal(http.ListenAndServe(*port, nil)) |
279 } | 281 } |
OLD | NEW |