From 90e1300aa62aa7e02cbaa001b8adb9e5d05d693c Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Wed, 28 Jun 2017 14:38:20 +0300 Subject: [PATCH] Use Docker Compose on Travis CI and local dev. --- .gitignore | 2 ++ .travis.yml | 21 ++++++++++++++++++--- CONTRIBUTING.md | 20 ++++++++++++++++++++ Makefile | 30 +++++++++++++++++++++++++++++- docker-compose.yml | 8 ++++++++ 5 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore index 919ab702e..01a985085 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ mongodb_exporter +coverage.txt +coverage_temp.txt diff --git a/.travis.yml b/.travis.yml index ad1bf3cd3..63a08067c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,25 @@ -sudo: false +dist: trusty +sudo: required language: go go: - - 1.7.x - 1.8.x - tip +env: + - MONGODB_IMAGE=mongo:3.4 + - MONGODB_IMAGE=percona/percona-server-mongodb:3.4 + +services: + - docker + +before_script: + - docker --version + - docker-compose --version + - docker-compose up -d + script: - - make + - make format build testall + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..5e7a7cb56 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,20 @@ +# Contributing notes + +## Local setup + +The easiest way to make a local development setup is to use Docker Compose. + +``` +docker-compose up +make all testall +export MONGODB_URL='mongodb://localhost:27017' +./mongodb_exporter +``` + +`testall` make target will run integration tests. + + +## Vendoring + +We use [Glide](https://glide.sh) to vendor dependencies. Please use released version of Glide (i.e. do not `go get` +from `master` branch). Also please use `--strip-vendor` flag. diff --git a/Makefile b/Makefile index 9c4096412..c46bf9496 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,17 @@ +# Copyright 2015 The Prometheus Authors +# Copyright 2017 Percona LLC +# 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. + GO := go FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) PROMU := $(FIRST_GOPATH)/bin/promu -v @@ -17,7 +31,21 @@ style: test: @echo ">> running tests" - @$(GO) test -short -race $(pkgs) + rm -f coverage.txt + for p in $(pkgs); do \ + rm -f coverage_temp.txt ; \ + $(GO) test -v -short -race -covermode atomic -coverprofile coverage_temp.txt $$p ; \ + cat coverage_temp.txt >> coverage.txt ; \ + done + +testall: + @echo ">> running all tests" + rm -f coverage.txt + for p in $(pkgs); do \ + rm -f coverage_temp.txt ; \ + $(GO) test -v -race -covermode atomic -coverprofile coverage_temp.txt $$p ; \ + cat coverage_temp.txt >> coverage.txt ; \ + done format: @echo ">> formatting code" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..fcee1672d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +# see CONTRIBUTING.md +--- +version: '3' +services: + mongo: + image: ${MONGODB_IMAGE:-mongo:3.4} + ports: + - 127.0.0.1:27017:27017