Skip to content

Commit

Permalink
Merge pull request netobserv#101 from eranra/improve_version
Browse files Browse the repository at this point in the history
improve version from Makefile
  • Loading branch information
eranra committed Mar 2, 2022
2 parents 510ca74 + e1184ef commit 553f43f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ NETFLOW_GENERATOR=nflow-generator
CMD_DIR=./cmd/
FLP_CONF_FILE ?= contrib/kubernetes/flowlogs-pipeline.conf.yaml

BUILD_DATE := $(shell date +%Y-%m-%d\ %H:%M)
TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
COMMIT := $(shell git rev-parse --short HEAD)
BUILD_VERSION := $(TAG:v%=%)
ifneq ($(COMMIT), $(TAG_COMMIT))
BUILD_VERSION := $(BUILD_VERSION)-$(COMMIT)
endif
ifneq ($(shell git status --porcelain),)
BUILD_VERSION := $(BUILD_VERSION)-dirty
endif

.DEFAULT_GOAL := help

FORCE: ;
Expand Down Expand Up @@ -59,7 +71,7 @@ lint: $(GOLANGCI_LINT) ## Lint the code
.PHONY: build_code
build_code: validate_go lint
@go mod vendor
VERSION=$$(date); go build -ldflags "-X 'main.Version=$$VERSION'" "${CMD_DIR}${FLP_BIN_FILE}"
go build -ldflags "-X 'main.BuildVersion=$(BUILD_VERSION)' -X 'main.BuildDate=$(BUILD_DATE)'" "${CMD_DIR}${FLP_BIN_FILE}"

.PHONY: build
build: build_code docs ## Build flowlogs-pipeline executable and update the docs
Expand Down
6 changes: 4 additions & 2 deletions cmd/flowlogs-pipeline/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import (
)

var (
Version string
BuildVersion string
BuildDate string
cfgFile string
logLevel string
envPrefix = "FLOWLOGS-PIPILNE"
Expand Down Expand Up @@ -163,7 +164,8 @@ func run() {
)

// Initial log message
fmt.Printf("%s starting - version [%s]\n\n", filepath.Base(os.Args[0]), Version)
fmt.Printf("Starting %s:\n=====\nBuild Version: %s\nBuild Date: %s\n\n",
filepath.Base(os.Args[0]), BuildVersion, BuildDate)

// Dump configuration
dumpConfig()
Expand Down
13 changes: 8 additions & 5 deletions contrib/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ WORKDIR /app
COPY go.mod .
COPY go.sum .

# Download modules
RUN go mod download

COPY cmd/ cmd/
COPY pkg/ pkg/
COPY .bingo/ .bingo/
COPY .git/ .git/
COPY Makefile Makefile

# Download modules
RUN go mod download
RUN go mod vendor

# Build
RUN VERSION=$(date); CGO_ENABLED=0 GOOS=linux GO111MODULE=on GOARCH=amd64 go build -ldflags "-X 'main.Version=$VERSION'" ./cmd/flowlogs-pipeline
RUN make build_code

# final stage
FROM ubuntu
Expand Down

0 comments on commit 553f43f

Please sign in to comment.