Unverified Commit 1645bb4d authored by Ben Kochie's avatar Ben Kochie Committed by GitHub

Update build (#276)

* Update build

* Update to circleci 2.0
* Update Makefile to use Prometheus Makefile.common.
Signed-off-by: 's avatarBen Kochie <superq@gmail.com>

* Fix spelling typos.
Signed-off-by: 's avatarBen Kochie <superq@gmail.com>

* Add percona server to docker test.

* Run the latest percona-server docker image.
* Set a `mysql-test` docker network.
Signed-off-by: 's avatarBen Kochie <superq@gmail.com>

* Update Travis go versions.
Signed-off-by: 's avatarBen Kochie <superq@gmail.com>

* Update README

* Recommend docker network, as link is deprecated.
* Make DSN example more consistent.
Signed-off-by: 's avatarBen Kochie <superq@gmail.com>
parent 79020cb5
---
version: 2
jobs:
test:
docker:
- image: circleci/golang:1.10
working_directory: /go/src/github.com/prometheus/mysqld_exporter
steps:
- checkout
- run: make promu
- run: make
- run: rm -v mysqld_exporter
codespell:
docker:
- image: circleci/python
steps:
- checkout
- run: sudo pip install codespell
- run: codespell --skip=".git,./vendor,ttar"
build:
machine: true
working_directory: /home/circleci/.go_workspace/src/github.com/prometheus/mysqld_exporter
environment:
DOCKER_IMAGE_NAME: prom/mysqld-exporter
QUAY_IMAGE_NAME: quay.io/prometheus/mysqld-exporter
DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.10-base
REPO_PATH: github.com/prometheus/mysqld_exporter
steps:
- checkout
- run: make promu
- run: promu crossbuild -v
- persist_to_workspace:
root: .
paths:
- .build
- run: ln -s .build/linux-amd64/mysqld_exporter mysqld_exporter
- run:
command: |
if [ -n "$CIRCLE_TAG" ]; then
make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG
make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG
else
make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME
make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME
fi
- run: docker images
- run: docker network create mysql-test
- run: docker run --network mysql-test -e MYSQL_ROOT_PASSWORD=secret -p 3306:3306 -d percona/percona-server:latest
- run: docker run --rm -t -v "$(pwd):/app" "${DOCKER_TEST_IMAGE_NAME}" -i "${REPO_PATH}" -T
- run:
command: |
if [ -n "$CIRCLE_TAG" ]; then
make test-docker DOCKER_IMAGE_TAG=$CIRCLE_TAG
else
make test-docker
fi
docker_hub_master:
docker:
- image: circleci/golang:1.10
working_directory: /go/src/github.com/prometheus/mysqld_exporter
environment:
DOCKER_IMAGE_NAME: prom/mysqld-exporter
QUAY_IMAGE_NAME: quay.io/prometheus/mysqld-exporter
DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.10-base
REPO_PATH: github.com/prometheus/mysqld_exporter
steps:
- checkout
- setup_remote_docker
- attach_workspace:
at: .
- run: ln -s .build/linux-amd64/mysqld_exporter mysqld_exporter
- run: make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME
- run: make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME
- run: docker images
- run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
- run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io
- run: docker push $DOCKER_IMAGE_NAME
- run: docker push $QUAY_IMAGE_NAME
docker_hub_release_tags:
docker:
- image: circleci/golang:1.10
working_directory: /go/src/github.com/prometheus/mysqld_exporter
environment:
DOCKER_IMAGE_NAME: prom/mysqld-exporter
QUAY_IMAGE_NAME: quay.io/prometheus/mysqld-exporter
DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.10-base
REPO_PATH: github.com/prometheus/mysqld_exporter
steps:
- checkout
- setup_remote_docker
- run: mkdir -v -p ${HOME}/bin
- run: curl -L 'https://github.com/aktau/github-release/releases/download/v0.7.2/linux-amd64-github-release.tar.bz2' | tar xvjf - --strip-components 3 -C ${HOME}/bin
- run: echo 'export PATH=${HOME}/bin:${PATH}' >> ${BASH_ENV}
- attach_workspace:
at: .
- run: make promu
- run: promu crossbuild tarballs
- run: promu checksum .tarballs
- run: promu release .tarballs
- store_artifacts:
path: .tarballs
destination: releases
- run: ln -s .build/linux-amd64/mysqld_exporter mysqld_exporter
- run:
command: |
if [ -n "$CIRCLE_TAG" ]; then
make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG
make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG
else
make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME
make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME
fi
- run: docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
- run: docker login -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io
- run: |
if [[ "$CIRCLE_TAG" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then
docker tag "$DOCKER_IMAGE_NAME:$CIRCLE_TAG" "$DOCKER_IMAGE_NAME:latest"
docker tag "$QUAY_IMAGE_NAME:$CIRCLE_TAG" "$QUAY_IMAGE_NAME:latest"
fi
- run: docker push $DOCKER_IMAGE_NAME:$CIRCLE_TAG
- run: docker push $QUAY_IMAGE_NAME:$CIRCLE_TAG
workflows:
version: 2
mysqld_exporter:
jobs:
- test:
filters:
tags:
only: /.*/
- build:
filters:
tags:
only: /.*/
- codespell:
filters:
tags:
only: /.*/
- docker_hub_master:
requires:
- test
- build
filters:
branches:
only: master
- docker_hub_release_tags:
requires:
- test
- build
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
......@@ -3,9 +3,8 @@ sudo: required
language: go
go:
- 1.8.x
- 1.9.x
- master
- 1.10.x
env:
- MYSQL_IMAGE=mysql/mysql-server:5.5
......
......@@ -11,55 +11,17 @@
# 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
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
all: vet
PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_NAME ?= mysqld-exporter
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
include Makefile.common
STATICCHECK_IGNORE = \
github.com/prometheus/mysqld_exporter/mysqld_exporter.go:SA1019
all: format build test-short
DOCKER_IMAGE_NAME ?= mysqld-exporter
style:
@echo ">> checking code style"
@! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
test-docker:
@echo ">> testing docker image"
./test_image.sh "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" 9104
test-short:
@echo ">> running short tests"
@$(GO) test -short -race $(pkgs)
test:
@echo ">> running tests"
@$(GO) test -race $(pkgs)
format:
@echo ">> formatting code"
@$(GO) fmt $(pkgs)
vet:
@echo ">> vetting code"
@$(GO) vet $(pkgs)
build: promu
@echo ">> building binaries"
@$(PROMU) build --prefix $(PREFIX)
tarball: promu
@echo ">> building release tarball"
@$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
docker:
@echo ">> building docker image"
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
promu:
@GOOS=$(shell uname -s | tr A-Z a-z) \
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
$(GO) get -u github.com/prometheus/promu
.PHONY: all style format build test vet tarball docker promu
.PHONY: test-docker
# Copyright 2018 The Prometheus Authors
# 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.
# A common Makefile that includes rules to be reused in different prometheus projects.
# !!! Open PRs only against the prometheus/prometheus/Makefile.common repository!
# Example usage :
# Create the main Makefile in the root project directory.
# include Makefile.common
# customTarget:
# @echo ">> Running customTarget"
#
# Ensure GOBIN is not set during build so that promu is installed to the correct path
unexport GOBIN
GO ?= go
GOFMT ?= $(GO)fmt
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
PROMU := $(FIRST_GOPATH)/bin/promu
STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck
GOVENDOR := $(FIRST_GOPATH)/bin/govendor
pkgs = ./...
PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
all: style staticcheck unused build test
style:
@echo ">> checking code style"
! $(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
check_license:
@echo ">> checking license header"
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
done); \
if [ -n "$${licRes}" ]; then \
echo "license header checking failed:"; echo "$${licRes}"; \
exit 1; \
fi
test-short:
@echo ">> running short tests"
$(GO) test -short $(pkgs)
test:
@echo ">> running all tests"
$(GO) test -race $(pkgs)
format:
@echo ">> formatting code"
$(GO) fmt $(pkgs)
vet:
@echo ">> vetting code"
$(GO) vet $(pkgs)
staticcheck: $(STATICCHECK)
@echo ">> running staticcheck"
$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
unused: $(GOVENDOR)
@echo ">> running check for unused packages"
@$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
build: promu
@echo ">> building binaries"
$(PROMU) build --prefix $(PREFIX)
tarball: promu
@echo ">> building release tarball"
$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
docker:
docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
promu:
GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu
$(FIRST_GOPATH)/bin/staticcheck:
GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck
$(FIRST_GOPATH)/bin/govendor:
GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
.PHONY: all style check_license format build test vet assets tarball docker promu staticcheck $(FIRST_GOPATH)/bin/staticcheck govendor $(FIRST_GOPATH)/bin/govendor
\ No newline at end of file
......@@ -28,7 +28,7 @@ NOTE: It is recommended to set a max connection limit for the user to avoid over
Running using an environment variable:
export DATA_SOURCE_NAME='login:password@(hostname:port)/'
export DATA_SOURCE_NAME='user:password@(hostname:3306)/'
./mysqld_exporter <flags>
Running using ~/.my.cnf:
......@@ -106,10 +106,14 @@ You can deploy this exporter using the [prom/mysqld-exporter](https://registry.h
For example:
```bash
docker network create my-mysql-network
docker pull prom/mysqld-exporter
docker run -d -p 9104:9104 --link=my_mysql_container:bdd \
-e DATA_SOURCE_NAME="user:password@(bdd:3306)/database" prom/mysqld-exporter
docker run -d \
-p 9104:9104 \
--network my-mysql-network \
-e DATA_SOURCE_NAME="user:password@(my-mysql-network:3306)/" \
prom/mysqld-exporter
```
## heartbeat
......
machine:
environment:
DOCKER_IMAGE_NAME: prom/mysqld-exporter
QUAY_IMAGE_NAME: quay.io/prometheus/mysqld-exporter
DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.8-base
REPO_PATH: github.com/prometheus/mysqld_exporter
pre:
- sudo curl -L -o /usr/bin/docker 'https://s3-external-1.amazonaws.com/circle-downloads/docker-1.9.1-circleci'
- sudo chmod 0755 /usr/bin/docker
- sudo curl -L 'https://github.com/aktau/github-release/releases/download/v0.6.2/linux-amd64-github-release.tar.bz2' | tar xvjf - --strip-components 3 -C $HOME/bin
services:
- docker
dependencies:
pre:
- make promu
- docker info
override:
- promu crossbuild
- ln -s .build/linux-amd64/mysqld_exporter mysqld_exporter
- |
if [ -n "$CIRCLE_TAG" ]; then
make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG
make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG
else
make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME
make docker DOCKER_IMAGE_NAME=$QUAY_IMAGE_NAME
fi
post:
- mkdir $CIRCLE_ARTIFACTS/binaries/ && cp -a .build/* $CIRCLE_ARTIFACTS/binaries/
- docker images
test:
override:
- docker run --rm -t -v "$(pwd):/app" "${DOCKER_TEST_IMAGE_NAME}" -i "${REPO_PATH}" -T
deployment:
hub_branch:
branch: master
owner: prometheus
commands:
- docker login -e $DOCKER_EMAIL -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
- docker login -e $QUAY_EMAIL -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io
- docker push $DOCKER_IMAGE_NAME
- docker push $QUAY_IMAGE_NAME
hub_tag:
tag: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/
owner: prometheus
commands:
- promu crossbuild tarballs
- promu checksum .tarballs
- promu release .tarballs
- mkdir $CIRCLE_ARTIFACTS/releases/ && cp -a .tarballs/* $CIRCLE_ARTIFACTS/releases/
- docker login -e $DOCKER_EMAIL -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
- docker login -e $QUAY_EMAIL -u $QUAY_LOGIN -p $QUAY_PASSWORD quay.io
- |
if [[ "$CIRCLE_TAG" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then
docker tag "$DOCKER_IMAGE_NAME:$CIRCLE_TAG" "$DOCKER_IMAGE_NAME:latest"
docker tag "$QUAY_IMAGE_NAME:$CIRCLE_TAG" "$QUAY_IMAGE_NAME:latest"
fi
- docker push $DOCKER_IMAGE_NAME
- docker push $QUAY_IMAGE_NAME
......@@ -47,6 +47,6 @@ func TestScrapeBinlogSize(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -160,6 +160,6 @@ END OF INNODB MONITOR OUTPUT
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -64,6 +64,6 @@ func TestScrapeEngineTokudbStatus(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -13,7 +13,7 @@ import (
const (
// Scrape query
globalStatusQuery = `SHOW GLOBAL STATUS`
// Subsytem.
// Subsystem.
globalStatus = "global_status"
)
......
......@@ -68,6 +68,6 @@ func TestScrapeGlobalStatus(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -64,7 +64,7 @@ func TestScrapeGlobalVariables(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......
......@@ -44,6 +44,6 @@ func TestScrapeHeartbeat(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -65,6 +65,6 @@ func TestScrapeClientStat(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -64,6 +64,6 @@ func TestScrapeInnodbMetrics(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -47,6 +47,6 @@ func TestScrapeInfoSchemaInnodbTablespaces(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -73,6 +73,6 @@ func TestScrapeQueryResponseTime(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -53,6 +53,6 @@ func TestScrapeTableStat(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -65,6 +65,6 @@ func TestScrapeUserStat(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -62,6 +62,6 @@ func TestScrapePerfFileInstances(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -56,6 +56,6 @@ func TestScrapePerfIndexIOWaits(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
......@@ -44,6 +44,6 @@ func TestScrapeSlaveStatus(t *testing.T) {
// Ensure all SQL queries were executed
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
t.Errorf("there were unfulfilled exceptions: %s", err)
}
}
#!/bin/bash
set -exo pipefail
docker_image=$1
port=$2
container_id=''
wait_start() {
for in in {1..10}; do
if /usr/bin/curl -s -m 5 -f "http://localhost:${port}/metrics" > /dev/null; then
docker_cleanup
exit 0
else
sleep 1
fi
done
exit 1
}
docker_start() {
container_id=$(docker run -d --network mysql-test -e DATA_SOURCE_NAME="root:secret@(mysql-test:3306)/" -p "${port}":"${port}" "${docker_image}")
}
docker_cleanup() {
docker kill "${container_id}"
}
if [[ "$#" -ne 2 ]] ; then
echo "Usage: $0 quay.io/prometheus/mysqld-exporter:v0.10.0 9104" >&2
exit 1
fi
docker_start
wait_start
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment