github.com/grailbio/bigslice@v0.0.0-20230519005545-30c4c12152ad/sliceconfig/sliceconfig.go (about) 1 // Copyright 2019 GRAIL, Inc. All rights reserved. 2 // Use of this source code is governed by the Apache 2.0 3 // license that can be found in the LICENSE file. 4 5 // Package sliceconfig provides a mechanism to create a bigslice 6 // session from a shared configuration. Sliceconfig uses the 7 // configuration mechanism in package 8 // github.com/grailbio/base/config, and reads a default profile from 9 // $HOME/.bigslice/config. Configurations may be provisioned 10 // using the bigslice command. 11 package sliceconfig 12 13 import ( 14 "flag" 15 "net/http" 16 17 // Imported to install pprof http handlers. 18 _ "net/http/pprof" 19 "os" 20 21 "github.com/grailbio/base/config" 22 "github.com/grailbio/base/log" 23 "github.com/grailbio/base/must" 24 "github.com/grailbio/base/status" 25 "github.com/grailbio/bigmachine" 26 27 // Imported to provide ec2system.System bigmachines. 28 _ "github.com/grailbio/base/config/aws" 29 _ "github.com/grailbio/bigmachine/ec2system" 30 31 "github.com/grailbio/bigslice/exec" 32 33 // Imported to provide an http server. 34 _ "github.com/grailbio/base/config/http" 35 ) 36 37 // Path determines the location of the bigslice profile read 38 // by Parse. 39 var Path = os.ExpandEnv("$HOME/.bigslice/config") 40 41 // Parse registers configuration flags, bigslice flags, and calls flag.Parse. It 42 // reads bigslice configuration from Path defined in this package. Parse returns 43 // a session as configured by the configuration and any flags provided. Parse 44 // panics if session creation fails. Parse also instantiates the default http 45 // server according to the configuration profile, and registers the bigslice 46 // session status handlers with it. Call Shutdown() on the returned session when 47 // you are done with it. 48 func Parse() *exec.Session { 49 log.AddFlags() 50 local := flag.Bool("local", false, "run bigslice in local mode") 51 config.RegisterFlags("", Path) 52 flag.Parse() 53 must.Nil(config.ProcessFlags()) 54 var sess *exec.Session 55 if *local { 56 sess = exec.Start(exec.Local, exec.Status(new(status.Status))) 57 } else { 58 bigmachine.Init() 59 config.Must("bigslice", &sess) 60 } 61 sess.HandleDebug(http.DefaultServeMux) 62 http.Handle("/debug/status", status.Handler(sess.Status())) 63 config.Must("http", nil) 64 return sess 65 }