Skip to content

Commit 96d4e1b

Browse files
* [CHG] enable crossbuils
1 parent a843bf7 commit 96d4e1b

File tree

6 files changed

+283
-19
lines changed

6 files changed

+283
-19
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
logstash_exporter
55
#Vendoring
66
vendor/*
7+
8+
/.build
9+
/.deps
10+
/.release
11+
/.tarballs

.promu.yml

+21-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
go:
22
cgo: false
3+
version: 1.11
34
repository:
45
path: github.com/sequra/logstash_exporter
56
build:
67
binaries:
78
- name: logstash_exporter
8-
flags: -i -tags 'netgo static_build'
9+
flags: -mod=vendor -a -tags 'netgo static_build'
910
ldflags: |
10-
-s
11-
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}}
12-
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}}
13-
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}}
14-
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
15-
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
11+
-X github.com/prometheus/common/version.Version={{.Version}}
12+
-X github.com/prometheus/common/version.Revision={{.Revision}}
13+
-X github.com/prometheus/common/version.Branch={{.Branch}}
14+
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
15+
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
1616
tarball:
1717
files:
1818
- LICENSE
19+
20+
crossbuild:
21+
platforms:
22+
- linux/amd64
23+
- linux/386
24+
- linux/arm
25+
- linux/arm64
26+
- linux/mips
27+
- linux/mipsle
28+
- linux/mips64
29+
- linux/mips64le
30+
- linux/ppc64
31+
- linux/ppc64le
32+
- linux/s390x

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ env:
1111

1212
before_script:
1313
- go get github.com/golangci/golangci-lint/cmd/golangci-lint
14-
- go get -u github.com/prometheus/promu
1514

1615
script:
1716
- make

Makefile

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
GO ?= GO15VENDOREXPERIMENT=1 go
2-
GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
3-
PROMU ?= $(GOPATH)/bin/promu
4-
GOLINTER ?= $(GOPATH)/bin/golangci-lint
5-
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
6-
TARGET ?= logstash_exporter
1+
all: clean format golint
72

8-
PREFIX ?= $(shell pwd)
9-
BIN_DIR ?= $(shell pwd)
3+
include Makefile.common
104

11-
all: clean format golint build test
5+
TARGET ?= logstash_exporter
6+
GOLINTER ?= $(GOPATH)/bin/golangci-lint
7+
8+
vendor:
9+
@echo ">> installing dependencies on vendor"
10+
@$(GO) mod vendor
1211

1312
test:
1413
@echo ">> running tests"
@@ -22,9 +21,21 @@ golint:
2221
@echo ">> linting code"
2322
@$(GOLINTER) run
2423

25-
build:
24+
build: promu vendor
2625
@echo ">> building binaries"
27-
@$(PROMU) build --prefix $(PREFIX)
26+
GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX)
27+
28+
crossbuild: promu vendor
29+
@echo ">> cross-building binaries"
30+
@$(PROMU) crossbuild
31+
32+
tarball: promu vendor
33+
@echo ">> building release tarball"
34+
@$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
35+
36+
tarballs: promu vendor
37+
@echo ">> building release tarballs"
38+
@$(PROMU) crossbuild tarballs $(BIN_DIR)
2839

2940
clean:
3041
@echo ">> Cleaning up"

Makefile.common

+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
# Copyright 2018 The Prometheus Authors
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
15+
# A common Makefile that includes rules to be reused in different prometheus projects.
16+
# !!! Open PRs only against the prometheus/prometheus/Makefile.common repository!
17+
18+
# Example usage :
19+
# Create the main Makefile in the root project directory.
20+
# include Makefile.common
21+
# customTarget:
22+
# @echo ">> Running customTarget"
23+
#
24+
25+
# Ensure GOBIN is not set during build so that promu is installed to the correct path
26+
unexport GOBIN
27+
28+
GO ?= go
29+
GOFMT ?= $(GO)fmt
30+
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
31+
GOOPTS ?=
32+
GOHOSTOS ?= $(shell $(GO) env GOHOSTOS)
33+
GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH)
34+
35+
GO_VERSION ?= $(shell $(GO) version)
36+
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
37+
PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.')
38+
39+
GOVENDOR :=
40+
GO111MODULE :=
41+
ifeq (, $(PRE_GO_111))
42+
ifneq (,$(wildcard go.mod))
43+
# Enforce Go modules support just in case the directory is inside GOPATH (and for Travis CI).
44+
GO111MODULE := on
45+
46+
ifneq (,$(wildcard vendor))
47+
# Always use the local vendor/ directory to satisfy the dependencies.
48+
GOOPTS := $(GOOPTS) -mod=vendor
49+
endif
50+
endif
51+
else
52+
ifneq (,$(wildcard go.mod))
53+
ifneq (,$(wildcard vendor))
54+
$(warning This repository requires Go >= 1.11 because of Go modules)
55+
$(warning Some recipes may not work as expected as the current Go runtime is '$(GO_VERSION_NUMBER)')
56+
endif
57+
else
58+
# This repository isn't using Go modules (yet).
59+
GOVENDOR := $(FIRST_GOPATH)/bin/govendor
60+
endif
61+
endif
62+
PROMU := $(FIRST_GOPATH)/bin/promu
63+
STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck
64+
pkgs = ./...
65+
66+
ifeq (arm, $(GOHOSTARCH))
67+
GOHOSTARM ?= $(shell GOARM= $(GO) env GOARM)
68+
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)v$(GOHOSTARM)
69+
else
70+
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)
71+
endif
72+
73+
PROMU_VERSION ?= 0.2.0
74+
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
75+
STATICCHECK_VERSION ?= 2019.1
76+
STATICCHECK_URL := https://github.com/dominikh/go-tools/releases/download/$(STATICCHECK_VERSION)/staticcheck_$(GOHOSTOS)_$(GOHOSTARCH)
77+
78+
PREFIX ?= $(shell pwd)
79+
BIN_DIR ?= $(shell pwd)
80+
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
81+
DOCKER_REPO ?= prom
82+
83+
ifeq ($(GOHOSTARCH),amd64)
84+
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux freebsd darwin windows))
85+
# Only supported on amd64
86+
test-flags := -race
87+
endif
88+
endif
89+
90+
.PHONY: all
91+
all: precheck style staticcheck unused build test
92+
93+
# This rule is used to forward a target like "build" to "common-build". This
94+
# allows a new "build" target to be defined in a Makefile which includes this
95+
# one and override "common-build" without override warnings.
96+
%: common-% ;
97+
98+
.PHONY: common-style
99+
common-style:
100+
@echo ">> checking code style"
101+
@fmtRes=$$($(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print)); \
102+
if [ -n "$${fmtRes}" ]; then \
103+
echo "gofmt checking failed!"; echo "$${fmtRes}"; echo; \
104+
echo "Please ensure you are using $$($(GO) version) for formatting code."; \
105+
exit 1; \
106+
fi
107+
108+
.PHONY: common-check_license
109+
common-check_license:
110+
@echo ">> checking license header"
111+
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
112+
awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
113+
done); \
114+
if [ -n "$${licRes}" ]; then \
115+
echo "license header checking failed:"; echo "$${licRes}"; \
116+
exit 1; \
117+
fi
118+
119+
.PHONY: common-test-short
120+
common-test-short:
121+
@echo ">> running short tests"
122+
GO111MODULE=$(GO111MODULE) $(GO) test -short $(GOOPTS) $(pkgs)
123+
124+
.PHONY: common-test
125+
common-test:
126+
@echo ">> running all tests"
127+
GO111MODULE=$(GO111MODULE) $(GO) test $(test-flags) $(GOOPTS) $(pkgs)
128+
129+
.PHONY: common-format
130+
common-format:
131+
@echo ">> formatting code"
132+
GO111MODULE=$(GO111MODULE) $(GO) fmt $(pkgs)
133+
134+
.PHONY: common-vet
135+
common-vet:
136+
@echo ">> vetting code"
137+
GO111MODULE=$(GO111MODULE) $(GO) vet $(GOOPTS) $(pkgs)
138+
139+
.PHONY: common-staticcheck
140+
common-staticcheck: $(STATICCHECK)
141+
@echo ">> running staticcheck"
142+
chmod +x $(STATICCHECK)
143+
ifdef GO111MODULE
144+
# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
145+
# Otherwise staticcheck might fail randomly for some reason not yet explained.
146+
GO111MODULE=$(GO111MODULE) $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
147+
GO111MODULE=$(GO111MODULE) $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
148+
else
149+
$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
150+
endif
151+
152+
.PHONY: common-unused
153+
common-unused: $(GOVENDOR)
154+
ifdef GOVENDOR
155+
@echo ">> running check for unused packages"
156+
@$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
157+
else
158+
ifdef GO111MODULE
159+
@echo ">> running check for unused/missing packages in go.mod"
160+
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
161+
ifeq (,$(wildcard vendor))
162+
@git diff --exit-code -- go.sum go.mod
163+
else
164+
@echo ">> running check for unused packages in vendor/"
165+
GO111MODULE=$(GO111MODULE) $(GO) mod vendor
166+
@git diff --exit-code -- go.sum go.mod vendor/
167+
endif
168+
endif
169+
endif
170+
171+
.PHONY: common-build
172+
common-build: promu
173+
@echo ">> building binaries"
174+
GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX)
175+
176+
.PHONY: common-tarball
177+
common-tarball: promu
178+
@echo ">> building release tarball"
179+
$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
180+
181+
.PHONY: common-docker
182+
common-docker:
183+
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
184+
185+
.PHONY: common-docker-publish
186+
common-docker-publish:
187+
docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)"
188+
189+
.PHONY: common-docker-tag-latest
190+
common-docker-tag-latest:
191+
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):latest"
192+
193+
.PHONY: promu
194+
promu: $(PROMU)
195+
196+
$(PROMU):
197+
$(eval PROMU_TMP := $(shell mktemp -d))
198+
curl -s -L $(PROMU_URL) | tar -xvzf - -C $(PROMU_TMP)
199+
mkdir -p $(FIRST_GOPATH)/bin
200+
cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
201+
rm -r $(PROMU_TMP)
202+
203+
.PHONY: proto
204+
proto:
205+
@echo ">> generating code from proto files"
206+
@./scripts/genproto.sh
207+
208+
$(STATICCHECK):
209+
mkdir -p $(FIRST_GOPATH)/bin
210+
curl -s -L $(STATICCHECK_URL) > $(STATICCHECK)
211+
212+
ifdef GOVENDOR
213+
.PHONY: $(GOVENDOR)
214+
$(GOVENDOR):
215+
GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
216+
endif
217+
218+
.PHONY: precheck
219+
precheck::
220+
221+
define PRECHECK_COMMAND_template =
222+
precheck:: $(1)_precheck
223+
224+
225+
PRECHECK_COMMAND_$(1) ?= $(1) $$(strip $$(PRECHECK_OPTIONS_$(1)))
226+
.PHONY: $(1)_precheck
227+
$(1)_precheck:
228+
@if ! $$(PRECHECK_COMMAND_$(1)) 1>/dev/null 2>&1; then \
229+
echo "Execution of '$$(PRECHECK_COMMAND_$(1))' command failed. Is $(1) installed?"; \
230+
exit 1; \
231+
fi
232+
endef

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
1010
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
1111
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
1212
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
13+
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
1314
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
1415
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
1516
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -49,6 +50,7 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf
4950
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
5051
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
5152
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
53+
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc h1:a3CU5tJYVj92DY2LaA1kUkrsqD5/3mLDhx2NcNqyW+0=
5254
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
5355
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
5456
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -61,4 +63,5 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
6163
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
6264
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
6365
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
66+
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
6467
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 commit comments

Comments
 (0)