From c010fb1c3cfd8b72c82cb97583441641fc1a7657 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Fri, 22 Sep 2017 16:49:28 -0700 Subject: [PATCH] Fix build versioning; add dev.docker file --- Makefile | 10 +++++++--- cmd/telegraf/telegraf.go | 2 +- scripts/build.py | 31 ++++++++++++++++++++----------- scripts/dev.docker | 8 ++++++++ 4 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 scripts/dev.docker diff --git a/Makefile b/Makefile index bf4c8dfec..3908be1d1 100644 --- a/Makefile +++ b/Makefile @@ -49,12 +49,16 @@ test-all: lint go test ./... package: - ./scripts/build.py --package --version="$(VERSION)" --platform=linux --arch=all --upload - + ./scripts/build.py --package --platform=all --arch=all clean: -rm -f telegraf -rm -f telegraf.exe +docker-image: + ./scripts/build.py --package --platform=linux --arch=amd64 + cp build/telegraf*$(COMMIT)*.deb . + docker build -f scripts/dev.docker --build-arg "package=telegraf*$(COMMIT)*.deb" -t "telegraf-dev:$(COMMIT)" . + # Run all docker containers necessary for integration tests docker-run: docker run --name aerospike -p "3000:3000" -d aerospike/aerospike-server:3.9.0 @@ -114,4 +118,4 @@ docker-kill: openldap postgres rabbitmq redis riemann zookeeper .PHONY: deps telegraf telegraf.exe install test test-windows lint test-all \ - package clean docker-run docker-run-circle docker-kill + package clean docker-run docker-run-circle docker-kill docker-image diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index 6301ea8ff..42fd6cf2f 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -268,7 +268,7 @@ func (p *program) Stop(s service.Service) error { func displayVersion() string { if version == "" { - return fmt.Sprintf("v%s~pre%s", nextVersion, commit) + return fmt.Sprintf("v%s~%s", nextVersion, commit) } return "v" + version } diff --git a/scripts/build.py b/scripts/build.py index 9b70e961e..cc0709e0a 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -95,6 +95,8 @@ supported_packages = { "freebsd": [ "tar" ] } +next_version = '1.5.0' + ################ #### Telegraf Functions ################ @@ -158,7 +160,8 @@ def go_get(branch, update=False, no_uncommitted=False): get_command = "go get github.com/sparrc/gdm" run(get_command) logging.info("Retrieving dependencies with `gdm`...") - run("{}/bin/gdm restore -v".format(os.environ.get("GOPATH"))) + run("{}/bin/gdm restore -v".format(os.environ.get("GOPATH", + os.path.expanduser("~/go")))) return True def run_tests(race, parallel, timeout, no_vet): @@ -223,13 +226,16 @@ def increment_minor_version(version): def get_current_version_tag(): """Retrieve the raw git version tag. """ - version = run("git describe --always --tags --abbrev=0") + version = run("git describe --exact-match --tags 2>/dev/null", + allow_failure=True, shell=True) return version def get_current_version(): """Parse version information from git tag output. """ version_tag = get_current_version_tag() + if not version_tag: + return None # Remove leading 'v' if version_tag[0] == 'v': version_tag = version_tag[1:] @@ -474,12 +480,17 @@ def build(version=None, if len(tags) > 0: build_command += "-tags {} ".format(','.join(tags)) - build_command += "-ldflags=\"-w -s -X main.version={} -X main.branch={} -X main.commit={}\" ".format( - version, - get_current_branch(), - get_current_commit()) + ldflags = [ + '-w', '-s', + '-X', 'main.branch={}'.format(get_current_branch()), + '-X', 'main.commit={}'.format(get_current_commit(short=True))] + if version: + ldflags.append('-X') + ldflags.append('main.version={}'.format(version)) + build_command += ' -ldflags="{}" '.format(' '.join(ldflags)) + if static: - build_command += "-a -installsuffix cgo " + build_command += " -a -installsuffix cgo " build_command += path start_time = datetime.utcnow() run(build_command, shell=True) @@ -575,10 +586,8 @@ def package(build_output, pkg_name, version, nightly=False, iteration=1, static= package_arch = 'armv6hl' else: package_arch = arch - if not release and not nightly: - # For non-release builds, just use the commit hash as the version - package_version = "{}~{}".format(version, - get_current_commit(short=True)) + if not version: + package_version = "{}~{}".format(next_version, get_current_commit(short=True)) package_iteration = "0" package_build_root = build_root current_location = build_output[platform][arch] diff --git a/scripts/dev.docker b/scripts/dev.docker new file mode 100644 index 000000000..902c7f9aa --- /dev/null +++ b/scripts/dev.docker @@ -0,0 +1,8 @@ +FROM debian:stretch +ARG package +ADD ${package} ${package} +RUN dpkg -i ${package} + +EXPOSE 8125/udp 8092/udp 8094 + +CMD ["telegraf"]