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 b81e2f9..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 \ No newline at end of file +# ignore build artifacts +build/ diff --git a/.pluginsync.yml b/.pluginsync.yml new file mode 100644 index 0000000..3bbec5c --- /dev/null +++ b/.pluginsync.yml @@ -0,0 +1,18 @@ +# File managed by pluginsync +pluginsync_config: '0.1.8' +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 index 009b5cf..c13c576 100644 --- a/.sync.yml +++ b/.sync.yml @@ -6,6 +6,9 @@ - GOOS: darwin GOARCH: amd64 .travis.yml: + sudo: true + services: + - docker env: global: - ORG_PATH=/home/travis/gopath/src/github.com/intelsdi-x diff --git a/.travis.yml b/.travis.yml index 3d732c8..81f31a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,27 +1,73 @@ -sudo: required -services: -- docker +# File managed by pluginsync +sudo: true language: go go: -- 1.5.4 -- 1.6.2 -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.3 +services: + - docker env: global: - - SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/intelsdi-x/snap-plugin-publisher-etcd + - ORG_PATH=/home/travis/gopath/src/github.com/intelsdi-x + - SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/${TRAVIS_REPO_SLUG} matrix: - - TEST=small - - TEST=medium -# - TEST=large + - 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= \ No newline at end of file + secure: VkbZLIc2RH8yf3PtIAxUNPdAu3rQQ7yQx0GcK124JhbEnZGaHyK615V0rbG7HcVmYKGPdB0cXqZiLBDKGqGKb2zR1NepOe1nF03jxGSpPq8jIFeEXSJGEYGL34ScDzZZGuG6qwbjFcXiW5lqn6t8igzp7v2+URYBaZo5ktCS2xY= +before_deploy: +- "./scripts/pre_deploy.sh" +deploy: +- provider: s3 + access_key_id: AKIAINMB43VSSPFZISAA + secret_access_key: + secure: NSjryYJMqALgAGAnyvusH+eiiPS37DR2BGfVzsieOVv6mDGf6aSe59zKkxcfvEOdypt3TgRuhxsPyS+/7mOEUDcBh6VtyR+CIXtfVcJ/ns6CGDkgyyRt1tcU/1BtTzS2gcNNN5zMkG5GGHdZT3ZtBbEWXepuEleD423dttL5zEA90QF+pgvoWrI1hprnBCBUAVeb6DGiv2/NbTOrwh4NapBMgkOzD9hpMXD9MXKZnELnOhajGqeI8fCpMoo+qnktiUsSevVp3siSUzJvobGUXJsUpIZRa5A5kQ8vbsrXvTWSecvsWRFmgWLi9Yr9FhGS5VIrvoSQe4p2EZY3+OtGMcfuJ0tEQe3tU6gq1Unz7tE+aKScl3Cck9Ds2PfZk0AQjM4RrgLAexG+EAmLidH+NftQCE6+y8ha0usmD9iuNj/NZaakP459/OjxslYKXaf8zOenH3JLtMCbtX3YBZi3b24AqXha0T0gFGzYjni6ek4hSw6YO/18dLhZMomoVqo+RFbx+HBQ+cBNgLUiWKYGcZOQAikBt2AxeT/VfVYkMlULQuKjgLNUIbQ7egKRUeBfT0zx/1yP2w6gGCJRrz27y/NzVK3pI8AqDNw+CtpVpIseGjH4PBt7CXwM/yqnhw15kWQLM2NIplGgf+Kyq2jyQkgiBNI7iQPwfDZ7EvNRIbY= + 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-etcd + branch: master + condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.3" +- provider: s3 + access_key_id: AKIAINMB43VSSPFZISAA + secret_access_key: + secure: NSjryYJMqALgAGAnyvusH+eiiPS37DR2BGfVzsieOVv6mDGf6aSe59zKkxcfvEOdypt3TgRuhxsPyS+/7mOEUDcBh6VtyR+CIXtfVcJ/ns6CGDkgyyRt1tcU/1BtTzS2gcNNN5zMkG5GGHdZT3ZtBbEWXepuEleD423dttL5zEA90QF+pgvoWrI1hprnBCBUAVeb6DGiv2/NbTOrwh4NapBMgkOzD9hpMXD9MXKZnELnOhajGqeI8fCpMoo+qnktiUsSevVp3siSUzJvobGUXJsUpIZRa5A5kQ8vbsrXvTWSecvsWRFmgWLi9Yr9FhGS5VIrvoSQe4p2EZY3+OtGMcfuJ0tEQe3tU6gq1Unz7tE+aKScl3Cck9Ds2PfZk0AQjM4RrgLAexG+EAmLidH+NftQCE6+y8ha0usmD9iuNj/NZaakP459/OjxslYKXaf8zOenH3JLtMCbtX3YBZi3b24AqXha0T0gFGzYjni6ek4hSw6YO/18dLhZMomoVqo+RFbx+HBQ+cBNgLUiWKYGcZOQAikBt2AxeT/VfVYkMlULQuKjgLNUIbQ7egKRUeBfT0zx/1yP2w6gGCJRrz27y/NzVK3pI8AqDNw+CtpVpIseGjH4PBt7CXwM/yqnhw15kWQLM2NIplGgf+Kyq2jyQkgiBNI7iQPwfDZ7EvNRIbY= + 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-etcd + tags: true + condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.3" +- provider: releases + api_key: + secure: BEm3q1po7Dt5MHKek73U2SjKTxgYH8OG5YDd3q7IvqABuoZtpG1fU45121H9mdW81Uw6o7KySPy/eyywGsc6WKwmZcGvX4bo/AeXkDFDwwPvKCbDaf2MspqlepvQaUPAk3qEYaQ35WrhCUBw1yMb4wjfldjpcg2EdYz0AJNgJhiBk7OBrJsIAk5Rhlufk7W4gwGEPsnkohp8fCjVpurd8oX1cmNSnLJSQHacT37Rf3SwJNZNtIkACfFzI8XILVMrxu6fDBhQi4LvnZzaC4LvPcQuYvH61Cu5gy63s5kiWmaYxAISA1Qs2aUtp/tTz6Y6IAcUix8RSRCv1KQ9H0kO78NN1o3N8SxbiM3KfXjM+pomUvdECNQhWtaTohm7nJCD3e9budN8e0VQewcu744Hv0fGUwPVnWcrRdSvlvju5xgqps1iwQ4cDaQRi9zfeqOsfwocTK5oUDQolGhJvHogA14upnfo11PjTK1d4YCdCPAUbPLGJx9MGLuzaNfVscVQSL9+SdOH5RM6TTbta+uchpTUe9DgxkyMRoe5Wm2O4T+ag9r8+GjbObt1wBF+6rhSR7To4w70sbUxJowZIVRsDT2/Nd5jWKwYYP/mbMzfGoX8AxzmnD88f5F0z8IdBF9wcFUXu6atoahHaFZPXRUToO9h4HC2AnuoJK8406nkkoc= + file: + - release/snap-plugin-publisher-etcd_linux_x86_64 + - release/snap-plugin-publisher-etcd_darwin_x86_64 + skip_cleanup: true + on: + repo: intelsdi-x/snap-plugin-publisher-etcd + tags: true + condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.3" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 45fd3d5..94678ab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,45 +1,57 @@ -# snap publisher plugin - etcd +# snap plugin publisher etcd 1. [Contributing Code](#contributing-code) 2. [Contributing Examples](#contributing-examples) 3. [Contribute Elsewhere](#contribute-elsewhere) -4. [Thank You](#thank-you) +4. [Reporting Security Issues](#reporting-security-issues) +5. [Thank You](#thank-you) -This repository has dedicated developers from Intel working on updates. The most helpful way to contribute is by reporting your experience through issues. Issues may not be updated while we review internally, but they're still incredibly appreciated. +This repository is primarily **community supported**. We both appreciate and need your contribution to keep it stable. Thank you for being part of the community! We love you for it. ## 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-etcd/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-etcd/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/`: + + ``` +$ cd "${GOPATH}/src/github.com/intelsdi-x/" +$ git clone https://github.com/intelsdi-x/snap-plugin-publisher-etcd.git + ``` +* Create a topic branch for your change and checkout that branch: + ``` - $ git checkout -b some-topic-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). ## 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 + + +## Reporting Security Issues + +The Snap team take security very seriously. If you have any issue regarding security, +please notify us by sending an email to snap-security@intel.com and not by creating a GitHub issue. +We will follow up with you promptly with more information and a plan for remediation. +While we are not offering a security bounty, we would love to send some Snap swag your way along with our +deepest gratitude for your assistance in making Snap a more secure product. ## Thank You And **thank you!** Your contribution, through code and participation, is incredibly important to us. diff --git a/LICENSE b/LICENSE index 7a4a3ea..f433b1a 100644 --- a/LICENSE +++ b/LICENSE @@ -175,28 +175,3 @@ of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. \ No newline at end of file diff --git a/Makefile b/Makefile index 2db0942..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 2016 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/scripts/build.sh b/scripts/build.sh index 2ee9b58..dd1f612 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,27 +1,52 @@ -#!/bin/bash -e +#!/bin/bash +# File managed by pluginsync -GITVERSION=`git describe --always` -SOURCEDIR=$1 -BUILDDIR=$SOURCEDIR/build -PLUGIN=`echo $SOURCEDIR | grep -oh "snap-.*"` -ROOTFS=$BUILDDIR/rootfs -BUILDCMD='go build -a -ldflags "-w"' +# 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. -echo -echo "**** Snap Plugin Build ****" -echo +set -e +set -u +set -o pipefail -# Disable CGO for builds -export CGO_ENABLED=0 +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" + +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" -# Clean build bin dir -rm -rf $ROOTFS/* +plugin_name=${__proj_dir##*/} +build_dir="${__proj_dir}/build" +go_build=(go build -ldflags "-w") -# Make dir -mkdir -p $ROOTFS +_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 +export GOOS=darwin +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/medium.sh b/scripts/medium.sh new file mode 100644 index 0000000..c6c6da6 --- /dev/null +++ b/scripts/medium.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e +set -u +set -o pipefail + +SNAP_ETCD_PUBLIC_IP="127.0.0.1" +SNAP_ETCD_PORT="5001" + +docker_id=$(docker run -d -p 8001:8001 -p ${SNAP_ETCD_PORT}:${SNAP_ETCD_PORT} --name=etcd quay.io/coreos/etcd:v0.4.6 -peer-addr ${SNAP_ETCD_PUBLIC_IP}:8001 -addr ${SNAP_ETCD_PUBLIC_IP}:${SNAP_ETCD_PORT}) + +sleep 5 +export SNAP_ETCD_HOST="http://$SNAP_ETCD_PUBLIC_IP:$SNAP_ETCD_PORT" + +UNIT_TEST="go_test" +test_unit + +_debug "stopping docker image: ${docker_id}" +docker stop "${docker_id}" > /dev/null +_debug "removing docker image: ${docker_id}" +docker rm "${docker_id}" > /dev/null 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 2876546..b73ac2b 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,99 +1,101 @@ -#!/bin/bash -e -# 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) +#!/bin/bash +# File managed by pluginsync -# Capture what test we should run -TEST_SUITE=$1 +# 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. -if [[ $TEST_SUITE == "small" ]]; 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 github.com/smartystreets/assertions - go get golang.org/x/tools/cmd/cover - - COVERALLS_TOKEN=t47LG6BQsfLwb9WxB56hXUezvwpED6D11 - TEST_DIRS="main.go etcd/" - VET_DIRS=". ./etcd/..." +# 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}" - set -e +set -e +set -u +set -o pipefail - # Automatic checks - echo "gofmt" - test -z "$(gofmt -l -d $TEST_DIRS | tee /dev/stderr)" +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__proj_dir="$(dirname "$__dir")" - echo "goimports" - test -z "$(goimports -l -d $TEST_DIRS | tee /dev/stderr)" +# shellcheck source=scripts/common.sh +. "${__dir}/common.sh" - # 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 ./... +_debug "script directory ${__dir}" +_debug "project directory ${__proj_dir}" - 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=small -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 == "medium" ]]; then - cd $SNAP_PLUGIN_SOURCE - if [[ $SNAP_PLUGIN_SOURCE == "" ]]; then - echo "env var SNAP_PLUGIN_SOURCE not set, should be location of snap-plugin-publisher-etcd" - exit 1 - fi - export SNAP_ETCD_PUBLIC_IP="127.0.0.1" - export SNAP_ETCD_PORT="5001" - echo "command: docker run -d -p 8001:8001 -p 5001:5001 --name=etcd quay.io/coreos/etcd:v0.4.6 -peer-addr ${SNAP_ETCD_PUBLIC_IP}:8001 -addr ${SNAP_ETCD_PUBLIC_IP}:$SNAP_ETCD_PORT" - docker run -d -p 8001:8001 -p $SNAP_ETCD_PORT:$SNAP_ETCD_PORT --name=etcd quay.io/coreos/etcd:v0.4.6 -peer-addr ${SNAP_ETCD_PUBLIC_IP}:8001 -addr ${SNAP_ETCD_PUBLIC_IP}:$SNAP_ETCD_PORT - sleep 5 - echo "command: SNAP_ETCD_HOST=\"$SNAP_ETCD_PUBLIC_IP:$SNAP_ETCD_PORT\" go test -v --tags=medium ./..." - # if you're using docker-machine, 127.0.0.1 needs to be replaced with your docker-machine ip - SNAP_ETCD_HOST="http://$SNAP_ETCD_PUBLIC_IP:$SNAP_ETCD_PORT" go test -v --tags=medium ./... - docker kill etcd && docker rm etcd -fi \ No newline at end of file +[[ "$TEST_TYPE" =~ ^(small|medium|large|legacy|build)$ ]] || _error "invalid TEST_TYPE (value must be 'small', 'medium', 'large', 'legacy', or 'build' recieved:${TEST_TYPE}" + +_gofmt() { + test -z "$(gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") | tee /dev/stderr)" +} + +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 go_cover" + echo "mode: count" > profile.cov + 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