mirror of
https://github.com/r-smith/deceptifeed.git
synced 2025-10-23 08:22:21 +00:00
Add setting and getting version information
- Add `Version` string var to config package for storing version information. - Update Makefile to set the `Version` variable at build time using the latest Git tag. - Add `-version` flag to main package to print version information and exit. - Remove setting the GO111MODULE environment variable from Makefile when building. It's not needed.
This commit is contained in:
48
Makefile
48
Makefile
@@ -1,24 +1,24 @@
|
||||
# Makefile for Deceptifeed
|
||||
|
||||
SOURCE = ./cmd/deceptifeed/
|
||||
BIN_DIRECTORY = ./bin/
|
||||
BIN_DEFAULT = deceptifeed
|
||||
BIN_LINUX = $(BIN_DEFAULT)_linux_amd64
|
||||
BIN_FREEBSD = $(BIN_DEFAULT)_freebsd_amd64
|
||||
BIN_WINDOWS = $(BIN_DEFAULT)_windows_amd64.exe
|
||||
INSTALL_SCRIPT = ./scripts/install.sh
|
||||
UNINSTALL_SCRIPT = ./scripts/install.sh --uninstall
|
||||
BUILD_OPTIONS = -trimpath -ldflags="-s -w"
|
||||
GO = go
|
||||
CGO_ENABLED = 0
|
||||
GO111MODULE = on
|
||||
SOURCE := ./cmd/deceptifeed/
|
||||
BIN_DIRECTORY := ./bin/
|
||||
BIN_DEFAULT := deceptifeed
|
||||
BIN_LINUX := $(BIN_DEFAULT)_linux_amd64
|
||||
BIN_FREEBSD := $(BIN_DEFAULT)_freebsd_amd64
|
||||
BIN_WINDOWS := $(BIN_DEFAULT)_windows_amd64.exe
|
||||
INSTALL_SCRIPT := ./scripts/install.sh
|
||||
UNINSTALL_SCRIPT := ./scripts/install.sh --uninstall
|
||||
VERSION := $(shell git describe --tags)
|
||||
BUILD_OPTIONS := -trimpath -ldflags="-s -w -X 'github.com/r-smith/deceptifeed/internal/config.Version=$(VERSION)'"
|
||||
GO := go
|
||||
CGO_ENABLED := 0
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
@echo "Building for current operating system to: $(BIN_DIRECTORY)$(BIN_DEFAULT)"
|
||||
@echo "Building for current operating system..."
|
||||
@mkdir -p $(BIN_DIRECTORY)
|
||||
GO111MODULE=$(GO111MODULE) CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(BUILD_OPTIONS) -o $(BIN_DIRECTORY)$(BIN_DEFAULT) $(SOURCE)
|
||||
@echo "Build complete."
|
||||
CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(BUILD_OPTIONS) -o $(BIN_DIRECTORY)$(BIN_DEFAULT) $(SOURCE)
|
||||
@echo "Build complete: $(BIN_DIRECTORY)$(BIN_DEFAULT)"
|
||||
@echo
|
||||
|
||||
.PHONY: all
|
||||
@@ -26,26 +26,26 @@ all: build build-linux build-freebsd build-windows
|
||||
|
||||
.PHONY: build-linux
|
||||
build-linux:
|
||||
@echo "Building for Linux to: $(BIN_DIRECTORY)$(BIN_LINUX)"
|
||||
@echo "Building for Linux..."
|
||||
@mkdir -p $(BIN_DIRECTORY)
|
||||
GOOS=linux GOARCH=amd64 GO111MODULE=$(GO111MODULE) CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(BUILD_OPTIONS) -o $(BIN_DIRECTORY)$(BIN_LINUX) $(SOURCE)
|
||||
@echo "Build complete."
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(BUILD_OPTIONS) -o $(BIN_DIRECTORY)$(BIN_LINUX) $(SOURCE)
|
||||
@echo "Build complete: $(BIN_DIRECTORY)$(BIN_LINUX)"
|
||||
@echo
|
||||
|
||||
.PHONY: build-freebsd
|
||||
build-freebsd:
|
||||
@echo "Building for FreeBSD to: $(BIN_DIRECTORY)$(BIN_FREEBSD)"
|
||||
@echo "Building for FreeBSD..."
|
||||
@mkdir -p $(BIN_DIRECTORY)
|
||||
GOOS=freebsd GOARCH=amd64 GO111MODULE=$(GO111MODULE) CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(BUILD_OPTIONS) -o $(BIN_DIRECTORY)$(BIN_FREEBSD) $(SOURCE)
|
||||
@echo "Build complete."
|
||||
GOOS=freebsd GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(BUILD_OPTIONS) -o $(BIN_DIRECTORY)$(BIN_FREEBSD) $(SOURCE)
|
||||
@echo "Build complete: $(BIN_DIRECTORY)$(BIN_FREEBSD)"
|
||||
@echo
|
||||
|
||||
.PHONY: build-windows
|
||||
build-windows:
|
||||
@echo "Building for Windows to: $(BIN_DIRECTORY)$(BIN_WINDOWS)"
|
||||
@echo "Building for Windows..."
|
||||
@mkdir -p $(BIN_DIRECTORY)
|
||||
GOOS=windows GOARCH=amd64 GO111MODULE=$(GO111MODULE) CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(BUILD_OPTIONS) -o $(BIN_DIRECTORY)$(BIN_WINDOWS) $(SOURCE)
|
||||
@echo "Build complete."
|
||||
GOOS=windows GOARCH=amd64 CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(BUILD_OPTIONS) -o $(BIN_DIRECTORY)$(BIN_WINDOWS) $(SOURCE)
|
||||
@echo "Build complete: $(BIN_DIRECTORY)$(BIN_WINDOWS)"
|
||||
@echo
|
||||
|
||||
.PHONY: install
|
||||
|
@@ -43,8 +43,15 @@ func main() {
|
||||
flag.StringVar(&https.CertPath, "https-cert", config.DefaultCertPathHTTPS, "Path to optional TLS public certificate")
|
||||
flag.StringVar(&https.KeyPath, "https-key", config.DefaultKeyPathHTTPS, "Path to optional TLS private key")
|
||||
flag.StringVar(&ssh.KeyPath, "ssh-key", config.DefaultKeyPathSSH, "Path to optional SSH private key")
|
||||
ver := flag.Bool("version", false, "Output the version number and exit")
|
||||
flag.Parse()
|
||||
|
||||
// If the `-version` flag is provided, output the version number and exit.
|
||||
if *ver {
|
||||
fmt.Println(config.Version)
|
||||
return
|
||||
}
|
||||
|
||||
// If the `-config` flag is not provided, use "config.xml" from the current
|
||||
// directory if the file exists.
|
||||
if len(*configPath) == 0 {
|
||||
|
@@ -12,6 +12,11 @@ import (
|
||||
"github.com/r-smith/deceptifeed/internal/logrotate"
|
||||
)
|
||||
|
||||
// Version stores Deceptifeed's version number. This variable is set at build
|
||||
// time using the `-X` option with `-ldflags` and is assigned the latest Git
|
||||
// tag. Refer to the Makefile in the project root for details on how it's set.
|
||||
var Version = "undefined"
|
||||
|
||||
// This block of constants defines the default application settings when no
|
||||
// configuration file is provided.
|
||||
const (
|
||||
|
Reference in New Issue
Block a user