From e679fecf6ea1f2e46c4aecf0abecb6394617e26d Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Sat, 28 Nov 2020 23:46:24 +0500 Subject: [PATCH] Correctly set version info when building, fixed build script and added headers for apps endpoints. --- Makefile | 6 +++--- internal/configuration/config.go | 2 ++ scripts/build.sh | 12 ++++++++++++ scripts/show_git_data.sh | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 1042eb8..a9dd857 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ help: Makefile @echo -e "Metricator Makefile available subcommands:\n" @cat $< | grep "## " | sort | sed -n 's/^## //p' @echo "" - @make -f Makefile show-git-data + @make show-git-data .DEFAULT_GOAL := help @@ -14,8 +14,8 @@ check-build-dir: ## metricatord-build: builds metricator daemon and places into ${PWD}/._bin. metricatord-build: check-build-dir - rm ./._bin/metricatord || true - cd cmd/metricatord && go build -o ../../._bin/metricatord + @rm ./._bin/metricatord || true + @scripts/build.sh metricatord ## metricatord-run: starts metricator daemon. metricatord-run: metricatord-build diff --git a/internal/configuration/config.go b/internal/configuration/config.go index 56b9dc5..5239495 100644 --- a/internal/configuration/config.go +++ b/internal/configuration/config.go @@ -27,6 +27,8 @@ type Config struct { // Endpoint is a remote application endpoint which should give us metrics // in Prometheus format. Endpoint string + // Headers is a list of headers that should be added to metrics request. + Headers map[string]string // TimeBetweenRequests is a minimal amount of time which should pass // between requests. TimeBetweenRequests time.Duration diff --git a/scripts/build.sh b/scripts/build.sh index 24557cf..f848b0b 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,3 +3,15 @@ # Metricator build script. source ./scripts/shell_helpers/get_git_data.sh + +WHATTOBUILD=$1 + +LINKERFLAGS="\ +-X go.dev.pztrn.name/metricator/internal/common.Branch=${BRANCHNAME} \ +-X go.dev.pztrn.name/metricator/internal/common.Build=${BUILDID} \ +-X go.dev.pztrn.name/metricator/internal/common.CommitHash=${COMMITHASH} \ +-X go.dev.pztrn.name/metricator/internal/common.Version=${VERSION}" + + +cd cmd/${WHATTOBUILD} +go build -tags netgo -ldflags "${LINKERFLAGS} -w -extldflags '-static'" -o ../../._bin/${WHATTOBUILD} diff --git a/scripts/show_git_data.sh b/scripts/show_git_data.sh index 3b86e8d..6dc2d44 100755 --- a/scripts/show_git_data.sh +++ b/scripts/show_git_data.sh @@ -3,7 +3,7 @@ # Showing git data in console. source ./scripts/shell_helpers/get_git_data.sh -echo "* Branch: ${BRANCH}" +echo "* Branch: ${BRANCHNAME}" echo "* Build ID: ${BUILDID}" echo "* Commit hash: ${COMMITHASH}" echo "* Version: ${VERSION}"