diff --git a/.gitignore b/.gitignore index e43b0f98895..c7b05fd71ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ +/.idea +/build + .DS_Store diff --git a/.travis.yml b/.travis.yml index 7893877faad..52e0489385e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1 +1,17 @@ -# TODO: Run the full setup and check if a running beat is created. +language: go + +go: + - 1.5.3 + +addons: + apt: + packages: + - python-virtualenv + +before_script: + - wget https://github.com/Masterminds/glide/releases/download/0.8.3/glide-0.8.3-linux-386.tar.gz -O /tmp/glide.tar.gz + - tar -xvf /tmp/glide.tar.gz + - export PATH=$PATH:$PWD/linux-386/ + +script: + - make test diff --git a/Makefile b/Makefile index 1272a9ae3b8..1e1c71bbb63 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,28 @@ -setup: - pip install cookiecutter +BUILD_DIR?=build +PWD=$(shell pwd) +PYTHON_ENV=${BUILD_DIR}/python-env/ + +.PHONY: test +test: python-env + mkdir -p build/src + cp -r \{\{cookiecutter.beat\}\} build + cp tests/cookiecutter.json build/ + . build/python-env/bin/activate; cookiecutter --no-input -o build/src -f build + + cd build/src/testbeat; \ + export GOPATH=${PWD}/build; \ + export GO15VENDOREXPERIMENT=1; \ + glide init; \ + glide update --no-recursive ; \ + make update; \ + make + +# Sets up the virtual python environment +.PHONY: python-env +python-env: + test -d ${PYTHON_ENV} || virtualenv ${PYTHON_ENV} + . ${PYTHON_ENV}/bin/activate && pip install cookiecutter PyYAML + +.PHONY: clean +clean: + rm -rf build diff --git a/README.md b/README.md index 2b7f869c486..ca2ed0dba00 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,19 @@ This generator makes it possible to generate your own beat in seconds and build To create your own beat based on this template, run inside your GOPATH where you want to create the beat: ``` -cookiecutter elastic/beat-generator +cookiecutter github.com/elastic/beat-generator ``` This requires python and cookiecutter to be installed (`pip install cookiecutter`). + + +# Goals + +This beat generator has several goals: + +* Create a running in beat in very few steps +* Have an environment for unit, integration and system testing ready to make testing a beat simple +* Ensure easy maintainable and standardised structure of a beat +* Provide all files needed to build up and grow a community around a beat +* Allow release management of a beat +* Make a beat easy to update to the most recent version of libbeat diff --git a/cookiecutter.json b/cookiecutter.json index a6fcaf047bb..66ae10e7b36 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -2,6 +2,6 @@ "project_name": "Examplebeat", "github_name": "your-github-name", "beat": "{{ cookiecutter.project_name|lower }}", - "beat_path": "github.com/{{ cookiecutter.github_name|lower }}", + "beat_path": "github.com/{{ cookiecutter.github_name|lower }}/", "full_name": "Firstname Lastname" } diff --git a/tests/cookiecutter.json b/tests/cookiecutter.json new file mode 100644 index 00000000000..a9f6ce34144 --- /dev/null +++ b/tests/cookiecutter.json @@ -0,0 +1,7 @@ +{ + "project_name": "Testbeat", + "github_name": "ruflin", + "beat": "{{ cookiecutter.project_name|lower }}", + "beat_path": "", + "full_name": "Nicolas Ruflin" +} diff --git a/{{cookiecutter.beat}}/.travis.yml b/{{cookiecutter.beat}}/.travis.yml index e69de29bb2d..cec8cb8f158 100644 --- a/{{cookiecutter.beat}}/.travis.yml +++ b/{{cookiecutter.beat}}/.travis.yml @@ -0,0 +1,43 @@ +sudo: required +dist: trusty +services: + - docker + +language: go + +go: + - 1.5.3 + +os: + - linux + - osx + +env: + matrix: + - TARGETS="check" + - TARGETS="-C {{cookiecutter.beat}} testsuite" + + global: + # Cross-compile for amd64 only to speed up testing. + - GOX_FLAGS="-arch amd64" + +addons: + apt: + packages: + - python-virtualenv + +before_install: + # Redo the travis setup but with the elastic/libbeat path. This is needed so the package path is correct + - mkdir -p $HOME/gopath/src/github.com/elastic/beats/ + - rsync -az ${TRAVIS_BUILD_DIR}/ $HOME/gopath/src/github.com/elastic/beats/ + - export TRAVIS_BUILD_DIR=$HOME/gopath/src/github.com/elastic/beats/ + - cd $HOME/gopath/src/github.com/elastic/beats/ + +install: + - true + +script: + - make $TARGETS + +after_success: + # Copy full.cov to coverage.txt because codecov.io requires this file diff --git a/{{cookiecutter.beat}}/Makefile b/{{cookiecutter.beat}}/Makefile index bbc009ea5b0..6e88569f64e 100644 --- a/{{cookiecutter.beat}}/Makefile +++ b/{{cookiecutter.beat}}/Makefile @@ -2,12 +2,15 @@ BEATNAME={{cookiecutter.beat}} BEAT_DIR={{cookiecutter.beat_path}} SYSTEM_TESTS=false TEST_ENVIRONMENT=false - -PREFIX?=. ES_BEATS=./vendor/github.com/elastic/beats GOPACKAGES=$(shell glide novendor) +BEAT_DIR={{cookiecutter.beat_path}} +PREFIX?=. + +# Path to the libbeat Makefile include $(ES_BEATS)/libbeat/scripts/Makefile + .PHONY: generate generate: python scripts/generate_template.py etc/fields.yml etc/{{cookiecutter.beat}}.template.json @@ -23,5 +26,6 @@ install-cfg: cp etc/{{cookiecutter.beat}}.yml $(PREFIX)/{{cookiecutter.beat}}-darwin.yml cp etc/{{cookiecutter.beat}}.yml $(PREFIX)/{{cookiecutter.beat}}-win.yml +.PHONY: update-deps update-deps: glide update --no-recursive diff --git a/{{cookiecutter.beat}}/beater/{{cookiecutter.beat}}.go b/{{cookiecutter.beat}}/beater/{{cookiecutter.beat}}.go index e5be5a5cf7e..021ee3b9c01 100644 --- a/{{cookiecutter.beat}}/beater/{{cookiecutter.beat}}.go +++ b/{{cookiecutter.beat}}/beater/{{cookiecutter.beat}}.go @@ -6,7 +6,7 @@ import ( "github.com/elastic/beats/libbeat/beat" "github.com/elastic/beats/libbeat/cfgfile" - "{{cookiecutter.beat_path}}/{{cookiecutter.beat}}/config" + "{{cookiecutter.beat_path}}{{cookiecutter.beat}}/config" ) type {{cookiecutter.beat|capitalize}} struct { @@ -30,7 +30,6 @@ func (bt *{{cookiecutter.beat|capitalize}}) Config(b *beat.Beat) error { return fmt.Errorf("Error reading config file: %v", err) } - return nil } @@ -40,8 +39,9 @@ func (bt *{{cookiecutter.beat|capitalize}}) Setup(b *beat.Beat) error { func (bt *{{cookiecutter.beat|capitalize}}) Run(b *beat.Beat) error { fmt.Println("{{cookiecutter.beat}} is running! Hit CTRL-C to stop it.") - + <-bt.done + return nil } diff --git a/{{cookiecutter.beat}}/main.go b/{{cookiecutter.beat}}/main.go index d9e5fdddb51..e1fb45ac02a 100644 --- a/{{cookiecutter.beat}}/main.go +++ b/{{cookiecutter.beat}}/main.go @@ -2,7 +2,7 @@ package main import ( "github.com/elastic/beats/libbeat/beat" - "{{cookiecutter.beat_path}}/{{cookiecutter.beat}}/beater" + "{{cookiecutter.beat_path}}{{cookiecutter.beat}}/beater" ) func main() {