Skip to content

Commit 93eddc9

Browse files
authored
Another attempt to replace go-bindata with //go:embed (#460)
* switch from go-bindata to embed Signed-off-by: moson-mo <[email protected]> * bump semver dependency to v4 Signed-off-by: moson-mo <[email protected]> * amend workflow jobs for go-embed switch Signed-off-by: moson-mo <[email protected]> --------- Signed-off-by: moson-mo <[email protected]>
1 parent 31f927c commit 93eddc9

File tree

11 files changed

+100
-868
lines changed

11 files changed

+100
-868
lines changed

.github/workflows/go.yaml

+19-15
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,22 @@ on:
66
# Run CI for PRs to main and staging
77
pull_request:
88
branches: [ main ]
9+
workflow_dispatch:
910
jobs:
10-
go-build:
11+
build:
1112
runs-on: ubuntu-latest
1213
strategy:
1314
matrix:
14-
go: ["1.18", "1.17", "1.14"]
15+
go: ["1.18", "1.17", "1.16"]
1516
steps:
1617
- uses: actions/[email protected]
17-
- uses: actions/setup-go@v2
18+
- uses: actions/setup-node@v3
1819
with:
19-
go-version: ${{ matrix.go }}
20-
- run: go build -x -work ./cmds/...
21-
node-build:
22-
runs-on: ubuntu-latest
23-
steps:
24-
- uses: actions/[email protected]
25-
- uses: actions/setup-node@v1
20+
node-version: current
21+
- uses: actions/setup-go@v3
2622
with:
27-
node-version: "10.x"
28-
- run: npm install
23+
go-version: ${{ matrix.go }}
24+
- run: make
2925
docker-build:
3026
name: Create docker image
3127
runs-on: ubuntu-latest
@@ -71,6 +67,10 @@ jobs:
7167
runs-on: ${{ matrix.os }}
7268
steps:
7369
- uses: actions/checkout@v3
70+
- uses: actions/setup-node@v3
71+
with:
72+
node-version: current
73+
- run: make ui
7474
- uses: actions/setup-go@v3
7575
with:
7676
go-version: ${{ matrix.go }}
@@ -79,15 +79,19 @@ jobs:
7979
with:
8080
version: v1.46.2
8181

82-
go-test:
82+
test:
8383
strategy:
8484
matrix:
85-
go: ["1.18", "1.17", "1.14"]
85+
go: ["1.18", "1.17", "1.16"]
8686
os: [windows-latest, ubuntu-latest]
8787
runs-on: ${{ matrix.os }}
8888
steps:
8989
- uses: actions/[email protected]
90-
- uses: actions/setup-go@v2
90+
- uses: actions/setup-node@v3
91+
with:
92+
node-version: current
93+
- run: make ui
94+
- uses: actions/setup-go@v3
9195
with:
9296
go-version: ${{ matrix.go }}
9397
- run: go test -race ./...

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
/.idea
99
dist/
1010
config.json
11+
/ui/.build

Dockerfile

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ FROM alpine:3.16
22

33
ENV GOPATH /go
44

5-
COPY . /go/src/github.com/hound-search/hound
5+
COPY . /src
66

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

1616
VOLUME ["/data"]
1717

1818
EXPOSE 6080
1919

20-
ENTRYPOINT ["/sbin/tini", "--", "/go/bin/houndd", "-conf", "/data/config.json"]
20+
ENTRYPOINT ["/sbin/tini", "--", "/bin/houndd", "-conf", "/data/config.json"]

Makefile

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CMDS := .build/bin/houndd .build/bin/hound
22

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

56
WEBPACK_ARGS := --mode production
67
ifdef DEBUG
@@ -9,27 +10,24 @@ endif
910

1011
ALL: $(CMDS)
1112

12-
ui: ui/bindata.go
13+
ui: ui/.build/ui
1314

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

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

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

26-
.build/bin/go-bindata:
27-
go build -o $@ github.com/go-bindata/go-bindata/go-bindata
28-
29-
ui/bindata.go: .build/bin/go-bindata node_modules/build $(wildcard ui/assets/**/*)
30-
rsync -r ui/assets/* .build/ui
27+
ui/.build/ui: node_modules/build $(UI)
28+
mkdir -p ui/.build/ui
29+
cp -r ui/assets/* ui/.build/ui
3130
npx webpack $(WEBPACK_ARGS)
32-
$< -o $@ -pkg ui -prefix .build/ui -nomemcopy .build/ui/...
3331

3432
dev: node_modules/build
3533

@@ -45,4 +43,4 @@ lint:
4543
golangci-lint run ./...
4644

4745
clean:
48-
rm -rf .build node_modules
46+
rm -rf .build ui/.build node_modules

README.md

+43-31
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,21 @@ Hound is an extremely fast source code search engine. The core is based on this
1111

1212
## Quick Start Guide
1313

14-
### Using Go Tools
14+
### Building hound
1515

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

17-
0. [Install Go](https://golang.org/doc/install) if you don't have it already. Hound requires version 1.4 or later.
18-
You might also want to define a [`GOPATH`](https://github.com/golang/go/wiki/GOPATH) environment variable)
19-
(it defaults to $HOME/go if you don't explicitly have one set). If everything is installed properly, `go version` should
20-
print out the installed version of go.
21-
22-
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).
23-
24-
```
25-
go get github.com/hound-search/hound/cmds/...
26-
```
27-
28-
If the above doesn't work for you, try to install hound manually with the following:
18+
1. Clone the repository and run make.
2919

3020
```
3121
git clone https://github.com/hound-search/hound.git
3222
cd hound
33-
go build ./cmds/hound
34-
go build ./cmds/houndd
35-
sudo mv hound houndd ~/go/bin/
23+
make
3624
```
3725

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

40-
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)
28+
2. Create a config.json file and use it to list your repositories. Check out our [example-config.json](config-example.json)
4129
to see how to set up various types of repositories. For example, we can configure Hound to search its own source code using
4230
the config found in [default-config.json](default-config.json):
4331

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

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

55-
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:
43+
3. Run the Hound server with `houndd` in the same directory as your `config.json`. You should see output similar to:
5644
```
5745
2015/03/13 09:07:42 Searcher started for statsd
5846
2015/03/13 09:07:42 Searcher started for Hound
@@ -62,21 +50,47 @@ the config found in [default-config.json](default-config.json):
6250

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

65-
### Using Docker (1.4+)
53+
### Using Docker (1.14+)
6654

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

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

73-
2. Run
74-
```
75-
docker run -d -p 6080:6080 --name hound -v $(pwd):/data ghcr.io/hound-search/hound:latest
76-
```
61+
62+
#### Run with image from github
63+
64+
```
65+
docker run -d -p 6080:6080 --name hound -v $(pwd):/data ghcr.io/hound-search/hound:latest
66+
```
7767

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

70+
#### Build image and container yourself
71+
72+
0. Clone repository
73+
```
74+
git clone https://github.com/hound-search/hound.git
75+
cd hound
76+
```
77+
78+
1. Build the image
79+
```
80+
docker build . --tag=hound
81+
```
82+
83+
2. Create the container
84+
```
85+
docker create -p 6080:6080 --name hound -v $(pwd):/data hound
86+
```
87+
88+
3. Starting and stopping the container
89+
```
90+
docker start hound
91+
docker stop hound
92+
```
93+
8094
## Running in Production
8195

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

90104
## Requirements
91-
* Go 1.13+
105+
* Go 1.16+
92106

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

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

135149
#### Requirements:
136150
* make
137-
* Node.js ([Installation Instructions](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager))
138-
139-
While Hound is a proper go module that can be installed with `go install`, there is also a `Makefile` to aid in building locally.
151+
* [npm](https://github.com/npm/cli/#installation)
152+
(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))
140153

141154
```
142155
git clone https://github.com/hound-search/hound.git
@@ -168,9 +181,8 @@ You need to install `Node.js >= 12` and install `jest` by `npm install jest` to
168181

169182
### Working on the web UI
170183

171-
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.
172-
173-
To bundle UI changes in `ui/bindata.go` use:
184+
Hound includes a web UI that is composed of several files (html, css, javascript, etc.).
185+
To compile UI changes use:
174186

175187
```
176188
make ui

cmds/houndd/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"strings"
1515
"syscall"
1616

17-
"github.com/blang/semver"
17+
"github.com/blang/semver/v4"
1818
"github.com/hound-search/hound/api"
1919
"github.com/hound-search/hound/config"
2020
"github.com/hound-search/hound/searcher"

go.mod

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
module github.com/hound-search/hound
22

3-
go 1.13
3+
go 1.16
44

5-
require (
6-
github.com/blang/semver v3.5.1+incompatible
7-
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect
8-
)
5+
require github.com/blang/semver/v4 v4.0.0

go.sum

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
github.com/blang/semver v1.1.0 h1:ol1rO7QQB5uy7umSNV7VAmLugfLRD+17sYJujRNYPhg=
2-
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
3-
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
4-
github.com/go-bindata/go-bindata v1.0.0 h1:DZ34txDXWn1DyWa+vQf7V9ANc2ILTtrEjtlsdJRF26M=
5-
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
6-
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
1+
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
2+
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=

tools/tools.go

-6
This file was deleted.

0 commit comments

Comments
 (0)