Skip to content

Commit

Permalink
Another attempt to replace go-bindata with //go:embed (hound-search#460)
Browse files Browse the repository at this point in the history
* switch from go-bindata to embed

Signed-off-by: moson-mo <mo-son@mailbox.org>

* bump semver dependency to v4

Signed-off-by: moson-mo <mo-son@mailbox.org>

* amend workflow jobs for go-embed switch

Signed-off-by: moson-mo <mo-son@mailbox.org>

---------

Signed-off-by: moson-mo <mo-son@mailbox.org>
  • Loading branch information
moson-mo authored Jun 8, 2023
1 parent 31f927c commit 93eddc9
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 868 deletions.
34 changes: 19 additions & 15 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,22 @@ on:
# Run CI for PRs to main and staging
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
go-build:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.18", "1.17", "1.14"]
go: ["1.18", "1.17", "1.16"]
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/setup-go@v2
- uses: actions/setup-node@v3
with:
go-version: ${{ matrix.go }}
- run: go build -x -work ./cmds/...
node-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/setup-node@v1
node-version: current
- uses: actions/setup-go@v3
with:
node-version: "10.x"
- run: npm install
go-version: ${{ matrix.go }}
- run: make
docker-build:
name: Create docker image
runs-on: ubuntu-latest
Expand Down Expand Up @@ -71,6 +67,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: current
- run: make ui
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
Expand All @@ -79,15 +79,19 @@ jobs:
with:
version: v1.46.2

go-test:
test:
strategy:
matrix:
go: ["1.18", "1.17", "1.14"]
go: ["1.18", "1.17", "1.16"]
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/setup-go@v2
- uses: actions/setup-node@v3
with:
node-version: current
- run: make ui
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- run: go test -race ./...
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/.idea
dist/
config.json
/ui/.build
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ FROM alpine:3.16

ENV GOPATH /go

COPY . /go/src/github.com/hound-search/hound
COPY . /src

RUN apk update \
&& apk add go git subversion libc-dev mercurial breezy openssh tini build-base \
&& cd /go/src/github.com/hound-search/hound \
&& go mod download \
&& go install github.com/hound-search/hound/cmds/houndd \
&& apk del go build-base \
&& rm -f /var/cache/apk/* \
&& rm -rf /go/src /go/pkg
&& apk add go git subversion libc-dev mercurial breezy openssh tini build-base npm rsync \
&& cd /src \
&& make \
&& cp .build/bin/houndd /bin \
&& rm -r .build \
&& apk del go build-base rsync npm \
&& rm -f /var/cache/apk/*

VOLUME ["/data"]

EXPOSE 6080

ENTRYPOINT ["/sbin/tini", "--", "/go/bin/houndd", "-conf", "/data/config.json"]
ENTRYPOINT ["/sbin/tini", "--", "/bin/houndd", "-conf", "/data/config.json"]
18 changes: 8 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CMDS := .build/bin/houndd .build/bin/hound

SRCS := $(shell find . -type f -name '*.go')
UI := $(shell find ui/assets -type f)

WEBPACK_ARGS := --mode production
ifdef DEBUG
Expand All @@ -9,27 +10,24 @@ endif

ALL: $(CMDS)

ui: ui/bindata.go
ui: ui/.build/ui

# the mtime is updated on a directory when its files change so it's better
# to rely on a single file to represent the presence of node_modules.
node_modules/build:
npm install
date -u >> $@

.build/bin/houndd: ui/bindata.go $(SRCS)
.build/bin/houndd: ui/.build/ui $(SRCS)
go build -o $@ github.com/hound-search/hound/cmds/houndd

.build/bin/hound: ui/bindata.go $(SRCS)
.build/bin/hound: $(SRCS)
go build -o $@ github.com/hound-search/hound/cmds/hound

.build/bin/go-bindata:
go build -o $@ github.com/go-bindata/go-bindata/go-bindata

ui/bindata.go: .build/bin/go-bindata node_modules/build $(wildcard ui/assets/**/*)
rsync -r ui/assets/* .build/ui
ui/.build/ui: node_modules/build $(UI)
mkdir -p ui/.build/ui
cp -r ui/assets/* ui/.build/ui
npx webpack $(WEBPACK_ARGS)
$< -o $@ -pkg ui -prefix .build/ui -nomemcopy .build/ui/...

dev: node_modules/build

Expand All @@ -45,4 +43,4 @@ lint:
golangci-lint run ./...

clean:
rm -rf .build node_modules
rm -rf .build ui/.build node_modules
74 changes: 43 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,21 @@ Hound is an extremely fast source code search engine. The core is based on this

## Quick Start Guide

### Using Go Tools
### Building hound

0. Install [go](https://go.dev/) (minimum version required: 1.16) and [npm](https://github.com/npm/cli/#installation)

0. [Install Go](https://golang.org/doc/install) if you don't have it already. Hound requires version 1.4 or later.
You might also want to define a [`GOPATH`](https://github.com/golang/go/wiki/GOPATH) environment variable)
(it defaults to $HOME/go if you don't explicitly have one set). If everything is installed properly, `go version` should
print out the installed version of go.

1. Use the Go tools to install Hound. The binaries `houndd` (server) and `hound` (cli) will be installed in your $GOPATH/bin directory. Your $GOPATH should be in your $PATH (`echo $PATH` to check).

```
go get github.com/hound-search/hound/cmds/...
```

If the above doesn't work for you, try to install hound manually with the following:
1. Clone the repository and run make.

```
git clone https://github.com/hound-search/hound.git
cd hound
go build ./cmds/hound
go build ./cmds/houndd
sudo mv hound houndd ~/go/bin/
make
```

You might have to change the path of the last command if you installed Go somewhere else on your system.
The resulting binaries (`hound`, `houndd`) can be found in the .build/bin/ directory.

2. Create a config.json file in your `$GOPATH/bin` and use it to list your repositories. Check out our [example-config.json](config-example.json)
2. Create a config.json file and use it to list your repositories. Check out our [example-config.json](config-example.json)
to see how to set up various types of repositories. For example, we can configure Hound to search its own source code using
the config found in [default-config.json](default-config.json):

Expand All @@ -52,7 +40,7 @@ the config found in [default-config.json](default-config.json):

A complete list of available config options can be found [here](docs/config-options.md).

3. Run the Hound server with `houndd` in the same directory as your `config.json`, which is most likely your `$GOPATH/bin` directory. You should see output similar to:
3. Run the Hound server with `houndd` in the same directory as your `config.json`. You should see output similar to:
```
2015/03/13 09:07:42 Searcher started for statsd
2015/03/13 09:07:42 Searcher started for Hound
Expand All @@ -62,21 +50,47 @@ the config found in [default-config.json](default-config.json):

4. By default, hound hosts a web ui at http://localhost:6080 . Open it in your browser, and start searching.

### Using Docker (1.4+)
### Using Docker (1.14+)

0. [Install docker](https://docs.docker.com/get-docker/) if you don't have it. We need at least `Docker >= 1.14`.

1. Create a config.json file and use it to list your repositories. Check out our [example-config.json](config-example.json)
to see how to set up various types of repositories. For example, we can configure Hound to search its own source code using
the config found in [default-config.json](default-config.json).

2. Run
```
docker run -d -p 6080:6080 --name hound -v $(pwd):/data ghcr.io/hound-search/hound:latest
```

#### Run with image from github

```
docker run -d -p 6080:6080 --name hound -v $(pwd):/data ghcr.io/hound-search/hound:latest
```

You should be able to navigate to [http://localhost:6080/](http://localhost:6080/) as usual.

#### Build image and container yourself

0. Clone repository
```
git clone https://github.com/hound-search/hound.git
cd hound
```

1. Build the image
```
docker build . --tag=hound
```

2. Create the container
```
docker create -p 6080:6080 --name hound -v $(pwd):/data hound
```

3. Starting and stopping the container
```
docker start hound
docker stop hound
```

## Running in Production

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.
Expand All @@ -88,7 +102,7 @@ We've used many similar tools in the past, and most of them are either too slow,
Which brings us to...

## Requirements
* Go 1.13+
* Go 1.16+

Yup, that's it. You can proxy requests to the Go service through Apache/nginx/etc., but that's not required.

Expand Down Expand Up @@ -134,9 +148,8 @@ Currently the following editors have plugins that support Hound:

#### Requirements:
* make
* Node.js ([Installation Instructions](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager))
While Hound is a proper go module that can be installed with `go install`, there is also a `Makefile` to aid in building locally.
* [npm](https://github.com/npm/cli/#installation)
(Usuall npm comes bundled with Node.js. If that's not the case on the system you're using, you can get it [here](https://nodejs.org/en/download))

```
git clone https://github.com/hound-search/hound.git
Expand Down Expand Up @@ -168,9 +181,8 @@ You need to install `Node.js >= 12` and install `jest` by `npm install jest` to
### Working on the web UI
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 bundled inside of the `houndd` binary. Note that changes to the UI will result in local changes to the `ui/bindata.go` file. You must include these changes in your Pull Request.
To bundle UI changes in `ui/bindata.go` use:
Hound includes a web UI that is composed of several files (html, css, javascript, etc.).
To compile UI changes use:
```
make ui
Expand Down
2 changes: 1 addition & 1 deletion cmds/houndd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"strings"
"syscall"

"github.com/blang/semver"
"github.com/blang/semver/v4"
"github.com/hound-search/hound/api"
"github.com/hound-search/hound/config"
"github.com/hound-search/hound/searcher"
Expand Down
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module github.com/hound-search/hound

go 1.13
go 1.16

require (
github.com/blang/semver v3.5.1+incompatible
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect
)
require github.com/blang/semver/v4 v4.0.0
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
github.com/blang/semver v1.1.0 h1:ol1rO7QQB5uy7umSNV7VAmLugfLRD+17sYJujRNYPhg=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/go-bindata/go-bindata v1.0.0 h1:DZ34txDXWn1DyWa+vQf7V9ANc2ILTtrEjtlsdJRF26M=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
6 changes: 0 additions & 6 deletions tools/tools.go

This file was deleted.

Loading

0 comments on commit 93eddc9

Please sign in to comment.