feat: add version flag and Makefile for release builds
- Add -version flag to show build version - Add Makefile with build targets: - make build-release: optimized build with version - make build-all: cross-compile for Linux/macOS - make run/test/clean: dev commands - Update documentation with build commands - Version is embedded via ldflags during build Usage: make build-release # Build with version ./bin/qfs -version # Show version Version format: v0.2.5-1-gfa0f5e3 (tag-commits-hash) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
19
CLAUDE.md
19
CLAUDE.md
@@ -134,9 +134,22 @@ Go 1.22+ | Gin | GORM | MariaDB 11 | SQLite (glebarez/sqlite) | htmx + Tailwind
|
|||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
```bash
|
```bash
|
||||||
go run ./cmd/qfs # Dev server
|
# Development
|
||||||
go run ./cmd/cron -job=X # cleanup-pricelists | update-prices | update-popularity
|
go run ./cmd/qfs # Dev server
|
||||||
CGO_ENABLED=0 go build -ldflags="-s -w" -o bin/qfs ./cmd/qfs
|
make run # Dev server (via Makefile)
|
||||||
|
|
||||||
|
# Production build
|
||||||
|
make build-release # Optimized build with version (recommended)
|
||||||
|
VERSION=$(git describe --tags --always --dirty)
|
||||||
|
CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=$VERSION" -o bin/qfs ./cmd/qfs
|
||||||
|
|
||||||
|
# Cron jobs
|
||||||
|
go run ./cmd/cron -job=cleanup-pricelists # Remove old unused pricelists
|
||||||
|
go run ./cmd/cron -job=update-prices # Recalculate all prices
|
||||||
|
go run ./cmd/cron -job=update-popularity # Update popularity scores
|
||||||
|
|
||||||
|
# Check version
|
||||||
|
./bin/qfs -version
|
||||||
```
|
```
|
||||||
|
|
||||||
## Code Style
|
## Code Style
|
||||||
|
|||||||
85
Makefile
Normal file
85
Makefile
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
.PHONY: build build-release clean test run version
|
||||||
|
|
||||||
|
# Get version from git
|
||||||
|
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||||
|
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
|
||||||
|
LDFLAGS := -s -w -X main.Version=$(VERSION)
|
||||||
|
|
||||||
|
# Binary name
|
||||||
|
BINARY := qfs
|
||||||
|
|
||||||
|
# Build for development (with debug info)
|
||||||
|
build:
|
||||||
|
go build -o bin/$(BINARY) ./cmd/qfs
|
||||||
|
|
||||||
|
# Build for release (optimized, with version)
|
||||||
|
build-release:
|
||||||
|
@echo "Building $(BINARY) version $(VERSION)..."
|
||||||
|
CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o bin/$(BINARY) ./cmd/qfs
|
||||||
|
@echo "✓ Built: bin/$(BINARY)"
|
||||||
|
@./bin/$(BINARY) -version
|
||||||
|
|
||||||
|
# Build release for Linux (cross-compile)
|
||||||
|
build-linux:
|
||||||
|
@echo "Building $(BINARY) for Linux..."
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o bin/$(BINARY)-linux-amd64 ./cmd/qfs
|
||||||
|
@echo "✓ Built: bin/$(BINARY)-linux-amd64"
|
||||||
|
|
||||||
|
# Build release for macOS (cross-compile)
|
||||||
|
build-macos:
|
||||||
|
@echo "Building $(BINARY) for macOS..."
|
||||||
|
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o bin/$(BINARY)-darwin-amd64 ./cmd/qfs
|
||||||
|
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o bin/$(BINARY)-darwin-arm64 ./cmd/qfs
|
||||||
|
@echo "✓ Built: bin/$(BINARY)-darwin-amd64"
|
||||||
|
@echo "✓ Built: bin/$(BINARY)-darwin-arm64"
|
||||||
|
|
||||||
|
# Build all platforms
|
||||||
|
build-all: build-release build-linux build-macos
|
||||||
|
|
||||||
|
# Show version
|
||||||
|
version:
|
||||||
|
@echo "Version: $(VERSION)"
|
||||||
|
|
||||||
|
# Clean build artifacts
|
||||||
|
clean:
|
||||||
|
rm -rf bin/
|
||||||
|
rm -f $(BINARY)
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
test:
|
||||||
|
go test -v ./...
|
||||||
|
|
||||||
|
# Run development server
|
||||||
|
run:
|
||||||
|
go run ./cmd/qfs
|
||||||
|
|
||||||
|
# Run with auto-restart (requires entr: brew install entr)
|
||||||
|
watch:
|
||||||
|
find . -name '*.go' | entr -r go run ./cmd/qfs
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
deps:
|
||||||
|
go mod download
|
||||||
|
go mod tidy
|
||||||
|
|
||||||
|
# Help
|
||||||
|
help:
|
||||||
|
@echo "QuoteForge Server (qfs) - Build Commands"
|
||||||
|
@echo ""
|
||||||
|
@echo "Usage: make [target]"
|
||||||
|
@echo ""
|
||||||
|
@echo "Targets:"
|
||||||
|
@echo " build Build for development (with debug info)"
|
||||||
|
@echo " build-release Build optimized release (default)"
|
||||||
|
@echo " build-linux Cross-compile for Linux"
|
||||||
|
@echo " build-macos Cross-compile for macOS (Intel + Apple Silicon)"
|
||||||
|
@echo " build-all Build for all platforms"
|
||||||
|
@echo " version Show current version"
|
||||||
|
@echo " clean Remove build artifacts"
|
||||||
|
@echo " test Run tests"
|
||||||
|
@echo " run Run development server"
|
||||||
|
@echo " watch Run with auto-restart (requires entr)"
|
||||||
|
@echo " deps Install/update dependencies"
|
||||||
|
@echo " help Show this help"
|
||||||
|
@echo ""
|
||||||
|
@echo "Current version: $(VERSION)"
|
||||||
21
README.md
21
README.md
@@ -97,9 +97,24 @@ go run ./cmd/importer
|
|||||||
# Development
|
# Development
|
||||||
go run ./cmd/qfs
|
go run ./cmd/qfs
|
||||||
|
|
||||||
# Production
|
# Production (with Makefile - recommended)
|
||||||
CGO_ENABLED=0 go build -ldflags="-s -w" -o bin/qfs ./cmd/qfs
|
make build-release # Builds with version info
|
||||||
./bin/qfs
|
./bin/qfs -version # Check version
|
||||||
|
|
||||||
|
# Production (manual)
|
||||||
|
VERSION=$(git describe --tags --always --dirty)
|
||||||
|
CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=$VERSION" -o bin/qfs ./cmd/qfs
|
||||||
|
./bin/qfs -version
|
||||||
|
```
|
||||||
|
|
||||||
|
**Makefile команды:**
|
||||||
|
```bash
|
||||||
|
make build-release # Оптимизированная сборка с версией
|
||||||
|
make build-all # Сборка для всех платформ (Linux, macOS)
|
||||||
|
make run # Запуск dev сервера
|
||||||
|
make test # Запуск тестов
|
||||||
|
make clean # Очистка bin/
|
||||||
|
make help # Показать все команды
|
||||||
```
|
```
|
||||||
|
|
||||||
Приложение будет доступно по адресу: http://localhost:8080
|
Приложение будет доступно по адресу: http://localhost:8080
|
||||||
|
|||||||
@@ -34,11 +34,21 @@ const (
|
|||||||
localDBPath = "./data/settings.db"
|
localDBPath = "./data/settings.db"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Version is set via ldflags during build
|
||||||
|
var Version = "dev"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configPath := flag.String("config", "config.yaml", "path to config file (optional, for server settings)")
|
configPath := flag.String("config", "config.yaml", "path to config file (optional, for server settings)")
|
||||||
migrate := flag.Bool("migrate", false, "run database migrations")
|
migrate := flag.Bool("migrate", false, "run database migrations")
|
||||||
|
version := flag.Bool("version", false, "show version information")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
// Show version if requested
|
||||||
|
if *version {
|
||||||
|
fmt.Printf("qfs version %s\n", Version)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize local SQLite database (always used)
|
// Initialize local SQLite database (always used)
|
||||||
local, err := localdb.New(localDBPath)
|
local, err := localdb.New(localDBPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user