Skip to content

Commit

Permalink
Fixes hound-search#7: Make Hound Go Gettable.
Browse files Browse the repository at this point in the history
  • Loading branch information
kellegous committed Mar 14, 2015
1 parent 851b9cc commit 3eeb57d
Show file tree
Hide file tree
Showing 84 changed files with 1,178 additions and 421 deletions.
1 change: 0 additions & 1 deletion .gaan

This file was deleted.

7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
pkg
bin
hound.sublime-workspace
data
.vagrant
pub/index.html
pub/excluded_files.html
build
config.json
29 changes: 8 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
BINS = bin/houndd bin/hound
HOST = localhost:6080

TESTS = ansi \
hound/codesearch/index \
hound/codesearch/regexp \
hound/client \
hound/index \
hound/vcs \
hound/config
ALL: ui/bindata.go

ALL: $(BINS)
build/bin/go-bindata:
GOPATH=`pwd`/build go get github.com/jteeuwen/go-bindata/...

bin/houndd : $(wildcard src/hound/**/*)
GOPATH=`pwd` go build -o $@ src/hound/cmds/houndd/main.go
ui/bindata.go: build/bin/go-bindata $(wildcard ui/assets/**/*)
rsync -r --exclude '*.js' ui/assets/* build/ui
jsx --no-cache-dir ui/assets/js build/ui/js
$< -o $@ -pkg ui -prefix build/ui -nomemcopy build/ui/...

bin/hound : $(wildcard src/hound/**/*)
GOPATH=`pwd` go build -o $@ \
-ldflags "-X main.defaultHost $(HOST)" \
src/hound/cmds/hound/*.go

test:
GOPATH=`pwd` go test $(TESTS)

clean:
rm -f $(BINS)
rm -f build
63 changes: 32 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,24 @@ Hound is an extremely fast source code search engine. The core is based on this

## Quick Start Guide

#### Preferred Method

This is the preferred approach, since the binaries are generally easier to work with, and make will build both the server and the CLI binaries at the same time.

1. Clone the repo: `git clone https://github.com/etsy/Hound.git`
2. Edit [config-example.json](config-example.json) to add the repos you want: `cd Hound && vim config-example.json`
3. Rename the (now edited) config file: `mv config-example.json config.json`
4. `make`
5. `./bin/houndd`
6. See Hound in action in your browser at [http://localhost:6080/](http://localhost:6080/)

#### Using only Go tools.
1. Use the Go tools to install Hound. The binaries `houndd` (server) and `hound` (cli) will be installed in your $GOPATH.
```
go get github.com/etsy/hound/cmds/...
```

Alternatively, you can avoid the use of make and just use go tools.
2. Create a [config.json](config-example.json) with your list of repositories.

1. Clone the repo: `git clone https://github.com/etsy/Hound.git`
2. Edit [config-example.json](config-example.json) to add the repos you want: `cd Hound && vim config-example.json`
3. Rename the (now edited) config file: `mv config-example.json config.json`
4. Set your GOPATH: ``export GOPATH=`pwd` ``
5. Run the server: `go run src/hound/cmds/houndd/main.go`
6. See Hound in action in your browser at [http://localhost:6080/](http://localhost:6080/)
3. Run the Hound server with `houndd` and you should see output similer to:
````
2015/03/13 09:07:42 Searcher started for statsd
2015/03/13 09:07:42 Searcher started for Hound
2015/03/13 09:07:42 All indexes built!
2015/03/13 09:07:42 running server at http://localhost:6080...
```
#### Why can't I use `go get`?
## Running in Production
That's coming, we just need to make it easier to bundle the javascript/css assets so it all works seamlessly.
There are no special flags to run Hound in production. You can use the `--addr=:6880` flag to control the port to which the server binds. Currently, Hound does not supports SSL/TLS as most users simply run Hound behind either Apache or nginx. Adding TLS support is pretty straight forward though if anyone wants to add it.
## Why Another Code Search Tool?
Expand Down Expand Up @@ -97,30 +90,38 @@ Currently the following editors have plugins that support Hound:
## Hacking on Hound
### Building
### Editing & Building
Hound uses the standard Go tools for development, so your favorite Go workflow should work. If you are looking for something that will work, here is one option:
```
make
git clone https://github.com/etsy/Hound.git hound/src/github.com/etsy/hound
cd hound
GOPATH=`pwd` go install github.com/etsy/hound/cmds/...
```
This will build `./bin/houndd` which is the server binary and `./bin/hound` which is the command line client.
### Testing
### Running in development
There are an increasing number of tests in each of the packages in Hound. Please make sure these pass before uploading your Pull Request. You can run the tests with the following command.
```
./bin/houndd
GOPATH=`pwd` go test github.com/etsy/hound/...
```
This will start up the combined server and indexer. The first time you start the server, it will take a bit of time to initialize your `data` directory with the repository data.
You can access the web frontend at http://localhost:6080/
### Working on the web UI
### Running in production
Hound includes a web UI that is composed of several files (html, css, javascript, etc.). To make sure hound works seamlessly with the standard Go tools, these resources are all built inside of the `houndd` binary. This adds a small burden on developers to re-package the UI files after each change. If you make changes to the UI, please follow these steps:
1. To make development easier, there is a flag that will read the files from the file system (allowing the much-loved edit/refresh cycle).
```
./bin/houndd --prod --addr=address:port
bin/houndd --dev
```
The will start up the combined server/indexer and build all static assets in production mode. The default addr is ":6080", and thus the `--addr` flag can be used to have the server listen on a different port.
2. Before uploading a Pull Request, please run the following command. This should regenerate the file `ui/bindata.go` which should be included in your Pull Request.
```
cd src/github.com/etsy/hound
make
```
## Get in Touch
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/hound/api/api.go → api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package api
import (
"encoding/json"
"fmt"
"hound/config"
"hound/index"
"hound/searcher"
"github.com/etsy/hound/config"
"github.com/etsy/hound/index"
"github.com/etsy/hound/searcher"
"log"
"net/http"
"strconv"
Expand Down
4 changes: 2 additions & 2 deletions src/hound/client/ack.go → client/ack.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package client

import (
"ansi"
"bytes"
"fmt"
"hound/config"
"github.com/etsy/hound/ansi"
"github.com/etsy/hound/config"
"os"
"regexp"
)
Expand Down
4 changes: 2 additions & 2 deletions src/hound/client/client.go → client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package client
import (
"encoding/json"
"fmt"
"hound/config"
"hound/index"
"github.com/etsy/hound/config"
"github.com/etsy/hound/index"
"net/http"
"net/url"
"regexp"
Expand Down
2 changes: 1 addition & 1 deletion src/hound/client/coalesce.go → client/coalesce.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"hound/index"
"github.com/etsy/hound/index"
)

type Block struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"hound/index"
"github.com/etsy/hound/index"
"testing"
)

Expand Down
4 changes: 2 additions & 2 deletions src/hound/client/grep.go → client/grep.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package client

import (
"ansi"
"fmt"
"hound/config"
"github.com/etsy/hound/ansi"
"github.com/etsy/hound/config"
"os"
"regexp"
)
Expand Down
4 changes: 2 additions & 2 deletions src/hound/cmds/hound/main.go → cmds/hound/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"encoding/json"
"flag"
"hound/client"
"hound/index"
"github.com/etsy/hound/client"
"github.com/etsy/hound/index"
"log"
"os"
"os/user"
Expand Down
120 changes: 120 additions & 0 deletions cmds/houndd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package main

import (
"encoding/json"
"flag"
"github.com/etsy/hound/api"
"github.com/etsy/hound/config"
"github.com/etsy/hound/searcher"
"github.com/etsy/hound/ui"
"log"
"net/http"
"os"
"runtime"
"strings"
)

var (
info_log *log.Logger
error_log *log.Logger
)

func makeSearchers(cfg *config.Config) (map[string]*searcher.Searcher, bool, error) {
// Ensure we have a dbpath
if _, err := os.Stat(cfg.DbPath); err != nil {
if err := os.MkdirAll(cfg.DbPath, os.ModePerm); err != nil {
return nil, false, err
}
}

searchers, errs, err := searcher.MakeAll(cfg)
if err != nil {
return nil, false, err
}

if len(errs) > 0 {
// NOTE: This mutates the original config so the repos
// are not even seen by other code paths.
for name, _ := range errs {
delete(cfg.Repos, name)
}

return searchers, false, nil
}

return searchers, true, nil
}

func makeTemplateData(cfg *config.Config) (interface{}, error) {
var data struct {
ReposAsJson string
}

res := map[string]*config.Repo{}
for name, repo := range cfg.Repos {
res[strings.ToLower(name)] = repo
}

b, err := json.Marshal(res)
if err != nil {
return nil, err
}

data.ReposAsJson = string(b)
return &data, nil
}

func runHttp(
addr string,
dev bool,
cfg *config.Config,
idx map[string]*searcher.Searcher) error {
m := http.DefaultServeMux

h, err := ui.Content(dev, cfg)
if err != nil {
return err
}

m.Handle("/", h)
api.Setup(m, idx)
return http.ListenAndServe(addr, m)
}

func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
info_log = log.New(os.Stdout, "", log.LstdFlags)
error_log = log.New(os.Stderr, "", log.LstdFlags)

flagConf := flag.String("conf", "config.json", "")
flagAddr := flag.String("addr", ":6080", "")
flagDev := flag.Bool("dev", false, "")

flag.Parse()

var cfg config.Config
if err := cfg.LoadFromFile(*flagConf); err != nil {
panic(err)
}

idx, ok, err := makeSearchers(&cfg)
if err != nil {
log.Panic(err)
}
if !ok {
info_log.Println("Some repos failed to index, see output above")
} else {
info_log.Println("All indexes built!")
}

host := *flagAddr
if strings.HasPrefix(host, ":") {
host = "localhost" + host
}

info_log.Printf("running server at http://%s...\n", host)

if err := runHttp(*flagAddr, *flagDev, &cfg, idx); err != nil {
panic(err)
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"syscall"
"unsafe"

"hound/codesearch/sparse"
"github.com/etsy/hound/codesearch/sparse"
)

// Index writing. See read.go for details of on-disk format.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"regexp/syntax"
"sort"

"hound/codesearch/sparse"
"github.com/etsy/hound/codesearch/sparse"
)

// A matcher holds the state for running regular expression search.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/hound/config/config_test.go → config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config

import (
"hound/vcs"
"github.com/etsy/hound/vcs"
"path/filepath"
"runtime"
"testing"
Expand All @@ -11,7 +11,7 @@ const exampleConfigFile = "config-example.json"

func rootDir() string {
_, file, _, _ := runtime.Caller(0)
return filepath.Join(filepath.Dir(file), "../../../")
return filepath.Join(filepath.Dir(file), "..")
}

// Test that we can parse the example config file. This ensures that as we
Expand Down
4 changes: 2 additions & 2 deletions hound.sublime-project
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
],
"settings":
{
"tab_size": 2,
"tab_size": 4,
"convert_tabspaces_on_save": true,
"translate_tabs_to_spaces": true
"translate_tabs_to_spaces": false
}
}
2 changes: 1 addition & 1 deletion src/hound/index/grep.go → index/grep.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package index
import (
"bytes"
"compress/gzip"
"hound/codesearch/regexp"
"github.com/etsy/hound/codesearch/regexp"
"io"
"os"
)
Expand Down
Loading

0 comments on commit 3eeb57d

Please sign in to comment.