diff --git a/.travis.yml b/.travis.yml index 893965a66..df8111f66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,12 +9,18 @@ before_install: - if [ ! -d $SNAP_SOURCE ]; then mkdir -p $HOME/gopath/src/github.com/intelsdi-x; ln -s $TRAVIS_BUILD_DIR $SNAP_SOURCE; fi # CI for forks not from intelsdi-x env: global: - - SNAP_SOURCE=/home/travis/gopath/src/github.com/intelsdi-x/snap - - GO15VENDOREXPERIMENT=1 + - SNAP_SOURCE=/home/travis/gopath/src/github.com/intelsdi-x/snap + - GO15VENDOREXPERIMENT=1 + - secure: kSsbBOCrSRyWx6yhSwhTYIWRId4WNMkO9OhMphBPXb5kDEd+asanCybuBKdOSgzuqrzBbQsuQjzhw+iZwdiPoQInZyDxeVl7frroNvg94n+q4tpPQOPzJ6gN15MCHSq3m1lCk3XVrESGEBTqmdmUtZhY+RfxSXuq1xkDMesst2f+gONd5Bl+QFiboRqvjUXwGC+e3JnZI2LxWjYZspNh2ZS6c5mvbhufDPV5MD6+jlZppzHcNkHAtHOt3KNoTFai8X0U8MYiEax3mSIAHjYzQQayS5al54MfgcVo1r4gWmPOybkyb5+/DyNSUT4KY+XVIrxV68fSOuCnLxLEaQZ9W0c0WuetmUU1fOT8Iy9q0qLQq9IknXNnfsCEGdwB2XKfyNvKEtkWbi6b6idrok5d1y7b8Qt5olveczGx0cRbpXQ0BTZ/bnQMhL9tpUeRltbDey6dsSsTJjnatqH7CdeEAV0ZeY+LjBgTukps4TlEHTn0ddEzhR1rrRsQ3OB0kT59Y3BCJ4kstzpMsTFWKUTMr/75UR1g5XETfOt0BtXkM3I343AIjJt+MQg/bW26ZOTbqPbqVO3Z7eDf0MaRC4Mugm809ekMZARTLAmq4FMIutDsTTT741IgWZQrMDI37WUztDUE1WFDzcTkAk99yc6gBjZ+0dZd1Qc7RQR0RMBi4M4= matrix: - - SNAP_TEST_TYPE=legacy - - SNAP_TEST_TYPE=small - - SNAP_TEST_TYPE=medium + - SNAP_TEST_TYPE=legacy + - SNAP_TEST_TYPE=small + - SNAP_TEST_TYPE=medium + - SNAP_TEST_TYPE=build +matrix: + exclude: + - go: 1.5.4 + env: SNAP_TEST_TYPE=build install: - export TMPDIR=$HOME/tmp - mkdir -p $TMPDIR @@ -23,5 +29,25 @@ install: script: - make check 2>&1 # Run test suite notifications: + email: false slack: secure: VkbZLIc2RH8yf3PtIAxUNPdAu3rQQ7yQx0GcK124JhbEnZGaHyK615V0rbG7HcVmYKGPdB0cXqZiLBDKGqGKb2zR1NepOe1nF03jxGSpPq8jIFeEXSJGEYGL34ScDzZZGuG6qwbjFcXiW5lqn6t8igzp7v2+URYBaZo5ktCS2xY= +before_deploy: +- "./scripts/pre_deploy.sh" +deploy: + provider: s3 + access_key_id: AKIAINMB43VSSPFZISAA + secret_access_key: + secure: vEWq7ImahLeJ3n+RsazhuCuzRV5b8biZRy3HpqJlNasSAqUPvugGD8TrhaK/3fru931flVLsLdFJObG3cIHmJrJDaLS+Zv7707+yAPHOLrATedO530P89CPlJpDmbPNuqU2e+6NfCu7DZQdceXF5hSQRIVeVloHcsnoo7XG4VFHPrIOCB+JbWnVquH7wtOn3h0RcOtzQQgdehqKB2c6Yi68wFkgKIEyIQHL63m28biMn1nMH1i0lYCN4rk8kxhPWar6e86JPeDvyhUbXixokXsy0H3J819yWwZIejb0UCucJmXMG+m9jMNXwh1DoC4+HMvFnzUdB61G6nYCPFz0GRyw363sXCg2rBizkTyhVF1Bd039gWgGFm6rb5cUKTlvNuvWe+x1E0lX8G3pPa8ZFX7/i2P9GPJCt8LHnZnskIHv0Yic/+6Kt89veS0YWgQRUuSGDnhaMuJHeyZppiFr4ALUi032/qTCuTj6z/v7UMpDSkPGpCh4505mMVsx11lT7zoZnK5/1Qxfd8ysJgfPKcptJXMfYjX/8QFT9EPok4KMx6E2k8hS82rT5i1pjjE9Kw18xqJNlWOUatfX5jzzoCYxuj/d99Zu4gD0n7UUN5rcNY7xrrBwYPmPaIKOTp+k+RdwlRIhxaXr2j5GFCaSPrtDobULioJIHfdbxVjrThQY= + bucket: intelsdi-x + region: us-west-2 + skip_cleanup: true + local-dir: build + upload-dir: snap + acl: public_read + on: + repo: intelsdi-x/snap + branch: master + condition: $SNAP_TEST_TYPE = build && $TRAVIS_GO_VERSION = "1.6.2" +after_deploy: +- "./scripts/post_deploy.sh" diff --git a/scripts/common.sh b/scripts/common.sh index 501d4a6c3..75c0c9248 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -45,7 +45,7 @@ _notice () { [ "${LOG_LEVEL}" -ge 5 ] && echo "$(_fmt notice) ${*}" 1>&2 || tru _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=$(find . -type f -name '*.go' -not -path "./.*" -not -path "*/_*" -not -path "./Godeps/*" -not -path "./vendor/*" -print0 | xargs -0 -n1 dirname| sort -u) +test_dirs=$(find . -type f -name '*.go' -not -path "./.*" -not -path "*/_*" -not -path "./Godeps/*" -not -path "./vendor/*" -not -path "./scripts/*" -print0 | xargs -0 -n1 dirname | sort -u) _debug "go code directories: ${test_dirs}" diff --git a/scripts/post_deploy.sh b/scripts/post_deploy.sh new file mode 100755 index 000000000..0e12c9df7 --- /dev/null +++ b/scripts/post_deploy.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +#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" + +git_sha=$(git log --pretty=format:"%H" -1) +SNAP_BUILD_URL="https://s3-us-west-2.amazonaws.com/intelsdi-x/snap/${git_sha}" +export SNAP_BUILD_URL + +_info "updating package URL: ${SNAP_BUILD_URL}" +go get github.com/dnsimple/dnsimple-go/dnsimple +go run "${__proj_dir}/scripts/update_dns.go" diff --git a/scripts/pre_deploy.sh b/scripts/pre_deploy.sh new file mode 100755 index 000000000..d3098b284 --- /dev/null +++ b/scripts/pre_deploy.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +#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="${SNAP_PATH:-"${__proj_dir}/build"}" +git_sha=$(git log --pretty=format:"%H" -1) +git_path="${build_path}/${git_sha}" + +mkdir -p "${git_path}" +_info "copying snap binaries to ${git_path}" +mv "${build_path}/bin/"* "${git_path}" +mv "${build_path}/plugin/"* "${git_path}" diff --git a/scripts/test.sh b/scripts/test.sh index 34261df9a..33f1742e7 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -31,8 +31,6 @@ __proj_dir="$(dirname "$__dir")" SNAP_PATH="${SNAP_PATH:-"${__proj_dir}/build"}" export SNAP_PATH -test_dirs=$(find . -type f -name '*.go' -not -path "./.*" -not -path "*/_*" -not -path "./Godeps/*" -not -path "./vendor/*" -print0 | xargs -0 -n1 dirname| sort -u) -export test_dirs # shellcheck source=scripts/common.sh . "${__dir}/common.sh" @@ -40,7 +38,12 @@ export test_dirs _debug "script directory ${__dir}" _debug "project directory ${__proj_dir}" -[[ "$SNAP_TEST_TYPE" =~ ^(small|medium|large|legacy)$ ]] || _error "invalid/missing SNAP_TEST_TYPE (value must be 'small', 'medium', 'large', or 'legacy', received:${SNAP_TEST_TYPE}" +[[ "$SNAP_TEST_TYPE" =~ ^(small|medium|large|legacy|build)$ ]] || _error "invalid/missing SNAP_TEST_TYPE (value must be 'small', 'medium', 'large', 'legacy', or 'build' received:${SNAP_TEST_TYPE}" + +if [[ "${SNAP_TEST_TYPE}" == "build" ]]; then + _info "s3 builds are generated by travis.ci and only triggered by merges on master branch." + exit 0 +fi # If the following plugins don't exist, exit [ -f $SNAP_PATH/plugin/snap-plugin-collector-mock1 ] || { _error 'Error: $SNAP_PATH/plugin/snap-plugin-collector-mock1 does not exist. Run make to build it.'; } diff --git a/scripts/update_dns.go b/scripts/update_dns.go new file mode 100644 index 000000000..e97c94bdd --- /dev/null +++ b/scripts/update_dns.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "os" + "strconv" + + "github.com/dnsimple/dnsimple-go/dnsimple" +) + +func main() { + url := os.Getenv("SNAP_BUILD_URL") + if len(url) == 0 { + fmt.Printf("Must provide SNAP_BUILD_URL") + os.Exit(1) + } + + oauthToken := os.Getenv("DNSIMPLE_TOKEN") + if len(oauthToken) == 0 { + fmt.Printf("Must provide DNSIMPLE_TOKEN") + os.Exit(1) + } + + client := dnsimple.NewClient(dnsimple.NewOauthTokenCredentials(oauthToken)) + + // get DNSimple client accountID + whoamiResponse, err := client.Identity.Whoami() + if err != nil { + fmt.Printf("Whoami() returned error: %v\n", err) + os.Exit(1) + } + accountID := strconv.Itoa(whoamiResponse.Data.Account.ID) + zoneID := "snap-telemetry.io" + + result, err := client.Zones.ListRecords(accountID, zoneID, &dnsimple.ZoneRecordListOptions{Name: "build.ci"}) + if err != nil { + fmt.Printf("build.ci.snap-telemetry.io DNS record not found: %v\n", err) + os.Exit(1) + } + + record := result.Data[0] + + // replace build.ci.snap-telemtry.io URL record with new s3 folder + record.Content = url + client.Zones.UpdateRecord(accountID, zoneID, record.ID, record) +}