From e9360f71439fcfea20fdfa56dc1d33ef739c2a73 Mon Sep 17 00:00:00 2001 From: Nan Liu Date: Wed, 21 Sep 2016 11:39:09 -0700 Subject: [PATCH] Update from Intelsdi-x pluginsync 0.1.6 --- .github/ISSUE_TEMPLATE.md | 34 ++++++ .github/PULL_REQUEST_TEMPLATE.md | 21 ++++ .gitignore | 22 ++-- .pluginsync.yml | 17 +++ .sync.yml | 14 +++ .travis.yml | 75 ++++++++++--- CONTRIBUTING.md | 39 +++---- LICENSE | 2 +- Makefile | 35 +++--- kafka/kafka_integration_test.go | 2 +- kafka/kafka_test.go | 2 +- main_test.go | 2 +- scripts/build.sh | 72 +++++++------ scripts/common.sh | 111 +++++++++++++++++++ scripts/deps.sh | 73 +++++++++++++ scripts/pre_deploy.sh | 80 ++++++++++++++ scripts/test.sh | 179 +++++++++++++++---------------- 17 files changed, 591 insertions(+), 189 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .pluginsync.yml create mode 100644 .sync.yml create mode 100644 scripts/common.sh create mode 100755 scripts/deps.sh create mode 100755 scripts/pre_deploy.sh diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..1f96a03 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,34 @@ + + +**Snap version** (use `snapctl -v`): + +**Environment**: +- **Cloud provider or hardware configuration**: +- **OS** (e.g. from /etc/os-release): +- **Kernel** (e.g. `uname -a`): +- **Relevant tools** (e.g. plugins used with Snap): +- **Others** (e.g. deploying with Ansible): + + +**What happened**: + + +**What you expected to happen**: + + +**Steps to reproduce it** (as minimally and precisely as possible): + +1. +2. +3. + + +**Anything else do we need to know** (e.g. issue happens only occasionally): diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..f7d30d0 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,21 @@ + +Fixes # + +Summary of changes: +- +- +- + +How to verify it: +- + +Testing done: +- + +A picture of a snapping turtle (not required but encouraged): +- diff --git a/.gitignore b/.gitignore index a946c69..acc50ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ +# File managed by pluginsync +# +# NOTE: please commit OS/Editor specific settings in your .gitignore_global +# .idea +# .DS_Store +# # Compiled Object files, Static and Dynamic libs (Shared Objects) *.o *.a @@ -21,17 +27,15 @@ _testmain.go *.exe *.test -.idea -tmp/ -*.tmp -scratch/ -build/ -*.swp +*.prof + +# Output of the go coverage tool +*.out profile.cov -gin-bin # we don't vendor godep _workspace **/Godeps/_workspace/** +vendor/ -# OSX stuff -.DS_Store +# ignore build artifacts +build/ diff --git a/.pluginsync.yml b/.pluginsync.yml new file mode 100644 index 0000000..139f660 --- /dev/null +++ b/.pluginsync.yml @@ -0,0 +1,17 @@ +pluginsync_config: '0.1.6' +managed_files: +- .github +- .github/ISSUE_TEMPLATE.md +- .github/PULL_REQUEST_TEMPLATE.md +- .gitignore +- .pluginsync.yml +- .travis.yml +- CONTRIBUTING.md +- LICENSE +- Makefile +- scripts +- scripts/build.sh +- scripts/common.sh +- scripts/deps.sh +- scripts/pre_deploy.sh +- scripts/test.sh diff --git a/.sync.yml b/.sync.yml new file mode 100644 index 0000000..2c915da --- /dev/null +++ b/.sync.yml @@ -0,0 +1,14 @@ +.travis.yml: + env: + global: + - ORG_PATH=/home/travis/gopath/src/github.com/intelsdi-x + - SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/${TRAVIS_REPO_SLUG} + matrix: + - TEST_TYPE=small + - TEST_TYPE=medium + deploy: + access_key_id: AKIAINMB43VSSPFZISAA + secret_access_key: + secure: M2MPahJfZeE1dAJcAB1mshyizhm3yJVa//4YwJz4aqNIIpT3hFyIVoIW1Ud2zXah3G5eARv8vq3WYxc//nLrQy1Baii532JkRRBkehoqhoj1+94lH/qy3qeOU1itsPYgmx8rwPLfjorIB/TdJnWJaJhEZxmuhyX0tVwM1N23WXlaDAZkYVEvT2dOhpBiQJRmbPzO9LBXd2KewRrs+NQNP1TEQjISqKHtA6wPlHRNkMe7BPrTzBJ8uciaiXsf0T+RdIsqX6W+h+nBUPv0S/V3VYR/TXvKSzkWcUf30lwLYT439/hFoRiNhMLcDDwl4bxHrU1RrlSS8JF1+2SuXltx1l7HU9wUk+meKEciHiHDBPTu1Ouy/9HfbAzyVZ5UXM/aeEB3j3lfjQezG2JzVvHap4wjtvMmifhYKPkHpB4C+nlMyvPwtncg11/9KNdABB5g/xvvh66YeD7RdW9KyOaaaipBC489Y72o1UZUZo7NYPRIhnJFJSxQoN1n9yYn6st9dfczhWmdnPFYac+iMUTkD7XezRH4D7aEMGMrvfdsGUB0WW8iaUn3csk0TDqnnzy75Uqj0Ddpthu6J60g+6AI0SMkK0b7XlsTALRq3eGO9SGHq23o57M0YzSMWgyjOgLeUhngUpfgDJM76jtmPJckAjFl7UJsGeFS91w0E1+fu0Y= + api_key: + secure: xBP1/9GdLtYHGUKXk/ac7t+NNodLo16fucPfqLoxC23Rw3a84vMluVZheWplSVbiTmuOVn777EfoK2ej0nTGL7+iNLc/z84pqDM5kW6Bo/EO5J9r54DpMcEznbkxsNyXtNdeX5EO7Ufs35+eU2cuvZ8YeIs3NNna6EBcB/JD7DlVKcLq4oKeMLafEs2vDSaFRDrgirtQhIU8525LCVSNwK3MiBPZnRMcTj6i0GLtz5BnVOBwgIElYhDawkIBnYmVxoBSMD7OyOfDt5zAq/1WJuoFj9zxjcTvCSKkgyno0ziDy3HrhV07QOy9gZ8nPUXPRI1u1cz0J3WLErvj0hmoBsOYbFGB6PpYwyjPZb0Pa8KrNqHYrVdgEu9VP6Y6y+YwzHOLqn8rFSaTCwlWlDN4Z9iso3jrbDfVdSKDb/GGF7MhWG981eresWB0jYpx3kJJ5mQtFTa0uD+udyYDyrvp5EP1MNxMCAkcg7s23E/517hcctFKCRRc5qt7ulDOD8djhYCQDTZlBkv5K6sWhILcyXMFsbKVLRc6pRYbdBN8P3BJ+6MkqxhQuu+ae7UQbAWtJxkPGWkaz3mYVEUUuu7Jne3wCs1lXbU0ORPuqSDhZckOuBpF4yd7WnBliqIrQ1TNc5K9eO3nLdWcF0gMLopOLDHw8MrI1EPGzlpIlx9Aink= diff --git a/.travis.yml b/.travis.yml index 611cdba..3387de6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,27 +1,70 @@ -sudo: required -services: -- docker +# File managed by pluginsync +sudo: false language: go go: -- 1.5.3 -- 1.6 -before_install: -- go get github.com/tools/godep -- if [ ! -d $SNAP_PLUGIN_SOURCE ]; then mkdir -p $HOME/gopath/src/github.com/intelsdi-x; ln -s $TRAVIS_BUILD_DIR $SNAP_PLUGIN_SOURCE; fi # CI for forks not from intelsdi-x +- 1.6.3 +- 1.7.1 env: global: - - SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/intelsdi-x/snap-plugin-publisher-kafka + - ORG_PATH=/home/travis/gopath/src/github.com/intelsdi-x + - SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/${TRAVIS_REPO_SLUG} matrix: - - TEST=unit - - TEST=integration - - TEST=integration + - TEST_TYPE=small + - TEST_TYPE=medium + - TEST_TYPE=build +matrix: + exclude: + - go: 1.6.3 + env: TEST_TYPE=build +before_install: +- "[[ -d $SNAP_PLUGIN_SOURCE ]] || mkdir -p $ORG_PATH && ln -s $TRAVIS_BUILD_DIR $SNAP_PLUGIN_SOURCE" install: -- export TMPDIR=$HOME/tmp -- mkdir -p $TMPDIR -- cd $SNAP_PLUGIN_SOURCE # change dir into source +- cd $SNAP_PLUGIN_SOURCE - make deps script: -- make check TEST=$TEST 2>&1 # Run test suite +- make check 2>&1 notifications: + email: false slack: secure: VkbZLIc2RH8yf3PtIAxUNPdAu3rQQ7yQx0GcK124JhbEnZGaHyK615V0rbG7HcVmYKGPdB0cXqZiLBDKGqGKb2zR1NepOe1nF03jxGSpPq8jIFeEXSJGEYGL34ScDzZZGuG6qwbjFcXiW5lqn6t8igzp7v2+URYBaZo5ktCS2xY= +before_deploy: +- "./scripts/pre_deploy.sh" +deploy: +- provider: s3 + access_key_id: AKIAINMB43VSSPFZISAA + secret_access_key: + secure: M2MPahJfZeE1dAJcAB1mshyizhm3yJVa//4YwJz4aqNIIpT3hFyIVoIW1Ud2zXah3G5eARv8vq3WYxc//nLrQy1Baii532JkRRBkehoqhoj1+94lH/qy3qeOU1itsPYgmx8rwPLfjorIB/TdJnWJaJhEZxmuhyX0tVwM1N23WXlaDAZkYVEvT2dOhpBiQJRmbPzO9LBXd2KewRrs+NQNP1TEQjISqKHtA6wPlHRNkMe7BPrTzBJ8uciaiXsf0T+RdIsqX6W+h+nBUPv0S/V3VYR/TXvKSzkWcUf30lwLYT439/hFoRiNhMLcDDwl4bxHrU1RrlSS8JF1+2SuXltx1l7HU9wUk+meKEciHiHDBPTu1Ouy/9HfbAzyVZ5UXM/aeEB3j3lfjQezG2JzVvHap4wjtvMmifhYKPkHpB4C+nlMyvPwtncg11/9KNdABB5g/xvvh66YeD7RdW9KyOaaaipBC489Y72o1UZUZo7NYPRIhnJFJSxQoN1n9yYn6st9dfczhWmdnPFYac+iMUTkD7XezRH4D7aEMGMrvfdsGUB0WW8iaUn3csk0TDqnnzy75Uqj0Ddpthu6J60g+6AI0SMkK0b7XlsTALRq3eGO9SGHq23o57M0YzSMWgyjOgLeUhngUpfgDJM76jtmPJckAjFl7UJsGeFS91w0E1+fu0Y= + bucket: snap.ci.snap-telemetry.io + region: us-west-2 + skip_cleanup: true + local-dir: s3 + upload-dir: plugins + acl: public_read + on: + repo: intelsdi-x/snap-plugin-publisher-kafka + branch: master + condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.1" +- provider: s3 + access_key_id: AKIAINMB43VSSPFZISAA + secret_access_key: + secure: M2MPahJfZeE1dAJcAB1mshyizhm3yJVa//4YwJz4aqNIIpT3hFyIVoIW1Ud2zXah3G5eARv8vq3WYxc//nLrQy1Baii532JkRRBkehoqhoj1+94lH/qy3qeOU1itsPYgmx8rwPLfjorIB/TdJnWJaJhEZxmuhyX0tVwM1N23WXlaDAZkYVEvT2dOhpBiQJRmbPzO9LBXd2KewRrs+NQNP1TEQjISqKHtA6wPlHRNkMe7BPrTzBJ8uciaiXsf0T+RdIsqX6W+h+nBUPv0S/V3VYR/TXvKSzkWcUf30lwLYT439/hFoRiNhMLcDDwl4bxHrU1RrlSS8JF1+2SuXltx1l7HU9wUk+meKEciHiHDBPTu1Ouy/9HfbAzyVZ5UXM/aeEB3j3lfjQezG2JzVvHap4wjtvMmifhYKPkHpB4C+nlMyvPwtncg11/9KNdABB5g/xvvh66YeD7RdW9KyOaaaipBC489Y72o1UZUZo7NYPRIhnJFJSxQoN1n9yYn6st9dfczhWmdnPFYac+iMUTkD7XezRH4D7aEMGMrvfdsGUB0WW8iaUn3csk0TDqnnzy75Uqj0Ddpthu6J60g+6AI0SMkK0b7XlsTALRq3eGO9SGHq23o57M0YzSMWgyjOgLeUhngUpfgDJM76jtmPJckAjFl7UJsGeFS91w0E1+fu0Y= + bucket: snap.ci.snap-telemetry.io + region: us-west-2 + skip_cleanup: true + local-dir: s3 + upload-dir: plugins + acl: public_read + on: + repo: intelsdi-x/snap-plugin-publisher-kafka + tags: true + condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.1" +- provider: releases + api_key: + secure: xBP1/9GdLtYHGUKXk/ac7t+NNodLo16fucPfqLoxC23Rw3a84vMluVZheWplSVbiTmuOVn777EfoK2ej0nTGL7+iNLc/z84pqDM5kW6Bo/EO5J9r54DpMcEznbkxsNyXtNdeX5EO7Ufs35+eU2cuvZ8YeIs3NNna6EBcB/JD7DlVKcLq4oKeMLafEs2vDSaFRDrgirtQhIU8525LCVSNwK3MiBPZnRMcTj6i0GLtz5BnVOBwgIElYhDawkIBnYmVxoBSMD7OyOfDt5zAq/1WJuoFj9zxjcTvCSKkgyno0ziDy3HrhV07QOy9gZ8nPUXPRI1u1cz0J3WLErvj0hmoBsOYbFGB6PpYwyjPZb0Pa8KrNqHYrVdgEu9VP6Y6y+YwzHOLqn8rFSaTCwlWlDN4Z9iso3jrbDfVdSKDb/GGF7MhWG981eresWB0jYpx3kJJ5mQtFTa0uD+udyYDyrvp5EP1MNxMCAkcg7s23E/517hcctFKCRRc5qt7ulDOD8djhYCQDTZlBkv5K6sWhILcyXMFsbKVLRc6pRYbdBN8P3BJ+6MkqxhQuu+ae7UQbAWtJxkPGWkaz3mYVEUUuu7Jne3wCs1lXbU0ORPuqSDhZckOuBpF4yd7WnBliqIrQ1TNc5K9eO3nLdWcF0gMLopOLDHw8MrI1EPGzlpIlx9Aink= + file: + - release/snap-plugin-publisher-kafka_linux_x86_64 + skip_cleanup: true + on: + repo: intelsdi-x/snap-plugin-publisher-kafka + tags: true + condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.1" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bdb0ecc..0f8eb69 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# snap publisher plugin - Kafka +# snap plugin publisher kafka 1. [Contributing Code](#contributing-code) 2. [Contributing Examples](#contributing-examples) @@ -10,36 +10,37 @@ This repository has dedicated developers from Intel working on updates. The most ## Contributing Code **_IMPORTANT_**: We encourage contributions to the project from the community. We ask that you keep the following guidelines in mind when planning your contribution. -* Whether your contribution is for a bug fix or a feature request, **create an [Issue](https://github.com/intelsdi-x/snap-plugin-publisher-kafka/issues)** and let us know what you are thinking -* **For bugs**, if you have already found a fix, feel free to submit a Pull Request referencing the Issue you created -* **For feature requests**, we want to improve upon the library incrementally which means small changes at a time. In order ensure your PR can be reviewed in a timely manner, please keep PRs small, e.g. <10 files and <500 lines changed. If you think this is unrealistic, then mention that within the issue and we can discuss it +* Whether your contribution is for a bug fix or a feature request, **create an [Issue](https://github.com/intelsdi-x/snap-plugin-publisher-kafka/issues)** and let us know what you are thinking. +* **For bugs**, if you have already found a fix, feel free to submit a Pull Request referencing the Issue you created. Include the `Fixes #` syntax to link it to the issue you're addressing. +* **For feature requests**, we want to improve upon the library incrementally which means small changes at a time. In order to ensure your PR can be reviewed in a timely manner, please keep PRs small, e.g. <10 files and <500 lines changed. If you think this is unrealistic, then mention that within the issue and we can discuss it. Once you're ready to contribute code back to this repo, start with these steps: -* Fork the appropriate sub-projects that are affected by your change -* Clone the fork to `$GOPATH/src/github.com/intelsdi-x/` - ``` - $ git clone https://github.com//.git - ``` -* Create a topic branch for your change and checkout that branch +* Fork the appropriate sub-projects that are affected by your change. +* Clone the fork to `$GOPATH/src/github.com/intelsdi-x/`: + + ``` +$ git clone https://github.com//.git + ``` +* Create a topic branch for your change and checkout that branch: + ``` $ git checkout -b some-topic-branch ``` -* Make your changes and run the test suite if one is provided (see below) -* Commit your changes and push them to your fork -* Open a pull request for the appropriate project -* Contributors will review your pull request, suggest changes, and merge it when it’s ready and/or offer feedback -* To report a bug or issue, please open a new issue against this repository +* Make your changes and run the test suite if one is provided. +* Commit your changes and push them to your fork. +* Open a pull request for the appropriate project. +* Contributors will review your pull request, suggest changes, and merge it when it’s ready and/or offer feedback. -If you have questions feel free to contact the [maintainers](https://github.com/intelsdi-x/snap/blob/master/README.md#maintainers). +If you have questions feel free to contact the [maintainers](https://github.com/intelsdi-x/snap/blob/master/README.md#maintainers) by tagging them: @intelsdi-x/plugin-maintainers. ## Contributing Examples The most immediately helpful way you can benefit this project is by cloning the repository, adding some further examples and submitting a pull request. -Have you written a blog post about how you use [snap](http://github.com/intelsdi-x/snap) and/or this plugin? Send it to us! +Have you written a blog post about how you use [Snap](http://github.com/intelsdi-x/snap) and/or this plugin? Send it to us [on Slack](http://slack.snap-telemetry.io)! ## Contribute Elsewhere -This repository is one of **many** plugins in **snap**, a powerful telemetry framework. See the full project at http://github.com/intelsdi-x/snap +This repository is one of **many** plugins in **Snap**, a powerful telemetry framework. See the full project at http://snap-telemetry.io ## Thank You -And **thank you!** Your contribution, through code and participation, is incredibly important to us. \ No newline at end of file +And **thank you!** Your contribution, through code and participation, is incredibly important to us. diff --git a/LICENSE b/LICENSE index 7a4a3ea..d645695 100644 --- a/LICENSE +++ b/LICENSE @@ -199,4 +199,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file + limitations under the License. diff --git a/Makefile b/Makefile index 58d1ab5..e9ea9a7 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,36 @@ -#http://www.apache.org/licenses/LICENSE-2.0.txt +# File managed by pluginsync +# http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Corporation +# Copyright 2015 Intel Corporation # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. default: $(MAKE) deps $(MAKE) all deps: - bash -c "godep restore" + bash -c "./scripts/deps.sh" test: - bash -c "./scripts/test.sh $(TEST)" + bash -c "./scripts/test.sh $(TEST_TYPE)" +test-legacy: + bash -c "./scripts/test.sh legacy" +test-small: + bash -c "./scripts/test.sh small" +test-medium: + bash -c "./scripts/test.sh medium" +test-large: + bash -c "./scripts/test.sh large" check: $(MAKE) test all: diff --git a/kafka/kafka_integration_test.go b/kafka/kafka_integration_test.go index 5ec33fb..dc56cf4 100644 --- a/kafka/kafka_integration_test.go +++ b/kafka/kafka_integration_test.go @@ -1,4 +1,4 @@ -// +build integration +// +build medium /* http://www.apache.org/licenses/LICENSE-2.0.txt diff --git a/kafka/kafka_test.go b/kafka/kafka_test.go index 52eb9d3..c397e09 100644 --- a/kafka/kafka_test.go +++ b/kafka/kafka_test.go @@ -1,4 +1,4 @@ -// +build unit +// +build small /* http://www.apache.org/licenses/LICENSE-2.0.txt diff --git a/main_test.go b/main_test.go index d3cd4b8..a73f73c 100644 --- a/main_test.go +++ b/main_test.go @@ -1,4 +1,4 @@ -// +build unit +// +build small /* http://www.apache.org/licenses/LICENSE-2.0.txt diff --git a/scripts/build.sh b/scripts/build.sh index 0a51846..58b6d41 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,44 +1,48 @@ -#!/bin/bash -e +#!/bin/bash +# File managed by pluginsync -#http://www.apache.org/licenses/LICENSE-2.0.txt +# http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Corporation +# Copyright 2016 Intel Corporation # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -GITVERSION=`git describe --always` -SOURCEDIR=$1 -BUILDDIR=$SOURCEDIR/build -PLUGIN=`echo $SOURCEDIR | grep -oh "snap-.*"` -ROOTFS=$BUILDDIR/rootfs -BUILDCMD='go build -a -ldflags "-w"' - -echo -echo "**** Snap Plugin Build ****" -echo - -# Disable CGO for builds -export CGO_ENABLED=0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e +set -u +set -o pipefail + +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" -# Clean build bin dir -rm -rf $ROOTFS/* +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" -# Make dir -mkdir -p $ROOTFS +plugin_name=${__proj_dir##*/} +build_dir="${__proj_dir}/build" +go_build=(go build -ldflags "-w") + +_info "project path: ${__proj_dir}" +_info "plugin name: ${plugin_name}" + +export CGO_ENABLED=0 -# Build plugin -echo "Source Dir = $SOURCEDIR" -echo "Building Snap Plugin: $PLUGIN" -$BUILDCMD -o $ROOTFS/$PLUGIN +# rebuild binaries: +_debug "removing: ${build_dir:?}/*" +rm -rf "${build_dir:?}/"* +_info "building plugin: ${plugin_name}" +export GOOS=linux +export GOARCH=amd64 +mkdir -p "${build_dir}/${GOOS}/x86_64" +"${go_build[@]}" -o "${build_dir}/${GOOS}/x86_64/${plugin_name}" . || exit 1 diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100644 index 0000000..b8e7413 --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,111 @@ +#!/bin/bash +# File managed by pluginsync + +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e +set -u +set -o pipefail + +LOG_LEVEL="${LOG_LEVEL:-6}" +NO_COLOR="${NO_COLOR:-}" + +trap_exitcode() { + exit $? +} + +trap trap_exitcode SIGINT + +_fmt () { + local color_debug="\x1b[35m" + local color_info="\x1b[32m" + local color_notice="\x1b[34m" + local color_warning="\x1b[33m" + local color_error="\x1b[31m" + local colorvar=color_$1 + + local color="${!colorvar:-$color_error}" + local color_reset="\x1b[0m" + if [ "${NO_COLOR}" = "true" ] || [[ "${TERM:-}" != "xterm"* ]] || [ -t 1 ]; then + # Don't use colors on pipes or non-recognized terminals + color=""; color_reset="" + fi + echo -e "$(date -u +"%Y-%m-%d %H:%M:%S UTC") ${color}$(printf "[%9s]" "${1}")${color_reset}"; +} + +_debug () { [ "${LOG_LEVEL}" -ge 7 ] && echo "$(_fmt debug) ${*}" 1>&2 || true; } +_info () { [ "${LOG_LEVEL}" -ge 6 ] && echo "$(_fmt info) ${*}" 1>&2 || true; } +_notice () { [ "${LOG_LEVEL}" -ge 5 ] && echo "$(_fmt notice) ${*}" 1>&2 || true; } +_warning () { [ "${LOG_LEVEL}" -ge 4 ] && echo "$(_fmt warning) ${*}" 1>&2 || true; } +_error () { [ "${LOG_LEVEL}" -ge 3 ] && echo "$(_fmt error) ${*}" 1>&2 || true; exit 1; } + +_test_dirs() { + local test_dirs=$(find . -type f -name '*.go' -not -path "./.*" -not -path "*/_*" -not -path "./Godeps/*" -not -path "./vendor/*" -print0 | xargs -0 -n1 dirname| sort -u) + _debug "go code directories ${test_dirs}" + echo "${test_dirs}" +} + +_go_get() { + local _url=$1 + local _util + + _util=$(basename "${_url}") + + type -p "${_util}" > /dev/null || go get "${_url}" && _debug "go get ${_util} ${_url}" +} + +_goimports() { + _go_get golang.org/x/tools/cmd/goimports + test -z "$(goimports -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") | tee /dev/stderr)" +} + +_golint() { + _go_get github.com/golang/lint/golint + golint ./... +} + +_go_vet() { + go vet $(_test_dirs) +} + +_go_race() { + go test -race ./... +} + +_go_test() { + _info "running test type: ${TEST_TYPE}" + # Standard go tooling behavior is to ignore dirs with leading underscors + for dir in $(_test_dirs); + do + if [[ -z ${go_cover+x} ]]; then + _debug "running go test with cover in ${dir}" + go test -v --tags="${TEST_TYPE}" -covermode=count -coverprofile="${dir}/profile.tmp" "${dir}" + if [ -f "${dir}/profile.tmp" ]; then + tail -n +2 "${dir}/profile.tmp" >> profile.cov + rm "${dir}/profile.tmp" + fi + else + _debug "running go test without cover in ${dir}" + go test -v --tags="${TEST_TYPE}" "${dir}" + fi + done +} + +_go_cover() { + go tool cover -func profile.cov +} diff --git a/scripts/deps.sh b/scripts/deps.sh new file mode 100755 index 0000000..1657a7f --- /dev/null +++ b/scripts/deps.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# File managed by pluginsync + +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e +set -u +set -o pipefail + +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" + +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" + +detect_go_dep() { + [[ -f "${__proj_dir}/Godeps/Godeps.json" ]] && _dep='godep' + [[ -f "${__proj_dir}/glide.yaml" ]] && _dep='glide' + [[ -f "${__proj_dir}/vendor/vendor.json" ]] && _dep='govendor' + _info "golang dependency tool: ${_dep}" + echo "${_dep}" +} + +install_go_dep() { + local _dep=${_dep:=$(_detect_dep)} + _info "ensuring ${_dep} is available" + case $_dep in + godep) + _go_get github.com/tools/godep + ;; + glide) + _go_get github.com/Masterminds/glide + ;; + govendor) + _go_get github.com/kardianos/govendor + ;; + esac +} + +restore_go_dep() { + local _dep=${_dep:=$(_detect_dep)} + _info "restoring dependency with ${_dep}" + case $_dep in + godep) + (cd "${__proj_dir}" && godep restore) + ;; + glide) + (cd "${__proj_dir}" && glide install) + ;; + govendor) + (cd "${__proj_dir}" && govendor sync) + ;; + esac +} + +_dep=$(detect_go_dep) +install_go_dep +restore_go_dep diff --git a/scripts/pre_deploy.sh b/scripts/pre_deploy.sh new file mode 100755 index 0000000..9a57824 --- /dev/null +++ b/scripts/pre_deploy.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# File managed by pluginsync + +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# +# Copyright 2016 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e +set -u +set -o pipefail + +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" + +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" + +build_path="${__proj_dir}/build" +_info "build_path: ${build_path}" +_debug "$(find "${build_path}")" + +plugin_name="${__proj_dir##*/}" +git_sha=$(git log --pretty=format:"%H" -1) +s3_path="${__proj_dir}/s3/${plugin_name}" + +set +u +if [ -z "$TRAVIS_TAG" ]; then + set -u + git_path="${s3_path}/${git_sha}" + latest_path="${s3_path}/latest_build" + mkdir -p "${git_path}" + mkdir -p "${latest_path}" + + _info "copying plugin binaries to ${git_path}" + cp -rp "${build_path}/"* "${git_path}" + _info "copying plugin binaries to ${latest_path}" + cp -rp "${build_path}/"* "${latest_path}" +else + set -u + tag_path="${s3_path}/${TRAVIS_TAG}" + latest_path="${s3_path}/latest" + mkdir -p "${tag_path}" + mkdir -p "${latest_path}" + + _info "copying plugin binaries to ${tag_path}" + cp -rp "${build_path}/"* "${tag_path}" + _info "copying plugin binaries to ${latest_path}" + cp -rp "${build_path}/"* "${latest_path}" +fi + +release_path="${SNAP_PATH:-"${__proj_dir}/release"}" +mkdir -p "${release_path}" + +_info "moving plugin binaries to ${release_path}" + +for file in "${build_path}"/**/*/snap-plugin-* ; do + filename="${file##*/}" + parent="${file%/*}" + arch="${parent##*/}" + parent="${parent%/*}" + os="${parent##*/}" + cp "${file}" "${release_path}/${filename}_${os}_${arch}" +done + +_debug "$(find "${build_path}")" +_debug "$(find "${s3_path}")" +_debug "$(find "${release_path}")" diff --git a/scripts/test.sh b/scripts/test.sh index e2a72cb..a63d7f0 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,109 +1,100 @@ -#!/bin/bash -e +#!/bin/bash +# File managed by pluginsync -#http://www.apache.org/licenses/LICENSE-2.0.txt +# http://www.apache.org/licenses/LICENSE-2.0.txt # # -#Copyright 2015 Intel Corporation +# Copyright 2016 Intel Corporation # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. -# The script does automatic checking on a Go package and its sub-packages, including: -# 1. gofmt (http://golang.org/cmd/gofmt/) -# 2. goimports (https://github.com/bradfitz/goimports) -# 3. golint (https://github.com/golang/lint) -# 4. go vet (http://golang.org/cmd/vet) -# 5. race detector (http://blog.golang.org/race-detector) -# 6. test coverage (http://blog.golang.org/cover) +# Support travis.ci environment matrix: +TEST_TYPE="${TEST_TYPE:-$1}" +UNIT_TEST="${UNIT_TEST:-"gofmt goimports go_vet go_test go_cover"}" +TEST_K8S="${TEST_K8S:-0}" -# Capture what test we should run -TEST_SUITE=$1 +set -e +set -u +set -o pipefail -if [[ $TEST_SUITE == "unit" ]]; then - go get github.com/axw/gocov/gocov - go get github.com/mattn/goveralls - go get -u github.com/golang/lint/golint - go get golang.org/x/tools/cmd/goimports - go get github.com/smartystreets/goconvey/convey - go get golang.org/x/tools/cmd/cover - - COVERALLS_TOKEN=t47LG6BQsfLwb9WxB56hXUezvwpED6D11 - TEST_DIRS="main.go kafka/" - VET_DIRS=". ./kafka/..." +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" - set -e +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" - # Automatic checks - echo "gofmt" - test -z "$(gofmt -l -d $TEST_DIRS | tee /dev/stderr)" +_debug "script directory ${__dir}" +_debug "project directory ${__proj_dir}" - echo "goimports" - test -z "$(goimports -l -d $TEST_DIRS | tee /dev/stderr)" +[[ "$TEST_TYPE" =~ ^(small|medium|large|legacy|build)$ ]] || _error "invalid TEST_TYPE (value must be 'small', 'medium', 'large', 'legacy', or 'build' recieved:${TEST_TYPE}" - # Useful but should not fail on link per: https://github.com/golang/lint - # "The suggestions made by golint are exactly that: suggestions. Golint is not perfect, - # and has both false positives and false negatives. Do not treat its output as a gold standard. - # We will not be adding pragmas or other knobs to suppress specific warnings, so do not expect - # or require code to be completely "lint-free". In short, this tool is not, and will never be, - # trustworthy enough for its suggestions to be enforced automatically, for example as part of - # a build process" - # echo "golint" - # golint ./... +_gofmt() { + test -z "$(gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") | tee /dev/stderr)" +} - echo "go vet" - go vet $VET_DIRS - # go test -race ./... - Lets disable for now - - # Run test coverage on each subdirectories and merge the coverage profile. - echo "mode: count" > profile.cov - - # Standard go tooling behavior is to ignore dirs with leading underscors - for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -not -path './examples/*' -not -path './scripts/*' -not -path './build/*' -not -path './Godeps/*' -type d); - do - if ls $dir/*.go &> /dev/null; then - go test --tags=unit -covermode=count -coverprofile=$dir/profile.tmp $dir - if [ -f $dir/profile.tmp ] - then - cat $dir/profile.tmp | tail -n +2 >> profile.cov - rm $dir/profile.tmp - fi - fi - done - - go tool cover -func profile.cov - - # Disabled Coveralls.io for now - # To submit the test coverage result to coveralls.io, - # use goveralls (https://github.com/mattn/goveralls) - # goveralls -coverprofile=profile.cov -service=travis-ci -repotoken t47LG6BQsfLwb9WxB56hXUezvwpED6D11 - # - # If running inside Travis we update coveralls. We don't want his happening on Macs - # if [ "$TRAVIS" == "true" ] - # then - # n=1 - # until [ $n -ge 6 ] - # do - # echo "posting to coveralls attempt $n of 5" - # goveralls -v -coverprofile=profile.cov -service travis.ci -repotoken $COVERALLS_TOKEN && break - # n=$[$n+1] - # sleep 30 - # done - # fi -elif [[ $TEST_SUITE == "integration" ]]; then - cd scripts/docker/kafka; docker build -t intelsdi-x/kafka:latest . - cd $SNAP_PLUGIN_SOURCE - cd scripts/docker/zookeeper; docker build -t intelsdi-x/zookeeper:latest . - cd $SNAP_PLUGIN_SOURCE - docker run -d --net=host intelsdi-x/zookeeper:latest - docker run -d --net=host intelsdi-x/kafka:latest - SNAP_TEST_KAFKA="127.0.0.1:9092" go test -v --tags=integration ./... +test_unit() { + # The script does automatic checking on a Go package and its sub-packages, including: + # 1. gofmt (http://golang.org/cmd/gofmt/) + # 2. goimports (https://github.com/bradfitz/goimports) + # 3. golint (https://github.com/golang/lint) + # 4. go vet (http://golang.org/cmd/vet) + # 5. race detector (http://blog.golang.org/race-detector) + # 6. go test + # 7. test coverage (http://blog.golang.org/cover) + local go_tests + go_tests=(gofmt goimports golint go_vet go_race go_test go_cover) + + _debug "available unit tests: ${go_tests[*]}" + _debug "user specified tests: ${UNIT_TEST}" + + ((n_elements=${#go_tests[@]}, max=n_elements - 1)) + + for ((i = 0; i <= max; i++)); do + if [[ "${UNIT_TEST}" =~ (^| )"${go_tests[i]}"( |$) ]]; then + _info "running ${go_tests[i]}" + _"${go_tests[i]}" + else + _debug "skipping ${go_tests[i]}" + fi + done +} + +if [[ $TEST_TYPE == "legacy" ]]; then + echo "mode: count" > profile.cov + export TEST_TYPE="unit" + test_unit +elif [[ $TEST_TYPE == "small" ]]; then + if [[ -f "${__dir}/small.sh" ]]; then + . "${__dir}/small.sh" + else + echo "mode: count" > profile.cov + test_unit + fi +elif [[ $TEST_TYPE == "medium" ]]; then + if [[ -f "${__dir}/medium.sh" ]]; then + . "${__dir}/medium.sh" + else + UNIT_TEST="go_test" + test_unit + fi +elif [[ $TEST_TYPE == "large" ]]; then + if [[ "${TEST_K8S}" != "0" && -f "$__dir/large_k8s.sh" ]]; then + . "${__dir}/large_k8s.sh" + elif [[ -f "${__dir}/large_compose.sh" ]]; then + . "${__dir}/large_compose.sh" + else + _info "No large tests." + fi +elif [[ $TEST_TYPE == "build" ]]; then + "${__dir}/build.sh" fi