Skip to content

Commit

Permalink
Merge pull request #212 from bzz/sdk-split-binaries
Browse files Browse the repository at this point in the history
Split lookout binary to daemon and SDK
  • Loading branch information
bzz authored Sep 3, 2018
2 parents aaa4337 + 97755a5 commit 2a9be39
Show file tree
Hide file tree
Showing 21 changed files with 147 additions and 114 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ jobs:
os: osx
osx_image: xcode9.4
before_install: skip
- name: "Lookout serve Integration Tests Linux"
- name: "Lookoutd Integration Tests Linux"
script:
- make prepare-services
- psql -c 'create database lookout;' -U postgres
- make build
- ./build/bin/lookout migrate
- ./build/bin/lookoutd migrate
- make test-json
- name: "Lookout serve Integration Tests macOS"
- name: "Lookoutd Integration Tests macOS"
script:
- make prepare-services
- psql -c 'create database lookout;' -U postgres
- make build
- ./build/lookout_darwin_amd64/lookout migrate
- ./build/lookout_darwin_amd64/lookoutd migrate
- make test-json
os: osx
osx_image: xcode9.4
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
- find "$PY_OUT_DIR" -iname gogo_pb2_grpc.py | grep '.*'
- name: "linux packages"
stage: release
script: PKG_OS="linux" make packages-sdk
script: PKG_OS="linux" make -f Makefile.sdk packages
deploy: &deploy_anchor
provider: releases
api_key: $GITHUB_TOKEN
Expand All @@ -100,7 +100,7 @@ jobs:
os: osx
osx_image: xcode9.4
before_install: skip
script: PKG_OS="darwin" make packages-sdk
script: PKG_OS="darwin" make -f Makefile.sdk packages
deploy: *deploy_anchor
- name: "push image to Docker Hub"
stage: release
Expand Down
49 changes: 19 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package configuration
PROJECT = lookout
COMMANDS = cmd/lookout
COMMANDS = cmd/lookoutd
DEPENDENCIES = \
gopkg.in/src-d/go-kallax.v1 \
github.com/jteeuwen/go-bindata
Expand All @@ -27,7 +27,10 @@ CONFIG_FILE := config.yml

# SDK binaries
DUMMY_BIN := $(BIN_PATH)/dummy
LOOKOUT_BIN := $(BIN_PATH)/lookout
LOOKOUT_SDK_BIN := $(BIN_PATH)/lookout-sdk

# lookoutd binary
LOOKOUT_BIN := $(BIN_PATH)/lookoutd

# Tools
BINDATA := go-bindata
Expand Down Expand Up @@ -80,61 +83,47 @@ GOTEST_INTEGRATION = $(GOTEST) -tags=integration

# Integration test for sdk client
.PHONY: test-sdk
test-sdk: clean-sdk build-sdk
test-sdk: clean-all build-all
DUMMY_BIN=$(PWD)/$(DUMMY_BIN) \
LOOKOUT_BIN=$(PWD)/$(LOOKOUT_BIN) \
LOOKOUT_BIN=$(PWD)/$(LOOKOUT_SDK_BIN) \
$(GOTEST_INTEGRATION) github.com/src-d/lookout/cmd/sdk-test

# Same as test-sdk, but skipping tests that require a bblfshd server
.PHONY: test-sdk-short
test-sdk-short: clean-sdk build-sdk
test-sdk-short: clean-all build-all
DUMMY_BIN=$(PWD)/$(DUMMY_BIN) \
LOOKOUT_BIN=$(PWD)/$(LOOKOUT_BIN) \
LOOKOUT_BIN=$(PWD)/$(LOOKOUT_SDK_BIN) \
$(GOTEST_INTEGRATION) -test.short github.com/src-d/lookout/cmd/sdk-test

# Integration test for lookout serve
.PHONY: test-json
test-json: clean-sdk build-sdk
test-json: clean build-all
DUMMY_BIN=$(PWD)/$(DUMMY_BIN) \
LOOKOUT_BIN=$(PWD)/$(LOOKOUT_BIN) \
$(GOTEST_INTEGRATION) github.com/src-d/lookout/cmd/server-test

# Build sdk client and dummy analyzer
.PHONY: build-sdk
build-sdk: $(DUMMY_BIN) $(LOOKOUT_BIN)
.PHONY: build-all
build-all: $(DUMMY_BIN) $(LOOKOUT_BIN) $(LOOKOUT_SDK_BIN)
$(LOOKOUT_BIN):
$(GOBUILD) -o "$(LOOKOUT_BIN)" ./cmd/lookout
$(GOBUILD) -o "$(LOOKOUT_BIN)" ./cmd/lookoutd
$(LOOKOUT_SDK_BIN):
$(GOBUILD) -o "$(LOOKOUT_SDK_BIN)" ./cmd/lookout-sdk
$(DUMMY_BIN):
$(GOBUILD) -o "$(DUMMY_BIN)" ./cmd/dummy

.PHONY: clean-sdk
clean-sdk:
.PHONY: clean-all
clean-all:
rm -f $(DUMMY_BIN)
rm -f $(LOOKOUT_BIN)
rm -f $(LOOKOUT_SDK_BIN)

.PHONY: dry-run
dry-run: $(CONFIG_FILE)
go run cmd/lookout/*.go serve --dry-run github.com/src-d/lookout
go run cmd/lookoutd/*.go serve --dry-run github.com/src-d/lookout
$(CONFIG_FILE):
cp "$(CONFIG_FILE).tpl" $(CONFIG_FILE)

# Builds build/lookout_sdk_*.tar.gz with the lookout bin and sdk dir
.PHONY: packages-sdk
packages-sdk: PROJECT = lookout_sdk
packages-sdk: build
@for os in $(PKG_OS); do \
for arch in $(PKG_ARCH); do \
cp -r sdk $(BUILD_PATH)/$(PROJECT)_$${os}_$${arch}/; \
done; \
done; \
cd $(BUILD_PATH); \
for os in $(PKG_OS); do \
for arch in $(PKG_ARCH); do \
TAR_VERSION=`echo $(VERSION) | tr "/" "-"`; \
tar -cvzf $(PROJECT)_$${TAR_VERSION}_$${os}_$${arch}.tar.gz $(PROJECT)_$${os}_$${arch}/; \
done; \
done

# TODO: remove when https://github.com/src-d/ci/pull/84 is merged
.PHONY: godep
GODEP ?= $(CI_PATH)/dep
Expand Down
2 changes: 1 addition & 1 deletion Makefile.dummy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Package configuration
# Packaging Dummy Analzyer binary
PROJECT = lookout-dummy-analyzer
COMMANDS = cmd/dummy

Expand Down
12 changes: 12 additions & 0 deletions Makefile.sdk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Packaging lookout-sdk binary
PROJECT = lookout-sdk
COMMANDS = cmd/lookout-sdk

# Including ci Makefile
CI_REPOSITORY ?= https://github.com/src-d/ci.git
CI_BRANCH ?= v1
CI_PATH ?= .ci
MAKEFILE := $(CI_PATH)/Makefile.main
$(MAKEFILE):
git clone --quiet --depth 1 -b $(CI_BRANCH) $(CI_REPOSITORY) $(CI_PATH);
-include $(MAKEFILE)
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A service for assisted code review, that allows running custom code Analyzers on

If you are developing an Analyzer, please check [SDK documentation](./sdk/README.md).

It includes a curl-style binary that allows to trigger Analyzers directly, without launching a full lookout server.
It includes a curl-style binary `lookout-sdk` that allows to trigger Analyzers directly, without launching a full lookout server.

# Installation

Expand Down Expand Up @@ -41,7 +41,7 @@ GITHUB_USER=<user> GITHUB_TOKEN=<token> REPO=github.com/<user>/<name> docker-com
```
1. Initialize the database. This command will work for the PostgreSQL created by docker-compose, use `-h` to see other options.
```bash
lookout migrate
lookoutd migrate
```
1. Start an analyzer
Any of the analyzers or a default dummy one, included in this repository
Expand All @@ -52,9 +52,9 @@ Any of the analyzers or a default dummy one, included in this repository
1. Start a lookout server
1. With posting analysis results on GitHub
- Obtain [GitHub access token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/)
- Run `lookout serve --github-token <token> --github-user <user> <repository>`
- Run `lookoutd serve --github-token <token> --github-user <user> <repository>`
1. Without posting analysis results (only printing)
- `lookout serve --dry-run <repository>`
- `lookoutd serve --dry-run <repository>`


# Configuration file
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions cmd/lookout-sdk/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import "github.com/src-d/lookout/util/cli"

var (
name = "lookout-sdk"
version = "undefined"
build = "undefined"
)

var app = cli.New(name)

func main() {
app.RunMain()
}
2 changes: 1 addition & 1 deletion cmd/lookout/push.go → cmd/lookout-sdk/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *PushCommand) Execute(args []string) error {
return err
}

srv := server.NewServer(nil, &LogPoster{log.DefaultLogger}, dataSrv.FileGetter, map[string]lookout.Analyzer{
srv := server.NewServer(nil, &server.LogPoster{log.DefaultLogger}, dataSrv.FileGetter, map[string]lookout.Analyzer{
"test-analyzes": lookout.Analyzer{
Client: client,
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/lookout/review.go → cmd/lookout-sdk/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c *ReviewCommand) Execute(args []string) error {
return err
}

srv := server.NewServer(nil, &LogPoster{log.DefaultLogger}, dataSrv.FileGetter, map[string]lookout.Analyzer{
srv := server.NewServer(nil, &server.LogPoster{log.DefaultLogger}, dataSrv.FileGetter, map[string]lookout.Analyzer{
"test-analyzes": lookout.Analyzer{
Client: client,
},
Expand Down
14 changes: 14 additions & 0 deletions cmd/lookout-sdk/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import "github.com/src-d/lookout/util/cli"

func init() {
if _, err := app.AddCommand("version", "show version information", "",
&cli.VersionCommand{
Name: name,
Version: version,
Build: build,
}); err != nil {
panic(err)
}
}
2 changes: 1 addition & 1 deletion cmd/lookout/main.go → cmd/lookoutd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import "github.com/src-d/lookout/util/cli"

var (
name = "lookout"
name = "lookoutd"
version = "undefined"
build = "undefined"
)
Expand Down
File renamed without changes.
41 changes: 3 additions & 38 deletions cmd/lookout/serve.go → cmd/lookoutd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"strings"

"github.com/gregjones/httpcache/diskcache"
"github.com/src-d/lookout"
"github.com/src-d/lookout/provider/github"
"github.com/src-d/lookout/provider/json"
Expand All @@ -24,6 +23,7 @@ import (
"github.com/src-d/lookout/util/grpchelper"

"github.com/golang-migrate/migrate"
"github.com/gregjones/httpcache/diskcache"
_ "github.com/lib/pq"
"google.golang.org/grpc"
"gopkg.in/src-d/go-billy.v4/osfs"
Expand Down Expand Up @@ -188,7 +188,7 @@ func (c *ServeCommand) initProvider(conf Config) error {

func (c *ServeCommand) initPoster(conf Config) (lookout.Poster, error) {
if c.DryRun {
return &LogPoster{log.DefaultLogger}, nil
return &server.LogPoster{log.DefaultLogger}, nil
}

switch c.Provider {
Expand Down Expand Up @@ -318,45 +318,10 @@ func (c *ServeCommand) initDB() (*sql.DB, error) {
if dbVersion != maxVersion {
return nil, fmt.Errorf(
"database version mismatch. Current version is %v, but this binary (version %s, built on %s) needs version %v. "+
"Use 'lookout migrate' to upgrade your database", dbVersion, version, build, maxVersion)
"Use '%s migrate' to upgrade your database", dbVersion, version, build, maxVersion, name)
}

log.Debugf("the DB version is up to date, %v", dbVersion)
log.Infof("connection with the DB established")
return db, nil
}

type LogPoster struct {
Log log.Logger
}

func (p *LogPoster) Post(ctx context.Context, e lookout.Event,
aCommentsList []lookout.AnalyzerComments) error {
for _, aComments := range aCommentsList {
for _, c := range aComments.Comments {
logger := p.Log.With(log.Fields{
"text": c.Text,
})
if c.File == "" {
logger.Infof("global comment")
continue
}

logger = logger.With(log.Fields{"file": c.File})
if c.Line == 0 {
logger.Infof("file comment")
continue
}

logger.With(log.Fields{"line": c.Line}).Infof("line comment")
}
}

return nil
}

func (p *LogPoster) Status(ctx context.Context, e lookout.Event,
status lookout.AnalysisStatus) error {
p.Log.Infof("status: %s", status)
return nil
}
14 changes: 14 additions & 0 deletions cmd/lookoutd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import "github.com/src-d/lookout/util/cli"

func init() {
if _, err := app.AddCommand("version", "show version information", "",
&cli.VersionCommand{
Name: name,
Version: version,
Build: build,
}); err != nil {
panic(err)
}
}
2 changes: 1 addition & 1 deletion cmd/server-test/error_analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (suite *ErrorAnalyzerIntegrationSuite) TearDownTest() {
func (suite *ErrorAnalyzerIntegrationSuite) TestAnalyzerErr() {
suite.sendEvent(successJSON)

suite.GrepTrue(suite.r, `msg="analysis failed" analyzer=Dummy app=lookout error="rpc error: code = Unknown desc = review error"`)
suite.GrepTrue(suite.r, `msg="analysis failed" analyzer=Dummy app=lookoutd error="rpc error: code = Unknown desc = review error"`)
}

func TestErrorAnalyzerIntegrationSuite(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
- "10301:10301"
entrypoint: ["/bin/sh"]
# sleep because container with db is up but the db itself doesn't accept connections yet
command: ["-c", "sleep 5 && lookout migrate && lookout serve ${REPO}"]
command: ["-c", "sleep 5 && lookoutd migrate && lookoutd serve ${REPO}"]
volumes:
- ./config.yml:/config.yml
dummy:
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apt-get update && \
apt-get install -y ca-certificates && \
rm -rf /var/lib/apt/lists/*

ADD ./build/bin/lookout /bin/lookout
ADD ./build/bin/lookoutd /bin/lookoutd

ENTRYPOINT ["/bin/lookout"]
ENTRYPOINT ["/bin/lookoutd"]
CMD [ "serve" ]
Loading

0 comments on commit 2a9be39

Please sign in to comment.