Skip to content

Commit

Permalink
Merge pull request #2 from ruflin/travis
Browse files Browse the repository at this point in the history
Update Makefile and add Travis
  • Loading branch information
Steffen Siering committed Jan 26, 2016
2 parents ff6e7fe + a3096f9 commit b7f294c
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/.idea
/build

.DS_Store
18 changes: 17 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 28 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
7 changes: 7 additions & 0 deletions tests/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"project_name": "Testbeat",
"github_name": "ruflin",
"beat": "{{ cookiecutter.project_name|lower }}",
"beat_path": "",
"full_name": "Nicolas Ruflin"
}
43 changes: 43 additions & 0 deletions {{cookiecutter.beat}}/.travis.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions {{cookiecutter.beat}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions {{cookiecutter.beat}}/beater/{{cookiecutter.beat}}.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.beat}}/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit b7f294c

Please sign in to comment.