Skip to content

Commit

Permalink
Move admin assets into the compiled binary.
Browse files Browse the repository at this point in the history
Fix #1032
  • Loading branch information
toddboom authored and jvshahid committed Oct 20, 2014
1 parent d2a4c7b commit 7df3781
Show file tree
Hide file tree
Showing 44 changed files with 2,045 additions and 22 deletions.
5 changes: 5 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ clean:
rm -rf $(rocksdb_dir)
$(MAKE) -C parser clean

rebuild_static_assets:
$(GO) get github.com/rakyll/statik
$(GOPATH)/bin/statik -src=./shared/admin
$(MAKE) format

only =
verbose = off
ifneq ($(only),)
Expand Down
14 changes: 10 additions & 4 deletions admin/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import (
"net"
"net/http"
"strings"

"github.com/rakyll/statik/fs"

_ "github.com/influxdb/influxdb/statik"
)

type HttpServer struct {
homeDir string
port string
listener net.Listener
closed bool
Expand All @@ -17,8 +20,8 @@ type HttpServer struct {
homeDir is the directory that is the root of the admin site.
port should be a string that looks like ":8080" or whatever port to serve on.
*/
func NewHttpServer(homeDir, port string) *HttpServer {
return &HttpServer{homeDir: homeDir, port: port, closed: true}
func NewHttpServer(port string) *HttpServer {
return &HttpServer{port: port, closed: true}
}

func (self *HttpServer) ListenAndServe() {
Expand All @@ -32,7 +35,10 @@ func (self *HttpServer) ListenAndServe() {
if err != nil {
panic(err)
}
err = http.Serve(self.listener, http.FileServer(http.Dir(self.homeDir)))

statikFS, _ := fs.New()

err = http.Serve(self.listener, http.FileServer(statikFS))
if !strings.Contains(err.Error(), "closed") {
panic(err)
}
Expand Down
12 changes: 2 additions & 10 deletions admin/http_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"io/ioutil"
. "launchpad.net/gocheck"
"net/http"
"path"
"testing"
)

Expand All @@ -19,19 +18,12 @@ type HttpServerSuite struct {
var _ = Suite(&HttpServerSuite{})

func (self *HttpServerSuite) TestServesIndexByDefault(c *C) {
// prepare some dummy site files
dir := c.MkDir()
content := []byte("Welcome to Influxdb")
path := path.Join(dir, "index.html")
err := ioutil.WriteFile(path, content, 0644)
c.Assert(err, IsNil)
s := NewHttpServer(dir, ":8083")
s := NewHttpServer(":8083")
go func() { s.ListenAndServe() }()
resp, err := http.Get("http://localhost:8083/")
c.Assert(err, IsNil)
defer resp.Body.Close()
c.Assert(resp.StatusCode, Equals, http.StatusOK)
actualContent, err := ioutil.ReadAll(resp.Body)
c.Assert(string(actualContent), Equals, string(content))
_, err = ioutil.ReadAll(resp.Body)
c.Assert(err, IsNil)
}
1 change: 0 additions & 1 deletion api/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type HttpServer struct {
func NewHttpServer(config *configuration.Configuration, theCoordinator api.Coordinator, userManager UserManager, clusterConfig *cluster.ClusterConfiguration, raftServer *coordinator.RaftServer) *HttpServer {
self := &HttpServer{}
self.httpPort = config.ApiHttpPortString()
self.adminAssetsDir = config.AdminAssetsDir
self.coordinator = theCoordinator
self.userManager = userManager
self.shutdown = make(chan bool, 2)
Expand Down
2 changes: 0 additions & 2 deletions api/http/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,8 @@ func (self *ApiSuite) SetUpSuite(c *C) {
clusterAdmins: []string{"root"},
dbUsers: map[string]map[string]MockDbUser{"db1": {"db_user1": {Name: "db_user1", IsAdmin: false}}},
}
dir := c.MkDir()
config := &configuration.Configuration{
ApiReadTimeout: 10 * time.Second,
AdminAssetsDir: dir,
}
self.server = NewHttpServer(
config,
Expand Down
1 change: 0 additions & 1 deletion config.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ file = "influxdb.log" # stdout to log to standard out, or syslog facil
# Configure the admin server
[admin]
port = 8083 # binding is disabled if the port isn't set
assets = "./admin"

# Configure the http api
[api]
Expand Down
2 changes: 0 additions & 2 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ type TomlConfiguration struct {

type Configuration struct {
AdminHttpPort int
AdminAssetsDir string
ApiHttpSslPort int
ApiHttpCertPath string
ApiHttpPort int
Expand Down Expand Up @@ -311,7 +310,6 @@ func parseTomlConfiguration(filename string) (*Configuration, error) {

config := &Configuration{
AdminHttpPort: tomlConfiguration.Admin.Port,
AdminAssetsDir: tomlConfiguration.Admin.Assets,
ApiHttpPort: tomlConfiguration.HttpApi.Port,
ApiHttpCertPath: tomlConfiguration.HttpApi.SslCertPath,
ApiHttpSslPort: tomlConfiguration.HttpApi.SslPort,
Expand Down
1 change: 0 additions & 1 deletion configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func (self *LoadConfigurationSuite) TestConfig(c *C) {
c.Assert(config.LogFile, Equals, "influxdb.log")
c.Assert(config.LogLevel, Equals, "info")

c.Assert(config.AdminAssetsDir, Equals, "./admin")
c.Assert(config.AdminHttpPort, Equals, 8083)

c.Assert(config.ApiHttpPort, Equals, 0)
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewServer(config *configuration.Configuration) (*Server, error) {
httpApi.EnableSsl(config.ApiHttpSslPortString(), config.ApiHttpCertPath)
graphiteApi := graphite.NewServer(config, coord, clusterConfig)
collectdApi := collectd.NewServer(config, coord, clusterConfig)
adminServer := admin.NewHttpServer(config.AdminAssetsDir, config.AdminHttpPortString())
adminServer := admin.NewHttpServer(config.AdminHttpPortString())

return &Server{
RaftServer: raftServer,
Expand Down
Binary file added shared/admin/fonts/FontAwesome.otf
Binary file not shown.
Binary file added shared/admin/fonts/font-mfizz.eot
Binary file not shown.
Loading

0 comments on commit 7df3781

Please sign in to comment.