diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..69c69453 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.build/ +.tarballs/ + +!.build/linux-amd64/ diff --git a/.gitignore b/.gitignore index 8fd5c323..65cc726b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,29 @@ -build/ -dist/ -*.pyc -*.egg-info +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +dependencies-stamp +/snmp_exporter +/.build +/.release +/.tarballs +.deps +*.tar.gz diff --git a/.promu.yml b/.promu.yml new file mode 100644 index 00000000..4cb42986 --- /dev/null +++ b/.promu.yml @@ -0,0 +1,15 @@ +repository: + path: github.com/prometheus/snmp_exporter +build: + flags: -a -tags netgo + ldflags: | + -X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}} + -X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}} + -X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}} + -X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}} + -X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}} +tarball: + files: + - snmp.yml + - LICENSE + - NOTICE diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..24225ea4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +sudo: false + +language: go + +go: +- 1.5.4 +- 1.6.2 + +script: +- make diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..7b2f7cd2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM quay.io/prometheus/busybox:latest +MAINTAINER The Prometheus Authors + +COPY snmp_exporter /bin/snmp_exporter +COPY snmp.yml /etc/snmp_exporter/snmp.yml + +EXPOSE 9116 +ENTRYPOINT [ "/bin/snmp_exporter" ] +CMD [ "-config.file=/etc/snmp_exporter/snmp.yml" ] diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..ffbad58a --- /dev/null +++ b/Makefile @@ -0,0 +1,60 @@ +# Copyright 2016 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. + +GO := GO15VENDOREXPERIMENT=1 go +PROMU := $(GOPATH)/bin/promu +pkgs = $(shell $(GO) list ./... | grep -v /vendor/) + +PREFIX ?= $(shell pwd) +BIN_DIR ?= $(shell pwd) +DOCKER_IMAGE_NAME ?= blackbox-exporter +DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) + + +all: format build test + +style: + @echo ">> checking code style" + @! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' + +test: + @echo ">> running tests" + @$(GO) test -short $(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 diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..1750564f --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.6 diff --git a/circle.yml b/circle.yml new file mode 100644 index 00000000..222f3ef8 --- /dev/null +++ b/circle.yml @@ -0,0 +1,61 @@ +machine: + environment: + DOCKER_IMAGE_NAME: prom/snmp-exporter + QUAY_IMAGE_NAME: quay.io/prometheus/snmp-exporter + DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.6-base + REPO_PATH: github.com/prometheus/snmp_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/snmp_exporter snmp_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 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