From 676744be8405e0f7038859250492715fd849b426 Mon Sep 17 00:00:00 2001 From: Nan Liu Date: Fri, 23 Sep 2016 16:42:09 -0700 Subject: [PATCH] (SDI-2036) Fix #1205 add darwin to binary release Currently we only build linux binaries. This update uses GOOS/GOARCH to crosscompile for MacOS. * remove dns update since we have multiple binaries * follow s3/${GOOS}/${GOARCH}/file convention * use helper.PluginFilePath to determine binary path * change latest folder -> last git tag, latest_build folder -> last pr --- .gitignore | 6 +- .travis.yml | 13 ++- control/control_grpc_server_test.go | 6 +- control/control_test.go | 27 +++--- control/fixtures/fixtures.go | 9 +- control/subscription_group_medium_test.go | 39 +++++---- core/plugin_test.go | 6 +- mgmt/rest/client/client_func_test.go | 13 ++- mgmt/rest/rest_func_test.go | 14 +-- pkg/psigning/psigning_test.go | 6 +- .../main_test.go | 7 +- .../snap-plugin-collector-mock1/main_test.go | 7 +- .../main_test.go | 7 +- .../snap-plugin-collector-mock2/main_test.go | 7 +- plugin/helper/helper.go | 38 +++++++-- .../main_test.go | 7 +- .../main_test.go | 7 +- scheduler/distributed_task_test.go | 16 ++-- scheduler/workflow_test.go | 13 ++- scripts/build_plugin.sh | 2 +- scripts/build_snap.sh | 34 ++++---- scripts/post_deploy.sh | 36 -------- scripts/pre_deploy.sh | 85 +++++++++++++------ scripts/test.sh | 6 -- scripts/update_dns.go | 46 ---------- 25 files changed, 204 insertions(+), 253 deletions(-) delete mode 100755 scripts/post_deploy.sh delete mode 100644 scripts/update_dns.go diff --git a/.gitignore b/.gitignore index fa25424ca..42b3553e6 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,6 @@ _testmain.go tmp/ *.tmp scratch/ -build/ *.swp profile.cov gin-bin @@ -40,3 +39,8 @@ vendor/ .DS_Store *.cov + +# build and release artifacts +build/ +s3/ +release/ diff --git a/.travis.yml b/.travis.yml index c1723315a..8420b4da7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ sudo: false language: go go: -- 1.5.4 -- 1.6.2 +- 1.6.3 +- 1.7.1 before_install: - bash scripts/gitcookie.sh - go get github.com/smartystreets/goconvey/convey @@ -11,7 +11,6 @@ env: global: - 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 @@ -19,7 +18,7 @@ env: - SNAP_TEST_TYPE=build matrix: exclude: - - go: 1.5.4 + - go: 1.6.3 env: SNAP_TEST_TYPE=build install: - export TMPDIR=$HOME/tmp @@ -42,12 +41,10 @@ deploy: bucket: snap.ci.snap-telemetry.io region: us-west-2 skip_cleanup: true - local-dir: build + local-dir: s3 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" + condition: $SNAP_TEST_TYPE = build && $TRAVIS_GO_VERSION = "1.7.1" diff --git a/control/control_grpc_server_test.go b/control/control_grpc_server_test.go index 20dcee346..149365c47 100644 --- a/control/control_grpc_server_test.go +++ b/control/control_grpc_server_test.go @@ -23,7 +23,6 @@ package control import ( "net" - "path" "testing" "github.com/intelsdi-x/gomit" @@ -38,6 +37,7 @@ import ( "github.com/intelsdi-x/snap/grpc/common" "github.com/intelsdi-x/snap/grpc/controlproxy/rpc" "github.com/intelsdi-x/snap/pkg/rpcutil" + "github.com/intelsdi-x/snap/plugin/helper" . "github.com/smartystreets/goconvey/convey" ) @@ -99,7 +99,7 @@ func TestGRPCServerScheduler(t *testing.T) { }) }) <-lpe.done - passthru, err := core.NewRequestedPlugin(path.Join(fixtures.SnapPath, "plugin", "snap-plugin-processor-passthru")) + passthru, err := core.NewRequestedPlugin(helper.PluginFilePath("snap-plugin-processor-passthru")) if err != nil { log.Fatal(err) } @@ -115,7 +115,7 @@ func TestGRPCServerScheduler(t *testing.T) { typeName: catalogedPassthru.TypeName(), } <-lpe.done - filepub, err := core.NewRequestedPlugin(path.Join(fixtures.SnapPath, "plugin", "snap-plugin-publisher-mock-file")) + filepub, err := core.NewRequestedPlugin(helper.PluginFilePath("snap-plugin-publisher-mock-file")) if err != nil { log.Fatal(err) } diff --git a/control/control_test.go b/control/control_test.go index f8ecf70b7..59d571814 100644 --- a/control/control_test.go +++ b/control/control_test.go @@ -46,6 +46,7 @@ import ( "github.com/intelsdi-x/snap/core/control_event" "github.com/intelsdi-x/snap/core/ctypes" "github.com/intelsdi-x/snap/core/serror" + "github.com/intelsdi-x/snap/plugin/helper" ) // Mock Executor used to test @@ -1460,7 +1461,7 @@ func TestPublishMetrics(t *testing.T) { time.Sleep(1 * time.Second) // Load plugin - _, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-publisher-mock-file")) + _, err := load(c, helper.PluginFilePath("snap-plugin-publisher-mock-file")) So(err, ShouldBeNil) <-lpe.done So(len(c.pluginManager.all()), ShouldEqual, 1) @@ -1508,7 +1509,7 @@ func TestProcessMetrics(t *testing.T) { c.Config.Plugins.Processor.Plugins["passthru"] = newPluginConfigItem(optAddPluginConfigItem("test", ctypes.ConfigValueBool{Value: true})) // Load plugin - _, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-processor-passthru")) + _, err := load(c, helper.PluginFilePath("snap-plugin-processor-passthru")) So(err, ShouldBeNil) <-lpe.done So(len(c.pluginManager.all()), ShouldEqual, 1) @@ -1590,7 +1591,7 @@ func TestMetricSubscriptionToNewVersion(t *testing.T) { lpe := newListenToPluginEvents() c.eventManager.RegisterHandler("TestMetricSubscriptionToNewVersion", lpe) c.Start() - _, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock1")) + _, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock1")) <-lpe.load So(err, ShouldBeNil) So(len(c.pluginManager.all()), ShouldEqual, 1) @@ -1625,7 +1626,7 @@ func TestMetricSubscriptionToNewVersion(t *testing.T) { }) Convey("Loading v2 of that plugin should move subscriptions to newer version", func() { // Load version snap-plugin-collector-mock2 - _, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock2")) + _, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock2")) So(err, ShouldBeNil) select { // Wait on subscriptionMovedEvent @@ -1662,7 +1663,7 @@ func TestMetricSubscriptionToOlderVersion(t *testing.T) { lpe := newListenToPluginEvents() c.eventManager.RegisterHandler("TestMetricSubscriptionToOlderVersion", lpe) c.Start() - _, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock2")) + _, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock2")) <-lpe.load So(err, ShouldBeNil) So(len(c.pluginManager.all()), ShouldEqual, 1) @@ -1693,7 +1694,7 @@ func TestMetricSubscriptionToOlderVersion(t *testing.T) { mockv2 := pc[0] Convey("Loading v1 of that plugin and unloading v2 should move subscriptions to older version", func() { // Load version snap-plugin-collector-mock1 - _, err = load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock1")) + _, err = load(c, helper.PluginFilePath("snap-plugin-collector-mock1")) <-lpe.load So(err, ShouldBeNil) // Unload version snap-plugin-collector-mock2 @@ -1746,7 +1747,7 @@ func TestDynamicMetricSubscriptionLoad(t *testing.T) { lpe := newListenToPluginEvents() c.eventManager.RegisterHandler("TestDynamicMetricSubscriptionLoad", lpe) c.Start() - _, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock1")) + _, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) So(len(c.pluginManager.all()), ShouldEqual, 1) lp, err2 := c.pluginManager.get("collector" + core.Separator + "mock" + core.Separator + "1") @@ -1787,7 +1788,7 @@ func TestDynamicMetricSubscriptionLoad(t *testing.T) { }) Convey("Loading mock plugin in version 2 should swap subscriptions to latest version", func() { // Load version snap-plugin-collector-mock2 - _, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock2")) + _, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock2")) So(err, ShouldBeNil) <-lpe.load // wait for load event <-lpe.sub // wait for subscription event @@ -1813,7 +1814,7 @@ func TestDynamicMetricSubscriptionLoad(t *testing.T) { }) Convey("Loading another plugin should add subscriptions", func() { // Load version snap-plugin-collector-anothermock1 - _, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-anothermock1")) + _, err := load(c, helper.PluginFilePath("snap-plugin-collector-anothermock1")) So(err, ShouldBeNil) <-lpe.load // wait for load event <-lpe.sub // wait for subscription event @@ -1845,9 +1846,9 @@ func TestDynamicMetricSubscriptionUnload(t *testing.T) { lpe := newListenToPluginEvents() c.eventManager.RegisterHandler("TestDynamicMetricSubscriptionUnload", lpe) c.Start() - _, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock1")) + _, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) - _, err = load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-anothermock1")) + _, err = load(c, helper.PluginFilePath("snap-plugin-collector-anothermock1")) So(err, ShouldBeNil) So(len(c.pluginManager.all()), ShouldEqual, 2) lpMock, err2 := c.pluginManager.get("collector" + core.Separator + "mock" + core.Separator + "1") @@ -1928,7 +1929,7 @@ func TestDynamicMetricSubscriptionLoadLessMetrics(t *testing.T) { lpe := newListenToPluginEvents() c.eventManager.RegisterHandler("TestDynamicMetricSubscriptionLoadLessMetrics", lpe) c.Start() - _, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock1")) + _, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) So(len(c.pluginManager.all()), ShouldEqual, 1) lp, err2 := c.pluginManager.get("collector" + core.Separator + "mock" + core.Separator + "1") @@ -1970,7 +1971,7 @@ func TestDynamicMetricSubscriptionLoadLessMetrics(t *testing.T) { }) Convey("Loading higher plugin version with less metrics", func() { // Load version snap-plugin-collector-mock2 - _, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock2")) + _, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock2")) So(err, ShouldBeNil) <-lpe.load // wait for load event <-lpe.sub // wait for subscription event diff --git a/control/fixtures/fixtures.go b/control/fixtures/fixtures.go index d970c7ac3..52771b42a 100644 --- a/control/fixtures/fixtures.go +++ b/control/fixtures/fixtures.go @@ -22,21 +22,20 @@ package fixtures import ( "encoding/json" - "os" - "path" "time" "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/core/cdata" + "github.com/intelsdi-x/snap/plugin/helper" ) var ( PluginName = "snap-plugin-collector-mock2" - SnapPath = os.ExpandEnv(os.Getenv("SNAP_PATH")) - PluginPath = path.Join(SnapPath, "plugin", PluginName) + SnapPath = helper.BuildPath + PluginPath = helper.PluginFilePath(PluginName) JSONRPCPluginName = "snap-plugin-collector-mock1" - JSONRPCPluginPath = path.Join(SnapPath, "plugin", JSONRPCPluginName) + JSONRPCPluginPath = helper.PluginFilePath(JSONRPCPluginName) ) // mocks a metric type diff --git a/control/subscription_group_medium_test.go b/control/subscription_group_medium_test.go index 8861c4d0f..7241f1d56 100644 --- a/control/subscription_group_medium_test.go +++ b/control/subscription_group_medium_test.go @@ -23,14 +23,13 @@ package control import ( "net" - "os" - "path" "testing" "github.com/intelsdi-x/snap/core" "github.com/intelsdi-x/snap/core/cdata" "github.com/intelsdi-x/snap/core/control_event" "github.com/intelsdi-x/snap/core/serror" + "github.com/intelsdi-x/snap/plugin/helper" log "github.com/Sirupsen/logrus" "github.com/intelsdi-x/gomit" @@ -128,7 +127,7 @@ func TestSubscriptionGroups_ProcessStaticNegative(t *testing.T) { c.Start() Convey("Loading a mock collector plugin", t, func() { - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) <-lpe.load @@ -166,7 +165,7 @@ func TestSubscriptionGroups_ProcessStaticNegative(t *testing.T) { config: cdata.NewNode(), } - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-anothermock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-anothermock1")) So(err, ShouldBeNil) <-lpe.load serrs := sg.Process() @@ -199,7 +198,7 @@ func TestSubscriptionGroups_ProcessStaticPositive(t *testing.T) { c.Start() Convey("Loading a mock collector plugin", t, func() { - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) <-lpe.load @@ -236,7 +235,7 @@ func TestSubscriptionGroups_ProcessStaticPositive(t *testing.T) { version: 2, config: cdata.NewNode(), } - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock2")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock2")) So(err, ShouldBeNil) <-lpe.load serrs := sg.Process() @@ -269,7 +268,7 @@ func TestSubscriptionGroups_ProcessDynamicPositive(t *testing.T) { c.Start() Convey("Loading a mock collector plugin", t, func() { - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) <-lpe.load @@ -307,7 +306,7 @@ func TestSubscriptionGroups_ProcessDynamicPositive(t *testing.T) { version: 1, config: cdata.NewNode(), } - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-anothermock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-anothermock1")) So(err, ShouldBeNil) <-lpe.load serrs := sg.Process() @@ -345,7 +344,7 @@ func TestSubscriptionGroups_ProcessDynamicNegative(t *testing.T) { c.Start() Convey("Loading a mock collector plugin", t, func() { - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) <-lpe.load @@ -382,7 +381,7 @@ func TestSubscriptionGroups_ProcessDynamicNegative(t *testing.T) { version: 1, config: cdata.NewNode(), } - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-anothermock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-anothermock1")) So(err, ShouldBeNil) <-lpe.load serrs := sg.Process() @@ -416,7 +415,7 @@ func TestSubscriptionGroups_ProcessSpecifiedDynamicPositive(t *testing.T) { c.Start() Convey("Loading a mock collector plugin", t, func() { - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) <-lpe.load @@ -459,7 +458,7 @@ func TestSubscriptionGroups_ProcessSpecifiedDynamicPositive(t *testing.T) { version: 1, config: cdata.NewNode(), } - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-anothermock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-anothermock1")) So(err, ShouldBeNil) <-lpe.load serrs := sg.Process() @@ -499,7 +498,7 @@ func TestSubscriptionGroups_ProcessSpecifiedDynamicNegative(t *testing.T) { c.Start() Convey("Loading a mock collector plugin", t, func() { - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) <-lpe.load @@ -540,7 +539,7 @@ func TestSubscriptionGroups_ProcessSpecifiedDynamicNegative(t *testing.T) { version: 1, config: cdata.NewNode(), } - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-anothermock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-anothermock1")) So(err, ShouldBeNil) <-lpe.load serrs := sg.Process() @@ -576,7 +575,7 @@ func TestSubscriptionGroups_AddRemoveStatic(t *testing.T) { c.Start() Convey("Loading a mock collector plugn", t, func() { - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) <-lpe.load @@ -615,7 +614,7 @@ func TestSubscriptionGroups_AddRemoveDynamic(t *testing.T) { c.Start() Convey("Loading a mock collector plugn", t, func() { - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) <-lpe.load @@ -657,7 +656,7 @@ func TestSubscriptionGroups_AddRemoveSpecifiedDynamic(t *testing.T) { c.Start() Convey("Loading a mock collector plugn", t, func() { - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) <-lpe.load @@ -702,7 +701,7 @@ func TestSubscriptionGroups_GetStatic(t *testing.T) { c.Start() Convey("Loading a mock collector plugn", t, func() { - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) <-lpe.load @@ -751,7 +750,7 @@ func TestSubscriptionGroups_GetDynamic(t *testing.T) { c.Start() Convey("Loading a mock collector plugn", t, func() { - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) <-lpe.load @@ -800,7 +799,7 @@ func TestSubscriptionGroups_GetSpecifiedDynamic(t *testing.T) { c.Start() Convey("Loading a mock collector plugn", t, func() { - _, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1")) + _, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1")) So(err, ShouldBeNil) <-lpe.load diff --git a/core/plugin_test.go b/core/plugin_test.go index 12e8db1ad..94c5e7841 100644 --- a/core/plugin_test.go +++ b/core/plugin_test.go @@ -24,17 +24,17 @@ package core import ( "crypto/sha256" "io/ioutil" - "os" "path" "testing" + "github.com/intelsdi-x/snap/plugin/helper" . "github.com/smartystreets/goconvey/convey" ) var ( PluginName = "snap-plugin-collector-mock1" - SnapPath = os.ExpandEnv(os.Getenv("SNAP_PATH")) - PluginPath = path.Join(SnapPath, "plugin", PluginName) + SnapPath = helper.BuildPath + PluginPath = helper.PluginFilePath(PluginName) SignatureFile = path.Join(SnapPath, "../pkg/psigning", "snap-plugin-collector-mock1.asc") ) diff --git a/mgmt/rest/client/client_func_test.go b/mgmt/rest/client/client_func_test.go index 06ce73383..5e5656329 100644 --- a/mgmt/rest/client/client_func_test.go +++ b/mgmt/rest/client/client_func_test.go @@ -26,7 +26,6 @@ package client import ( "fmt" "io/ioutil" - "os" "sync" "testing" "time" @@ -36,6 +35,7 @@ import ( "github.com/intelsdi-x/snap/control" "github.com/intelsdi-x/snap/mgmt/rest" + "github.com/intelsdi-x/snap/plugin/helper" "github.com/intelsdi-x/snap/scheduler" "github.com/intelsdi-x/snap/scheduler/wmap" . "github.com/smartystreets/goconvey/convey" @@ -45,12 +45,11 @@ var ( // Change to set the REST API logging to debug LOG_LEVEL = log.FatalLevel - SNAP_PATH = os.ExpandEnv(os.Getenv("SNAP_PATH")) - MOCK_PLUGIN_PATH1 = []string{SNAP_PATH + "/plugin/snap-plugin-collector-mock1"} - MOCK_PLUGIN_PATH2 = []string{SNAP_PATH + "/plugin/snap-plugin-collector-mock2"} - ANOTHERMOCK_PLUGIN_PATH = []string{SNAP_PATH + "/plugin/snap-plugin-collector-anothermock1"} - FILE_PLUGIN_PATH = []string{SNAP_PATH + "/plugin/snap-plugin-publisher-mock-file"} - DIRECTORY_PATH = []string{SNAP_PATH + "/plugin/"} + MOCK_PLUGIN_PATH1 = []string{helper.PluginFilePath("snap-plugin-collector-mock1")} + MOCK_PLUGIN_PATH2 = []string{helper.PluginFilePath("snap-plugin-collector-mock2")} + ANOTHERMOCK_PLUGIN_PATH = []string{helper.PluginFilePath("snap-plugin-collector-anothermock1")} + FILE_PLUGIN_PATH = []string{helper.PluginFilePath("snap-plugin-publisher-mock-file")} + DIRECTORY_PATH = []string{helper.PluginPath()} NextPort = 45000 diff --git a/mgmt/rest/rest_func_test.go b/mgmt/rest/rest_func_test.go index 38b3297a5..9a44e4756 100644 --- a/mgmt/rest/rest_func_test.go +++ b/mgmt/rest/rest_func_test.go @@ -46,6 +46,7 @@ import ( "github.com/intelsdi-x/snap/core/ctypes" "github.com/intelsdi-x/snap/mgmt/rest/rbody" "github.com/intelsdi-x/snap/pkg/cfgfile" + "github.com/intelsdi-x/snap/plugin/helper" "github.com/intelsdi-x/snap/scheduler" "github.com/intelsdi-x/snap/scheduler/wmap" . "github.com/smartystreets/goconvey/convey" @@ -55,11 +56,11 @@ var ( // Switching this turns on logging for all the REST API calls LOG_LEVEL = log.WarnLevel - SNAP_PATH = os.ExpandEnv(os.Getenv("SNAP_PATH")) + SNAP_PATH = helper.BuildPath SNAP_AUTODISCOVER_PATH = os.Getenv("SNAP_AUTODISCOVER_PATH") - MOCK_PLUGIN_PATH1 = SNAP_PATH + "/plugin/snap-plugin-collector-mock1" - MOCK_PLUGIN_PATH2 = SNAP_PATH + "/plugin/snap-plugin-collector-mock2" - FILE_PLUGIN_PATH = SNAP_PATH + "/plugin/snap-plugin-publisher-mock-file" + MOCK_PLUGIN_PATH1 = helper.PluginFilePath("snap-plugin-collector-mock1") + MOCK_PLUGIN_PATH2 = helper.PluginFilePath("snap-plugin-collector-mock2") + FILE_PLUGIN_PATH = helper.PluginFilePath("snap-plugin-publisher-mock-file") CompressedUpload = true TotalUploadSize = 0 @@ -584,8 +585,9 @@ func TestPluginRestCalls(t *testing.T) { So(err, ShouldBeNil) if len(SNAP_AUTODISCOVER_PATH) == 0 { if len(SNAP_PATH) != 0 { - SNAP_AUTODISCOVER_PATH = fmt.Sprintf("%s/plugin", SNAP_PATH) - log.Warning(fmt.Sprintf("SNAP_AUTODISCOVER_PATH has been set to SNAP_PATH/plugin (%s). This might cause test failures", SNAP_AUTODISCOVER_PATH)) + + SNAP_AUTODISCOVER_PATH = helper.PluginPath() + log.Warning(fmt.Sprintf("SNAP_AUTODISCOVER_PATH has been set to plugin build path (%s). This might cause test failures", SNAP_AUTODISCOVER_PATH)) } } else { log.Warning(fmt.Sprintf("SNAP_AUTODISCOVER_PATH is set to %s. This might cause test failures", SNAP_AUTODISCOVER_PATH)) diff --git a/pkg/psigning/psigning_test.go b/pkg/psigning/psigning_test.go index 0e9e1c39b..b388543df 100644 --- a/pkg/psigning/psigning_test.go +++ b/pkg/psigning/psigning_test.go @@ -23,10 +23,9 @@ package psigning import ( "io/ioutil" - "os" - "path" "testing" + "github.com/intelsdi-x/snap/plugin/helper" . "github.com/smartystreets/goconvey/convey" ) @@ -34,8 +33,7 @@ func TestValidateSignature(t *testing.T) { keyringFile := []string{"pubring.gpg"} signedFile := "snap-plugin-collector-mock1" signatureFile := signedFile + ".asc" - snapPath := os.ExpandEnv(os.Getenv("SNAP_PATH")) - unsignedFile := path.Join(snapPath, "plugin", "snap-plugin-collector-mock2") + unsignedFile := helper.PluginFilePath("snap-plugin-collector-mock2") s := SigningManager{} signature, _ := ioutil.ReadFile(signatureFile) diff --git a/plugin/collector/snap-plugin-collector-anothermock1/main_test.go b/plugin/collector/snap-plugin-collector-anothermock1/main_test.go index 8804b882b..4459ccfaa 100644 --- a/plugin/collector/snap-plugin-collector-anothermock1/main_test.go +++ b/plugin/collector/snap-plugin-collector-anothermock1/main_test.go @@ -22,8 +22,6 @@ limitations under the License. package main import ( - "os" - "path" "testing" "github.com/intelsdi-x/snap/control" @@ -35,8 +33,7 @@ import ( var ( PluginName = "snap-plugin-collector-anothermock1" PluginType = "collector" - SnapPath = os.ExpandEnv(os.Getenv("SNAP_PATH")) - PluginPath = path.Join(SnapPath, "plugin", PluginName) + PluginPath = helper.PluginFilePath(PluginName) ) func TestMockPluginLoad(t *testing.T) { @@ -44,7 +41,7 @@ func TestMockPluginLoad(t *testing.T) { // It is the responsibility of the testing framework to // build the plugins first into the build dir. Convey("make sure plugin has been built", t, func() { - err := helper.CheckPluginBuilt(SnapPath, PluginName) + err := helper.PluginFileCheck(PluginName) So(err, ShouldBeNil) Convey("ensure plugin loads and responds", func() { diff --git a/plugin/collector/snap-plugin-collector-mock1/main_test.go b/plugin/collector/snap-plugin-collector-mock1/main_test.go index 44d61311a..223e84c8e 100644 --- a/plugin/collector/snap-plugin-collector-mock1/main_test.go +++ b/plugin/collector/snap-plugin-collector-mock1/main_test.go @@ -22,8 +22,6 @@ limitations under the License. package main import ( - "os" - "path" "testing" "github.com/intelsdi-x/snap/control" @@ -35,8 +33,7 @@ import ( var ( PluginName = "snap-plugin-collector-mock1" PluginType = "collector" - SnapPath = os.ExpandEnv(os.Getenv("SNAP_PATH")) - PluginPath = path.Join(SnapPath, "plugin", PluginName) + PluginPath = helper.PluginFilePath(PluginName) ) func TestMockPluginLoad(t *testing.T) { @@ -45,7 +42,7 @@ func TestMockPluginLoad(t *testing.T) { // build the plugins first into the build dir. Convey("make sure plugin has been built", t, func() { - err := helper.CheckPluginBuilt(SnapPath, PluginName) + err := helper.PluginFileCheck(PluginName) So(err, ShouldBeNil) Convey("ensure plugin loads and responds", func() { diff --git a/plugin/collector/snap-plugin-collector-mock2-grpc/main_test.go b/plugin/collector/snap-plugin-collector-mock2-grpc/main_test.go index 1a4dd471a..ad7e2539e 100644 --- a/plugin/collector/snap-plugin-collector-mock2-grpc/main_test.go +++ b/plugin/collector/snap-plugin-collector-mock2-grpc/main_test.go @@ -22,8 +22,6 @@ limitations under the License. package main import ( - "os" - "path" "testing" "github.com/intelsdi-x/snap/control" @@ -35,8 +33,7 @@ import ( var ( PluginName = "snap-plugin-collector-mock2-grpc" PluginType = "collector" - SnapPath = os.ExpandEnv(os.Getenv("SNAP_PATH")) - PluginPath = path.Join(SnapPath, "plugin", PluginName) + PluginPath = helper.PluginFilePath(PluginName) ) func TestMockPluginLoad(t *testing.T) { @@ -44,7 +41,7 @@ func TestMockPluginLoad(t *testing.T) { // It is the responsibility of the testing framework to // build the plugins first into the build dir. Convey("make sure plugin has been built", t, func() { - err := helper.CheckPluginBuilt(SnapPath, PluginName) + err := helper.PluginFileCheck(PluginName) So(err, ShouldBeNil) Convey("ensure plugin loads and responds", func() { diff --git a/plugin/collector/snap-plugin-collector-mock2/main_test.go b/plugin/collector/snap-plugin-collector-mock2/main_test.go index 548841036..4ba9825e3 100644 --- a/plugin/collector/snap-plugin-collector-mock2/main_test.go +++ b/plugin/collector/snap-plugin-collector-mock2/main_test.go @@ -22,8 +22,6 @@ limitations under the License. package main import ( - "os" - "path" "testing" "github.com/intelsdi-x/snap/control" @@ -35,8 +33,7 @@ import ( var ( PluginName = "snap-plugin-collector-mock2" PluginType = "collector" - SnapPath = os.ExpandEnv(os.Getenv("SNAP_PATH")) - PluginPath = path.Join(SnapPath, "plugin", PluginName) + PluginPath = helper.PluginFilePath(PluginName) ) func TestMockPluginLoad(t *testing.T) { @@ -44,7 +41,7 @@ func TestMockPluginLoad(t *testing.T) { // It is the responsibility of the testing framework to // build the plugins first into the build dir. Convey("make sure plugin has been built", t, func() { - err := helper.CheckPluginBuilt(SnapPath, PluginName) + err := helper.PluginFileCheck(PluginName) So(err, ShouldBeNil) Convey("ensure plugin loads and responds", func() { diff --git a/plugin/helper/helper.go b/plugin/helper/helper.go index e1ab54323..d73a1d2c9 100644 --- a/plugin/helper/helper.go +++ b/plugin/helper/helper.go @@ -1,7 +1,6 @@ /* http://www.apache.org/licenses/LICENSE-2.0.txt - Copyright 2015 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,19 +22,40 @@ package helper import ( "fmt" "os" + "path" + "runtime" ) -//SNAP_PATH should be set to Snap's build directory +var ( + BuildPath = os.ExpandEnv(os.Getenv("SNAP_PATH")) +) -//CheckPluginBuilt checks if PluginName has been built. -func CheckPluginBuilt(SnapPath string, PluginName string) error { - if SnapPath == "" { - return fmt.Errorf("SNAP_PATH not set. Cannot test %s plugin.\n", PluginName) +func PluginFileCheck(name string) error { + if BuildPath == "" { + return fmt.Errorf("$SNAP_PATH environment variable not set. Cannot test plugins.\n") } - bPath := fmt.Sprintf("%s/plugin/%s", SnapPath, PluginName) - if _, err := os.Stat(bPath); os.IsNotExist(err) { + + fpath := PluginFilePath(name) + if _, err := os.Stat(fpath); os.IsNotExist(err) { //the binary has not been built yet - return fmt.Errorf("Error: $SNAP_PATH/plugin/%s does not exist. Run make to build it.", PluginName) + return fmt.Errorf("Error: %s does not exist in %s. Run make to build it.", name, fpath) } return nil } + +func PluginPath() string { + var arch string + if runtime.GOARCH == "amd64" { + arch = "x86_64" + } else { + arch = runtime.GOARCH + } + + fpath := path.Join(BuildPath, runtime.GOOS, arch) + return fpath +} + +func PluginFilePath(name string) string { + fpath := path.Join(PluginPath(), name) + return fpath +} diff --git a/plugin/publisher/snap-plugin-publisher-mock-file-grpc/main_test.go b/plugin/publisher/snap-plugin-publisher-mock-file-grpc/main_test.go index f1ac32146..87309dbb5 100644 --- a/plugin/publisher/snap-plugin-publisher-mock-file-grpc/main_test.go +++ b/plugin/publisher/snap-plugin-publisher-mock-file-grpc/main_test.go @@ -22,8 +22,6 @@ limitations under the License. package main import ( - "os" - "path" "testing" "github.com/intelsdi-x/snap/control" @@ -35,8 +33,7 @@ import ( var ( PluginName = "snap-plugin-publisher-mock-file-grpc" PluginType = "publisher" - SnapPath = os.ExpandEnv(os.Getenv("SNAP_PATH")) - PluginPath = path.Join(SnapPath, "plugin", PluginName) + PluginPath = helper.PluginFilePath(PluginName) ) func TestFilePublisherLoad(t *testing.T) { @@ -45,7 +42,7 @@ func TestFilePublisherLoad(t *testing.T) { // build the plugins first into the build dir. Convey("make sure plugin has been built", t, func() { - err := helper.CheckPluginBuilt(SnapPath, PluginName) + err := helper.PluginFileCheck(PluginName) So(err, ShouldBeNil) Convey("ensure plugin loads and responds", func() { diff --git a/plugin/publisher/snap-plugin-publisher-mock-file/main_test.go b/plugin/publisher/snap-plugin-publisher-mock-file/main_test.go index febf0e3dd..949d69022 100644 --- a/plugin/publisher/snap-plugin-publisher-mock-file/main_test.go +++ b/plugin/publisher/snap-plugin-publisher-mock-file/main_test.go @@ -22,8 +22,6 @@ limitations under the License. package main import ( - "os" - "path" "testing" "github.com/intelsdi-x/snap/control" @@ -35,8 +33,7 @@ import ( var ( PluginName = "snap-plugin-publisher-mock-file" PluginType = "publisher" - SnapPath = os.ExpandEnv(os.Getenv("SNAP_PATH")) - PluginPath = path.Join(SnapPath, "plugin", PluginName) + PluginPath = helper.PluginFilePath(PluginName) ) func TestFilePublisherLoad(t *testing.T) { @@ -45,7 +42,7 @@ func TestFilePublisherLoad(t *testing.T) { // build the plugins first into the build dir. Convey("make sure plugin has been built", t, func() { - err := helper.CheckPluginBuilt(SnapPath, PluginName) + err := helper.PluginFileCheck(PluginName) So(err, ShouldBeNil) Convey("ensure plugin loads and responds", func() { diff --git a/scheduler/distributed_task_test.go b/scheduler/distributed_task_test.go index cbe6ada3e..e5878c4b3 100644 --- a/scheduler/distributed_task_test.go +++ b/scheduler/distributed_task_test.go @@ -25,7 +25,6 @@ import ( "errors" "fmt" "net" - "path" "testing" "time" @@ -37,12 +36,13 @@ import ( "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/grpc/controlproxy" "github.com/intelsdi-x/snap/pkg/schedule" + "github.com/intelsdi-x/snap/plugin/helper" "github.com/intelsdi-x/snap/scheduler/wmap" . "github.com/smartystreets/goconvey/convey" ) var ( - PluginPath = path.Join(SnapPath, "plugin") + PluginPath = helper.PluginPath() ) func TestDistributedWorkflow(t *testing.T) { @@ -65,9 +65,9 @@ func TestDistributedWorkflow(t *testing.T) { err := sch.Start() So(err, ShouldBeNil) // Load appropriate plugins into each control. - mock2Path := path.Join(PluginPath, "snap-plugin-collector-mock2") - passthruPath := path.Join(PluginPath, "snap-plugin-processor-passthru") - filePath := path.Join(PluginPath, "snap-plugin-publisher-mock-file") + mock2Path := helper.PluginFilePath("snap-plugin-collector-mock2") + passthruPath := helper.PluginFilePath("snap-plugin-processor-passthru") + filePath := helper.PluginFilePath("snap-plugin-publisher-mock-file") // mock2 and file onto c1 @@ -204,9 +204,9 @@ func TestDistributedSubscriptions(t *testing.T) { err := sch.Start() So(err, ShouldBeNil) // Load appropriate plugins into each control. - mock2Path := path.Join(PluginPath, "snap-plugin-collector-mock2") - passthruPath := path.Join(PluginPath, "snap-plugin-processor-passthru") - filePath := path.Join(PluginPath, "snap-plugin-publisher-mock-file") + mock2Path := helper.PluginFilePath("snap-plugin-collector-mock2") + passthruPath := helper.PluginFilePath("snap-plugin-processor-passthru") + filePath := helper.PluginFilePath("snap-plugin-publisher-mock-file") // mock2 and file onto c1 diff --git a/scheduler/workflow_test.go b/scheduler/workflow_test.go index 426064abc..5d8c8287a 100644 --- a/scheduler/workflow_test.go +++ b/scheduler/workflow_test.go @@ -24,8 +24,6 @@ package scheduler import ( "errors" "fmt" - "os" - "path" "sync" "testing" "time" @@ -40,6 +38,7 @@ import ( "github.com/intelsdi-x/snap/core/serror" "github.com/intelsdi-x/snap/pkg/promise" "github.com/intelsdi-x/snap/pkg/schedule" + "github.com/intelsdi-x/snap/plugin/helper" "github.com/intelsdi-x/snap/scheduler/wmap" log "github.com/Sirupsen/logrus" @@ -47,11 +46,11 @@ import ( ) var ( - SnapPath = os.ExpandEnv(os.Getenv("SNAP_PATH")) - snap_collector_mock1_path = path.Join(SnapPath, "plugin", "snap-plugin-collector-mock1") - snap_collector_mock2_path = path.Join(SnapPath, "plugin", "snap-plugin-collector-mock2") - snap_processor_passthru_path = path.Join(SnapPath, "plugin", "snap-plugin-processor-passthru") - snap_publisher_file_path = path.Join(SnapPath, "plugin", "snap-plugin-publisher-mock-file") + SnapPath = helper.BuildPath + snap_collector_mock1_path = helper.PluginFilePath("snap-plugin-collector-mock1") + snap_collector_mock2_path = helper.PluginFilePath("snap-plugin-collector-mock2") + snap_processor_passthru_path = helper.PluginFilePath("snap-plugin-processor-passthru") + snap_publisher_file_path = helper.PluginFilePath("snap-plugin-publisher-mock-file") metricsToCollect = 3 ) diff --git a/scripts/build_plugin.sh b/scripts/build_plugin.sh index 08f51d356..3195f6611 100755 --- a/scripts/build_plugin.sh +++ b/scripts/build_plugin.sh @@ -28,7 +28,7 @@ __proj_dir="$(dirname "$__dir")" . "${__dir}/common.sh" build_dir="${__proj_dir}/build" -plugin_dir="${build_dir}/plugin" +plugin_dir="${build_dir}/${GOOS}/x86_64" plugin_src_path=$1 plugin_name=$(basename "${plugin_src_path}") diff --git a/scripts/build_snap.sh b/scripts/build_snap.sh index d503326b7..2bbcc9f32 100755 --- a/scripts/build_snap.sh +++ b/scripts/build_snap.sh @@ -34,9 +34,7 @@ __proj_dir="$(dirname "$__dir")" _info "project path: ${__proj_dir}" -build_dir="${__proj_dir}/build" -bin_dir="${build_dir}/bin" -plugin_dir="${build_dir}/plugin" +build_path="${__proj_dir}/build" go_build=(go build -ldflags "-w -X main.gitversion=${git_version}") _info "snap build version: ${git_version}" @@ -46,20 +44,24 @@ _info "git commit: $(git log --pretty=format:"%H" -1)" export CGO_ENABLED=0 # rebuild binaries: -_debug "removing: ${bin_dir:?}/*" -rm -rf "${bin_dir:?}/"* -mkdir -p "${bin_dir}" +export GOOS=linux +export GOARCH=amd64 +bin_path="${build_path}/${GOOS}/x86_64" +mkdir -p "${bin_path}" +_info "building snapd/snapctl for ${GOOS}/${GOARCH}" +"${go_build[@]}" -o "${bin_path}/snapd" . || exit 1 +(cd "${__proj_dir}/cmd/snapctl" && "${go_build[@]}" -o "${bin_path}/snapctl" . || exit 1) -_info "building snapd" -"${go_build[@]}" -o "${bin_dir}/snapd" . || exit 1 - -_info "building snapctl" -(cd "${__proj_dir}/cmd/snapctl" && "${go_build[@]}" -o "${bin_dir}/snapctl" . || exit 1) +_info "building plugins for ${GOOS}/${GOARCH}" +find "${__proj_dir}/plugin/" -type d -iname "snap-*" -print0 | xargs -0 -n 1 -I{} "${__dir}/build_plugin.sh" {} -# rebuild plugins: -_debug "removing: ${plugin_dir:?}/*" -rm -rf "${plugin_dir:?}/"* -mkdir -p "${plugin_dir}" +export GOOS=darwin +export GOARCH=amd64 +bin_path="${build_path}/${GOOS}/x86_64" +mkdir -p "${bin_path}" +_info "building snapd/snapctl for ${GOOS}/${GOARCH}" +"${go_build[@]}" -o "${bin_path}/snapd" . || exit 1 +(cd "${__proj_dir}/cmd/snapctl" && "${go_build[@]}" -o "${bin_path}/snapctl" . || exit 1) -_info "building plugins" +_info "building plugins for ${GOOS}/${GOARCH}" find "${__proj_dir}/plugin/" -type d -iname "snap-*" -print0 | xargs -0 -n 1 -I{} "${__dir}/build_plugin.sh" {} diff --git a/scripts/post_deploy.sh b/scripts/post_deploy.sh deleted file mode 100755 index 0e12c9df7..000000000 --- a/scripts/post_deploy.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/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 index 340dc902e..9a578247f 100755 --- a/scripts/pre_deploy.sh +++ b/scripts/pre_deploy.sh @@ -1,21 +1,22 @@ #!/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 2016 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. set -e set -u @@ -27,17 +28,53 @@ __proj_dir="$(dirname "$__dir")" # shellcheck source=scripts/common.sh . "${__dir}/common.sh" -build_path="${SNAP_PATH:-"${__proj_dir}/build"}" +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) -git_path="${build_path}/${TRAVIS_BRANCH}/${git_sha}" -latest_path="${build_path}/${TRAVIS_BRANCH}/latest" - -mkdir -p "${git_path}" -mkdir -p "${latest_path}" - -_info "copying snap binaries to ${git_path}" -cp "${build_path}/bin/"* "${git_path}" -cp "${build_path}/plugin/"* "${git_path}" -_info "copying snap binaries to ${latest_path}" -mv "${build_path}/bin/"* "${latest_path}" -mv "${build_path}/plugin/"* "${latest_path}" +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 33f1742e7..0d56efff3 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -45,12 +45,6 @@ if [[ "${SNAP_TEST_TYPE}" == "build" ]]; then 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.'; } -[ -f $SNAP_PATH/plugin/snap-plugin-collector-mock2 ] || { _error 'Error: $SNAP_PATH/plugin/snap-plugin-collector-mock2 does not exist. Run make to build it.'; } -[ -f $SNAP_PATH/plugin/snap-plugin-processor-passthru ] || { _error 'Error: $SNAP_PATH/plugin/snap-plugin-processor-passthru does not exist. Run make to build it.'; } -[ -f $SNAP_PATH/plugin/snap-plugin-publisher-mock-file ] || { _error 'Error: $SNAP_PATH/plugin/snap-plugin-publisher-mock-file does not exist. Run make to build it.'; } - _go_path # If the following tools don't exist, get them _go_get github.com/smartystreets/goconvey diff --git a/scripts/update_dns.go b/scripts/update_dns.go deleted file mode 100644 index 3a4c9ee6f..000000000 --- a/scripts/update_dns.go +++ /dev/null @@ -1,46 +0,0 @@ -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: "latest.snap.ci"}) - if err != nil { - fmt.Printf("latest.snap.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) -}