Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Update snap build scripts (#1027)
Browse files Browse the repository at this point in the history
* gofmt is asleep at the wheel in current test.

* Update snap build scripts

* make SNAP_PATH optional.
* remove options around build-plugins.
* use test as branch name when checking out git ref.
* fix docker test so it works regardless of directory.
* simplify travis.ci config.

* Make sure gopath and path configured correctly.
  • Loading branch information
nanliu authored and pittma committed Jul 1, 2016
1 parent 47b789c commit cc4eda7
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 220 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ go:
- 1.6.2
before_install:
- bash scripts/gitcookie.sh
- go get github.com/tools/godep
- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/goimports
- go get github.com/smartystreets/goconvey/convey
- 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
- go get golang.org/x/tools/cmd/cover
env:
global:
- SNAP_SOURCE=/home/travis/gopath/src/github.com/intelsdi-x/snap
- SNAP_PATH=/home/travis/gopath/src/github.com/intelsdi-x/snap/build
- GO15VENDOREXPERIMENT=1
matrix:
- SNAP_TEST_TYPE=legacy
Expand Down
14 changes: 6 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,19 @@ default:
deps:
bash -c "./scripts/deps.sh"
test:
export SNAP_PATH=`pwd`/build; bash -c "./scripts/test.sh $(SNAP_TEST_TYPE)"
bash -c "./scripts/test.sh $(SNAP_TEST_TYPE)"
test-legacy:
export SNAP_PATH=`pwd`/build; bash -c "./scripts/test.sh legacy"
bash -c "./scripts/test.sh legacy"
test-small:
export SNAP_PATH=`pwd`/build; bash -c "./scripts/test.sh small"
bash -c "./scripts/test.sh small"
test-medium:
export SNAP_PATH=`pwd`/build; bash -c "./scripts/test.sh medium"
bash -c "./scripts/test.sh medium"
test-large:
export SNAP_PATH=`pwd`/build; bash -c "./scripts/test.sh large"
bash -c "./scripts/test.sh large"
check:
$(MAKE) test
all:
bash -c "./scripts/build.sh $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) true"
snap:
bash -c "./scripts/build.sh $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))"
bash -c "./scripts/build_snap.sh"
install:
cp build/bin/snapd /usr/local/bin/
cp build/bin/snapctl /usr/local/bin/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,3 @@ func TestGetConfigPolicy(t *testing.T) {
So(configPolicy, ShouldNotBeNil)
})
}

5 changes: 3 additions & 2 deletions plugin/publisher/snap-publisher-file/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (
"errors"
"fmt"
"os"
"strings"

log "github.com/Sirupsen/logrus"

"github.com/intelsdi-x/snap/control/plugin"
"github.com/intelsdi-x/snap/control/plugin/cpolicy"
"github.com/intelsdi-x/snap/core/ctypes"
"strings"
)

const (
Expand Down Expand Up @@ -81,6 +81,7 @@ func (f *filePublisher) Publish(contentType string, content []byte, config map[s

return nil
}

// formatMetricTagsAsString returns metric's tags as a string in the following format tagKey:tagValue where the next tags are separated by semicolon
func formatMetricTagsAsString(metricTags map[string]string) string {
var tags string
Expand All @@ -90,7 +91,7 @@ func formatMetricTagsAsString(metricTags map[string]string) string {
// trim the last semicolon
tags = strings.TrimSuffix(tags, "; ")

return "tags["+tags+"]"
return "tags[" + tags + "]"
}

func Meta() *plugin.PluginMeta {
Expand Down
10 changes: 2 additions & 8 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
FROM golang:latest
FROM golang:latest
ENV GOPATH=$GOPATH:/app
ENV SNAP_PATH=/go/src/github.com/intelsdi-x/snap/build
RUN apt-get update && \
apt-get -y install facter
RUN apt-get update
WORKDIR /go/src/github.com/intelsdi-x/
RUN git clone https://github.com/intelsdi-x/gomit.git
WORKDIR /go/src/github.com/intelsdi-x/snap
ADD . /go/src/github.com/intelsdi-x/snap
RUN go get github.com/tools/godep && \
go get golang.org/x/tools/cmd/goimports && \
go get golang.org/x/tools/cmd/cover && \
go get github.com/smartystreets/goconvey
RUN scripts/deps.sh
RUN make
88 changes: 0 additions & 88 deletions scripts/build.sh

This file was deleted.

26 changes: 20 additions & 6 deletions scripts/build-plugin.sh → scripts/build_plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,24 @@
#See the License for the specific language governing permissions and
#limitations under the License.

BUILDCMD='go build -a -ldflags "-w"'
BUILDDIR=$1
PLUGIN=$2
PLUGINNAME=`echo $PLUGIN | grep -oh "snap-.*"`
set -e
set -u
set -o pipefail

echo " $PLUGINNAME => $BUILDDIR"
$BUILDCMD -o $BUILDDIR/$PLUGINNAME $PLUGIN || exit 2
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__proj_dir="$(dirname "$__dir")"

# shellcheck source=scripts/common.sh
. "${__dir}/common.sh"

build_dir="${__proj_dir}/build"
plugin_dir="${build_dir}/plugin"

plugin_src_path=$1
plugin_name=$(basename "${plugin_src_path}")
go_build=(go build -a -ldflags "-w")

_debug "plugin source: ${plugin_src_path}"
_info "building ${plugin_name}"

(cd "${plugin_src_path}" && "${go_build[@]}" -o "${plugin_dir}/${plugin_name}" . || exit 1)
65 changes: 65 additions & 0 deletions scripts/build_snap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

#http://www.apache.org/licenses/LICENSE-2.0.txt
#
#
#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
#
# 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.

git_branch=$(git symbolic-ref HEAD 2> /dev/null | cut -b 12-)
git_branch="${git_branch:-test}"
git_sha=$(git log --pretty=format:"%h" -1)
git_version=$(git describe --always --exact-match 2> /dev/null || echo "${git_branch}-${git_sha}")

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"

_info "project path: ${__proj_dir}"

build_dir="${__proj_dir}/build"
bin_dir="${build_dir}/bin"
plugin_dir="${build_dir}/plugin"
go_build=(go build -ldflags "-w -X main.gitversion=${git_version}")

_info "snap build version: ${git_version}"
_info "git commit: $(git log --pretty=format:"%H" -1)"

# Disable CGO for builds.
export CGO_ENABLED=0

# rebuild binaries:
_debug "removing: ${bin_dir:?}/*"
rm -rf "${bin_dir:?}/"*
mkdir -p "${bin_dir}"

_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)

# rebuild plugins:
_debug "removing: ${plugin_dir:?}/*"
rm -rf "${plugin_dir:?}/"*
mkdir -p "${plugin_dir}"

_info "building plugins"
find "${__proj_dir}/plugin/" -type d -iname "snap-*" -print0 | xargs -0 -n 1 -I{} "${__dir}/build_plugin.sh" {}
Loading

0 comments on commit cc4eda7

Please sign in to comment.