Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Included in this repo are tools shared by weave.git and scope.git. They include

- ```bazel```: Bazel build rules used in our projects
- ```build```: a set of docker base-images for building weave
projects. These should be used instead of giving each project its
own build image.
Expand Down Expand Up @@ -32,7 +33,11 @@ Included in this repo are tools shared by weave.git and scope.git. They include
## Requirements

- ```lint``` requires shfmt to lint sh files; get shfmt with
```go get -u gopkg.in/mvdan/sh.v1/cmd/shfmt```
```
curl -fsSLo shfmt https://github.com/mvdan/sh/releases/download/v1.3.0/shfmt_v1.3.0_linux_amd64
chmod +x shfmt
```
(we pin that version, and it doesn't build from the source repo any more)

## Using build-tools.git

Expand Down
26 changes: 26 additions & 0 deletions tools/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
load("@io_bazel_rules_go//proto:compiler.bzl", "go_proto_compiler")

go_proto_compiler(
name = "gogo_proto",
deps = [
"//vendor/github.com/gogo/protobuf/gogoproto:go_default_library",
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/github.com/gogo/protobuf/sortkeys:go_default_library",
],
plugin = "@com_github_gogo_protobuf//protoc-gen-gogoslick",
visibility = ["//visibility:public"],
)

go_proto_compiler(
name = "gogo_grpc",
deps = [
"//vendor/github.com/gogo/protobuf/gogoproto:go_default_library",
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/github.com/gogo/protobuf/sortkeys:go_default_library",
"//vendor/google.golang.org/grpc:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
],
plugin = "@com_github_gogo_protobuf//protoc-gen-gogoslick",
options = ["plugins=grpc"],
visibility = ["//visibility:public"],
)
36 changes: 36 additions & 0 deletions tools/bazel/gogo.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
load("@io_bazel_rules_go//go:def.bzl", "go_repository")


_BUILD_FILE = """
proto_library(
name = "gogoproto",
srcs = ["gogo.proto"],
deps = [
"@com_google_protobuf//:descriptor_proto",
],
visibility = ["//visibility:public"],
)
"""

def _go_repository_impl(ctx):
ctx.file("BUILD.bazel", content="")
ctx.file("github.com/gogo/protobuf/gogoproto/BUILD.bazel", content=_BUILD_FILE)
ctx.template("github.com/gogo/protobuf/gogoproto/gogo.proto", ctx.attr._proto)

_gogo_proto_repository = repository_rule(
implementation = _go_repository_impl,
attrs = {
"_proto": attr.label(default="//vendor/github.com/gogo/protobuf/gogoproto:gogo.proto"),
},
)

def gogo_dependencies():
go_repository(
name = "com_github_gogo_protobuf",
importpath = "github.com/gogo/protobuf",
urls = ["https://codeload.github.com/ianthehat/protobuf/zip/2adc21fd136931e0388e278825291678e1d98309"],
strip_prefix = "protobuf-2adc21fd136931e0388e278825291678e1d98309",
type = "zip",
build_file_proto_mode="disable",
)
_gogo_proto_repository(name = "internal_gogo_proto_repository")
5 changes: 3 additions & 2 deletions tools/build/golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.8.0-stretch
FROM golang:1.9.2-stretch
RUN apt-get update && \
apt-get install -y \
curl \
Expand All @@ -11,9 +11,10 @@ RUN apt-get update && \
python-pip \
python-requests \
python-yaml \
shellcheck \
unzip && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN pip install attrs pyhcl
RUN pip install attrs pyhcl yapf==0.16.2 flake8==3.3.0
RUN curl -fsSLo shfmt https://github.com/mvdan/sh/releases/download/v1.3.0/shfmt_v1.3.0_linux_amd64 && \
echo "b1925c2c405458811f0c227266402cf1868b4de529f114722c2e3a5af4ac7bb2 shfmt" | sha256sum -c && \
chmod +x shfmt && \
Expand Down
18 changes: 4 additions & 14 deletions tools/circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,13 @@ dependencies:
- go install -tags netgo std
- mkdir -p $(dirname $SRCDIR)
- cp -r $(pwd)/ $SRCDIR
- |
curl -fsSLo shfmt https://github.com/mvdan/sh/releases/download/v1.3.0/shfmt_v1.3.0_linux_amd64 && \
echo "b1925c2c405458811f0c227266402cf1868b4de529f114722c2e3a5af4ac7bb2 shfmt" | sha256sum -c && \
chmod +x shfmt && \
sudo mv shfmt /usr/bin
- |
cd $SRCDIR;
go get \
github.com/fzipp/gocyclo \
github.com/golang/lint/golint \
github.com/kisielk/errcheck \
github.com/fatih/hclfmt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hclfmt is not mentioned elsewhere?

- pip install yapf==0.16.2 flake8==3.3.0

test:
override:
- cd $SRCDIR; ./lint .
- |
cd $SRCDIR/build && \
make && \
docker run --rm -v "$SRCDIR:$SRCDIR" -w "$SRCDIR" --entrypoint sh quay.io/weaveworks/build-golang -c ./lint .
- cd $SRCDIR/cover; make
- cd $SRCDIR/socks; make
- cd $SRCDIR/runner; make
Expand Down
46 changes: 23 additions & 23 deletions tools/lint
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#
# For shell files, it runs shfmt. If you don't have that installed, you can get
# it with:
# go get -u gopkg.in/mvdan/sh.v1/cmd/shfmt
# curl -fsSLo shfmt https://github.com/mvdan/sh/releases/download/v1.3.0/shfmt_v1.3.0_linux_amd64
# chmod +x shfmt
#
# With no arguments, it lints the current files staged
# for git commit. Or you can pass it explicit filenames
Expand Down Expand Up @@ -50,14 +51,6 @@ spell_check() {
local filename="$1"
local lint_result=0

# we don't want to spell check tar balls, binaries, Makefile and json files
if file "$filename" | grep executable >/dev/null 2>&1; then
return $lint_result
fi
if [[ $filename == *".tar" || $filename == *".gz" || $filename == *".json" || $(basename "$filename") == "Makefile" ]]; then
return $lint_result
fi

# misspell is completely optional. If you don't like it
# don't have it installed.
if ! type misspell >/dev/null 2>&1; then
Expand Down Expand Up @@ -103,9 +96,11 @@ lint_go() {
# 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 -r line; do
echo "${filename}": higher than 25 cyclomatic complexity - "${line}"
done
cycloutput=$(gocyclo -over 25 "${filename}")
if [ -n "$cycloutput" ]; then
lint_result=1
echo "${filename}": higher than 25 cyclomatic complexity - "${cycloutput}"
fi
fi

return $lint_result
Expand Down Expand Up @@ -187,19 +182,24 @@ lint() {
*.pb.go) return ;;
esac

if [[ "$(file --mime-type "${filename}" | awk '{print $2}')" == "text/x-shellscript" ]]; then
ext="sh"
fi
mimetype=$(file --mime-type "${filename}" | awk '{print $2}')

case "$ext" in
go) lint_go "${filename}" || lint_result=1 ;;
sh) lint_sh "${filename}" || lint_result=1 ;;
tf) lint_tf "${filename}" || lint_result=1 ;;
md) lint_md "${filename}" || lint_result=1 ;;
py) lint_py "${filename}" || lint_result=1 ;;
case "$mimetype.$ext" in
text/x-shellscript.*) lint_sh "${filename}" || lint_result=1 ;;
*.go) lint_go "${filename}" || lint_result=1 ;;
*.tf) lint_tf "${filename}" || lint_result=1 ;;
*.md) lint_md "${filename}" || lint_result=1 ;;
*.py) lint_py "${filename}" || lint_result=1 ;;
esac

spell_check "${filename}" || lint_result=1
# we don't want to spell check tar balls, binaries, Makefile and json files
case "$mimetype.$ext" in
*.tar | *.gz | *.json) ;;
*.req | *.key | *.pem | *.crt) ;;
application/x-executable.*) ;;
text/x-makefile.*) ;;
*) spell_check "${filename}" || lint_result=1 ;;
esac

return $lint_result
}
Expand Down Expand Up @@ -242,7 +242,7 @@ filter_out() {

list_files() {
if [ $# -gt 0 ]; then
find "$@" | grep -vE '(^|/)vendor/'
find "$@" \( -name vendor -o -name .git \) -prune -o -type f
else
git ls-files --exclude-standard | grep -vE '(^|/)vendor/'
fi
Expand Down
7 changes: 3 additions & 4 deletions tools/provisioning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ You can then use these machines as is or run various Ansible playbooks from `../

* On macOS: `brew install vagrant`
* On Linux (via Aptitude): `sudo apt install vagrant`
* If you need a specific version:

curl -fsS https://releases.hashicorp.com/terraform/x.y.z/terraform_x.y.z_linux_amd64.zip | gunzip > terraform && chmod +x terraform && sudo mv terraform /usr/bin

* For other platforms or more details, see [here](https://www.vagrantup.com/docs/installation/)

* You will need [Terraform](https://www.terraform.io) installed on your machine and added to your `PATH` in order to be able to provision cloud-hosted machines automatically.

* On macOS: `brew install terraform`
* On Linux (via Aptitude): `sudo apt install terraform`
* If you need a specific version:

curl -fsS https://releases.hashicorp.com/terraform/x.y.z/terraform_x.y.z_linux_amd64.zip | gunzip > terraform && chmod +x terraform && sudo mv terraform /usr/bin
* For other platforms or more details, see [here](https://www.terraform.io/intro/getting-started/install.html)

* Depending on the cloud provider, you may have to create an account, manually onboard, create and register SSH keys, etc.
Expand Down
2 changes: 1 addition & 1 deletion tools/push-images
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ done

# Wait individually for tasks so we fail-exit on any non-zero return code
for p in $pids; do
wait $p
wait "$p"
done

wait
8 changes: 6 additions & 2 deletions tools/scheduler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ def avg(test):
r'(?P<type>[\w\-]+)$'),
]
NAME_REGEXES = [
re.compile(r'^host(?P<index>\d+)-(?P<build>\d+)-(?P<shard>\d+)$'),
re.compile(r'^test-(?P<build>\d+)-(?P<shard>\d+)-(?P<index>\d+)$'),
re.compile(pat)
for pat in (
r'^host(?P<index>\d+)-(?P<build>\d+)-(?P<shard>\d+)$',
r'^host(?P<index>\d+)-(?P<project>[a-zA-Z0-9-]+)-(?P<build>\d+)'
r'-(?P<shard>\d+)$',
r'^test-(?P<build>\d+)-(?P<shard>\d+)-(?P<index>\d+)$', )
]


Expand Down
7 changes: 6 additions & 1 deletion tools/test
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ TAGS=
PARALLEL=
RACE="-race -covermode=atomic"
TIMEOUT=1m
VERBOSE=

usage() {
echo "$0 [-slow] [-in-container foo] [-netgo] [-(no-)go-get] [-timeout 1m]"
}

while [ $# -gt 0 ]; do
case "$1" in
"-v")
VERBOSE="-v"
shift 1
;;
"-slow")
SLOW=true
shift 1
Expand Down Expand Up @@ -55,7 +60,7 @@ while [ $# -gt 0 ]; do
esac
done

GO_TEST_ARGS=(-tags "${TAGS[@]}" -cpu 4 -timeout $TIMEOUT)
GO_TEST_ARGS=(-tags "${TAGS[@]}" -cpu 4 -timeout $TIMEOUT $VERBOSE)

if [ -n "$SLOW" ] || [ -n "$CIRCLECI" ]; then
SLOW=true
Expand Down