Merge pull request #354 from weaveworks/tools

Use various scripts from tools.git
This commit is contained in:
Tom Wilkie
2015-08-18 12:21:56 +01:00
8 changed files with 28 additions and 244 deletions

View File

@@ -61,7 +61,7 @@ client-sync:
-v $(shell pwd)/client/build:/home/weave/build \
$(SCOPE_UI_BUILD_IMAGE) gulp sync
$(SCOPE_UI_BUILD_EXPORT): client/Dockerfile client/gulpfile.js client/package.json
$(SCOPE_UI_BUILD_EXPORT): client/Dockerfile client/gulpfile.js client/package.json client/webpack.config.js client/.eslintrc
docker build -t $(SCOPE_UI_BUILD_IMAGE) client
docker save $(SCOPE_UI_BUILD_IMAGE):latest > $@

133
bin/lint
View File

@@ -1,133 +0,0 @@
#!/bin/bash
# This scipt lints go files for common errors.
#
# Its runs gofmt and go vet, and optionally golint and
# gocyclo, if they are installed.
#
# With no arguments, it lints the current files staged
# for git commit. Or you can pass it explicit filenames
# (or directories) and it will lint them.
#
# To use this script automatically, run:
# ln -s ../../bin/lint .git/hooks/pre-commit
set -eu
function spell_check {
filename="$1"
local lint_result=0
if grep -iH --color=always psueod "${filename}"; then
echo "${filename}: spelling mistake"
lint_result=1
fi
return $lint_result
}
function test_mismatch {
filename="$1"
package=$(grep '^package ' $filename | awk '{print $2}')
local lint_result=0
if [[ $package == "main" ]]; then
continue # in package main, all bets are off
fi
if [[ $filename == *"_internal_test.go" ]]; then
if [[ $package == *"_test" ]]; then
lint_result=1
echo "${filename}: should not be part of a _test package"
fi
else
if [[ ! $package == *"_test" ]]; then
lint_result=1
echo "${filename}: should be part of a _test package"
fi
fi
return $lint_result
}
function lint_go {
filename="$1"
local lint_result=0
if [ -n "$(gofmt -s -l "${filename}")" ]; then
lint_result=1
echo "${filename}: run gofmt -s -w ${filename}!"
fi
go tool vet "${filename}" || lint_result=$?
# golint is completely optional. If you don't like it
# don't have it installed.
if type golint >/dev/null 2>&1; then
# golint doesn't set an exit code it seems
lintoutput=$(golint "${filename}")
if [ "$lintoutput" != "" ]; then
lint_result=1
echo "$lintoutput"
fi
fi
# gocyclo is completely optional. If you don't like it
# don't have it installed. Also never blocks a commit,
# it just warns.
if type gocyclo >/dev/null 2>&1; then
gocyclo -over 25 "${filename}" | while read line; do
echo "${filename}": higher than 25 cyclomatic complexity - "${line}"
done
fi
return $lint_result
}
function lint {
filename="$1"
ext="${filename##*\.}"
local lint_result=0
# Don't lint deleted files
if [ ! -f "$filename" ]; then
return
fi
# Don't lint this script or static.go
case "${filename}" in
./bin/lint) return;;
./app/static.go) return;;
./coverage.html) return;;
esac
case "$ext" in
go) lint_go "${filename}" || lint_result=1
;;
esac
if [[ $filename == *"_test.go" ]]; then
test_mismatch "${filename}" || lint_result=1
fi
spell_check "${filename}" || lint_result=1
return $lint_result
}
function lint_files {
local lint_result=0
while read filename; do
lint "${filename}" || lint_result=1
done
exit $lint_result
}
function list_files {
if [ $# -gt 0 ]; then
find "$@" -type f | grep -vE '^\./\.git/'
else
git diff --cached --name-only
fi
}
list_files "$@" | lint_files

View File

@@ -1,39 +0,0 @@
#!/bin/bash
set -eux
CACHE_DIR=$HOME/docker/
rebuild() {
rm $CACHE_DIR/* || true
make scope_ui_build.tar
mkdir -p $CACHE_DIR
mv scope_ui_build.tar $CACHE_DIR/image-$CIRCLE_SHA1
}
# Get the revision the cached image was build at
cached_image_rev() {
find $CACHE_DIR -name 'image-*' -type f | sed 's/[^\-]*\-//'
}
# Have there been any revision beween $1 and $2
has_changes() {
local rev1=$1
local rev2=$2
local changes=$(git log --oneline $rev1..$rev2 -- client/Dockerfile client/gulpfile.js client/package.json | wc -l)
[ "$changes" -gt 0 ]
}
cached_revision=$(cached_image_rev)
if [ -z "$cached_revision" ]; then
rebuild
exit 0
fi
if has_changes $cached_revision $CIRCLE_SHA1 ; then
rebuild
exit 0
fi
# we didn't rebuild; import cached version
docker load -i $CACHE_DIR/image-*

View File

@@ -1,43 +0,0 @@
#!/bin/sh
set -eu
GO_TEST_ARGS="-cpu 4 -timeout 10s -tags netgo"
SLOW=""
if [ $# -eq 1 ] && [ "$1" = "-slow" ]; then
GO_TEST_ARGS="$GO_TEST_ARGS -race -covermode=atomic"
SLOW="yes"
fi
echo "mode: count" > profile.cov
fail=0
for dir in $(find . -type f -name '*_test.go' | grep -v '^./.git/' | grep -v '^./experimental/' | grep -v '^./releases/' | xargs -n1 dirname | sort -u); do
if [ "$SLOW" = "yes" ]; then
go get -t $dir
if ! errcheck -ignore 'Close' $dir ; then
fail=1
fi
output=$(mktemp cover.XXXXXXXXXX)
GO_TEST_ARGS_RUN="$GO_TEST_ARGS -coverprofile=$output"
else
GO_TEST_ARGS_RUN="$GO_TEST_ARGS"
fi
if ! go test $GO_TEST_ARGS_RUN $dir ; then
fail=1
fi
if [ "$SLOW" = "yes" ] && [ -f $output ]; then
tail -n +2 <$output >>profile.cov
rm $output
fi
done
if [ "$SLOW" = "yes" ]; then
go tool cover -html=profile.cov -o=coverage.html
fi
exit $fail

View File

@@ -8,6 +8,7 @@ machine:
- docker
environment:
GOPATH: /home/ubuntu:$GOPATH
TOOLS: /home/ubuntu/src/github.com/weaveworks/tools
SRCDIR: /home/ubuntu/src/github.com/weaveworks/scope
PATH: $PATH:$HOME/.local/bin
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
@@ -18,30 +19,31 @@ machine:
dependencies:
cache_directories:
- "~/docker"
override:
post:
- mkdir -p $TOOLS
- git clone https://github.com/weaveworks/tools.git $TOOLS
- sudo apt-get update
- sudo apt-get --only-upgrade install tar libpcap0.8-dev
- bin/rebuild-ui-build-image
- sudo apt-get install jq
- curl https://sdk.cloud.google.com | bash
- test -z "$SECRET_PASSWORD" || bin/setup-circleci-secrets "$SECRET_PASSWORD"
post:
- go get $WEAVE_REPO/...
- make -C $WEAVE_ROOT testing/runner/runner
- sudo apt-get install jq
- go version
- go clean -i net
- go install -tags netgo std
- make deps
- mkdir -p $(dirname $SRCDIR)
- cp -r $(pwd)/ $SRCDIR
- cd $SRCDIR/client; $TOOLS/rebuild-image weaveworks/scope-ui-build . Dockerfile gulpfile.js package.json webpack.config.js .eslintrc
test:
override:
- cd $SRCDIR; ./bin/lint .
- cd $SRCDIR; $TOOLS/lint .
- cd $SRCDIR; make client-test
- cd $SRCDIR; make static
- cd $SRCDIR; rm -f app/scope-app probe/scope-probe; make
- cd $SRCDIR; ./bin/test -slow
- cd $SRCDIR; $TOOLS/test -slow
- cd $SRCDIR/experimental; make
- test -z "$SECRET_PASSWORD" || (cd $SRCDIR/integration; ./gce.sh setup)
- test -z "$SECRET_PASSWORD" || (cd $SRCDIR/integration; eval $(./gce.sh hosts); ./setup.sh)

View File

@@ -1,19 +1,6 @@
FROM debian:latest
FROM node:0.10
WORKDIR /home/weave
RUN apt-get update && apt-get install -y curl bzip2 libfreetype6 libfontconfig1
# Install nodejs
RUN curl -sL https://deb.nodesource.com/setup | bash -
RUN apt-get install -y nodejs
# build tool
RUN npm install -g gulp
# install app and build dependencies
ADD package.json /home/weave/
COPY package.json /home/weave/
RUN npm install
ADD gulpfile.js webpack.config.js .eslintrc /home/weave/
# For instructions on running this container, consult the toplevel Makefile
COPY gulpfile.js webpack.config.js .eslintrc /home/weave/

View File

@@ -51,16 +51,17 @@
"gulp-util": "^3.0.4",
"istanbul-instrumenter-loader": "^0.1.3",
"jasmine-core": "^2.3.4",
"karma": "^0.12.33",
"karma": "^0.13.3",
"karma-cli": "0.0.4",
"karma-coverage": "^0.4.2",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "^0.1.4",
"karma-webpack": "^1.5.1",
"karma-webpack": "^1.7.0",
"less": "^2.5.1",
"less-loader": "^2.2.0",
"minimist": "^1.1.1",
"node-libs-browser": "^0.5.2",
"phantomjs": "^1.9.18",
"postcss-loader": "^0.4.3",
"proxy-middleware": "^0.12.0",
"react-tools": "^0.13.3",

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"net"
"runtime"
"sync"
"testing"
"time"
@@ -18,14 +19,22 @@ func TestResolver(t *testing.T) {
oldLookupIP := lookupIP
defer func() { lookupIP = oldLookupIP }()
ipsLock := sync.Mutex{}
ips := map[string][]net.IP{}
lookupIP = func(host string) ([]net.IP, error) {
ipsLock.Lock()
defer ipsLock.Unlock()
addrs, ok := ips[host]
if !ok {
return nil, fmt.Errorf("Not found")
}
return addrs, nil
}
updateIPs := func(key string, values []net.IP) {
ipsLock.Lock()
defer ipsLock.Unlock()
ips = map[string][]net.IP{key: values}
}
port := ":80"
ip1 := "192.168.0.1"
@@ -42,8 +51,8 @@ func TestResolver(t *testing.T) {
if want != have {
t.Errorf("line %d: want %q, have %q", line, want, have)
}
case <-time.After(time.Millisecond):
t.Errorf("line %d: didn't get add in time", line)
case <-time.After(100 * time.Millisecond):
t.Fatalf("line %d: didn't get add in time", line)
}
}
@@ -58,14 +67,14 @@ func TestResolver(t *testing.T) {
assertAdd(fmt.Sprintf("%s:%d", ip2, xfer.AppPort))
ip3 := "1.2.3.4"
ips = map[string][]net.IP{"symbolic.name": makeIPs(ip3)}
updateIPs("symbolic.name", makeIPs(ip3))
c <- time.Now() // trigger a resolve
assertAdd(ip3 + port) // we want 1 add
assertAdd(ip1 + port)
assertAdd(fmt.Sprintf("%s:%d", ip2, xfer.AppPort))
ip4 := "10.10.10.10"
ips = map[string][]net.IP{"symbolic.name": makeIPs(ip3, ip4)}
updateIPs("symbolic.name", makeIPs(ip3, ip4))
c <- time.Now() // trigger another resolve, this time with 2 adds
assertAdd(ip3 + port) // first add
assertAdd(ip4 + port) // second add