From 2357ae19d36e35d7ac75957da4501a0793b00fef Mon Sep 17 00:00:00 2001 From: Ruben Homs Date: Fri, 20 Apr 2018 11:45:28 +0200 Subject: [PATCH] Add build tools, readying for release --- .promu.yml | 27 +++++++++++++++++++ Dockerfile | 8 ++++++ Makefile | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ VERSION | 1 + 4 files changed, 113 insertions(+) create mode 100644 .promu.yml create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 VERSION diff --git a/.promu.yml b/.promu.yml new file mode 100644 index 0000000..0f7c2f3 --- /dev/null +++ b/.promu.yml @@ -0,0 +1,27 @@ +go: + cgo: true +repository: + path: github.com/VoIPGRID/opensips_exporter +build: + binaries: + - name: opensips_exporter + 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: + - LICENSE +crossbuild: + platforms: + - linux/amd64 + - linux/386 + - darwin/amd64 + - darwin/386 + - netbsd/amd64 + - netbsd/386 + - linux/arm + - linux/arm64 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ed34aec --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM quay.io/prometheus/busybox:latest +MAINTAINER The Prometheus Authors + +COPY opensips_exporter /bin/opensips_exporter + +ENTRYPOINT ["/bin/opensips_exporter"] +USER nobody +EXPOSE 9737 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1975050 --- /dev/null +++ b/Makefile @@ -0,0 +1,77 @@ +# Copyright 2015 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 +GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) +GOARCH := $(shell $(GO) env GOARCH) +GOHOSTARCH := $(shell $(GO) env GOHOSTARCH) + +PROMTOOL ?= $(GOPATH)/bin/promtool +PROMU ?= $(GOPATH)/bin/promu +STATICCHECK ?= $(GOPATH)/bin/staticcheck +pkgs = $(shell $(GO) list ./... | grep -v /vendor/) + +PREFIX ?= $(shell pwd) +BIN_DIR ?= $(shell pwd) +DOCKER_IMAGE_NAME ?= opensips_exporter +DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) +MACH ?= $(shell uname -m) +DOCKERFILE ?= Dockerfile + +all: format vet staticcheck build + +style: + @echo ">> checking code style" + @! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' + +format: + @echo ">> formatting code" + @$(GO) fmt $(pkgs) + +vet: + @echo ">> vetting code" + @$(GO) vet $(pkgs) + +staticcheck: $(STATICCHECK) + @echo ">> running staticcheck" + @$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(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 from $(DOCKERFILE)" + @docker build --file $(DOCKERFILE) -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . + +$(GOPATH)/bin/promtool promtool: + @GOOS= GOARCH= $(GO) get -u github.com/prometheus/prometheus/cmd/promtool + +$(GOPATH)/bin/promu promu: + @GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu + +$(GOPATH)/bin/staticcheck: + @GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck + + +.PHONY: all style format build test vet tarball docker promtool promu staticcheck + +# Declaring the binaries at their default locations as PHONY targets is a hack +# to ensure the latest version is downloaded on every make execution. +# If this is not desired, copy/symlink these binaries to a different path and +# set the respective environment variables. +.PHONY: $(GOPATH)/bin/promtool $(GOPATH)/bin/promu $(GOPATH)/bin/staticcheck diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6c6aa7c --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 \ No newline at end of file