initial commit
This commit is contained in:
commit
e7987e88a7
70 changed files with 13661 additions and 0 deletions
252
Makefile
Normal file
252
Makefile
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
# go-first Makefile
|
||||
# Web application for URPI - https://www.urpi.be
|
||||
|
||||
.PHONY: help build run dev test lint fmt vet tidy docker-build docker-run docker-push deploy clean
|
||||
|
||||
# Variables
|
||||
APP_NAME := go-first
|
||||
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||
BUILD_TIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
||||
GO_VERSION := 1.23
|
||||
NODE_VERSION := 20
|
||||
|
||||
# Go variables
|
||||
GO := go
|
||||
GOFLAGS := -ldflags="-s -w -X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME) -X main.gitCommit=$(GIT_COMMIT)"
|
||||
CGO_ENABLED := 0
|
||||
|
||||
# Docker variables
|
||||
DOCKER_REGISTRY := ghcr.io
|
||||
DOCKER_IMAGE := $(DOCKER_REGISTRY)/dnoulet/$(APP_NAME)
|
||||
DOCKER_TAG := $(VERSION)
|
||||
|
||||
# Directories
|
||||
BUILD_DIR := ./build
|
||||
WEB_DIR := ./web
|
||||
DIST_DIR := $(WEB_DIR)/dist
|
||||
SERVER_DIR := ./cmd/server
|
||||
|
||||
# Default target
|
||||
help: ## Show this help message
|
||||
@echo "$(APP_NAME) - URPI Web Application"
|
||||
@echo ""
|
||||
@echo "Usage: make [target]"
|
||||
@echo ""
|
||||
@echo "Development:"
|
||||
@echo " dev Run development servers (Go + Vite)"
|
||||
@echo " dev-backend Run Go backend only"
|
||||
@echo " dev-frontend Run Vite frontend only"
|
||||
@echo " install Install all dependencies"
|
||||
@echo ""
|
||||
@echo "Building:"
|
||||
@echo " build Build production binaries"
|
||||
@echo " build-backend Build Go backend only"
|
||||
@echo " build-frontend Build React frontend only"
|
||||
@echo ""
|
||||
@echo "Testing & Quality:"
|
||||
@echo " test Run all tests"
|
||||
@echo " test-backend Run Go tests"
|
||||
@echo " test-frontend Run frontend tests"
|
||||
@echo " lint Run all linters"
|
||||
@echo " lint-backend Run Go linters"
|
||||
@echo " lint-frontend Run frontend linters"
|
||||
@echo " fmt Format all code"
|
||||
@echo " vet Run go vet"
|
||||
@echo " tidy Run go mod tidy"
|
||||
@echo ""
|
||||
@echo "Docker:"
|
||||
@echo " docker-build Build Docker image"
|
||||
@echo " docker-run Run Docker container locally"
|
||||
@echo " docker-push Push Docker image to registry"
|
||||
@echo ""
|
||||
@echo "Deployment:"
|
||||
@echo " deploy Deploy to production (requires config)"
|
||||
@echo " deploy-staging Deploy to staging"
|
||||
@echo ""
|
||||
@echo "Maintenance:"
|
||||
@echo " clean Clean build artifacts"
|
||||
@echo " clean-all Clean everything including node_modules"
|
||||
@echo " generate Generate code (mocks, etc.)"
|
||||
|
||||
# Development
|
||||
dev: ## Run both backend and frontend in development mode
|
||||
@echo "Starting development servers..."
|
||||
@trap 'kill %1; kill %2' INT; \
|
||||
$(MAKE) dev-backend & \
|
||||
$(MAKE) dev-frontend & \
|
||||
wait
|
||||
|
||||
dev-backend: ## Run Go backend
|
||||
@$(GO) run ./cmd/server
|
||||
|
||||
dev-frontend: ## Run Vite frontend dev server
|
||||
@cd $(WEB_DIR) && npm run dev
|
||||
|
||||
install: ## Install all dependencies
|
||||
@echo "Installing Go dependencies..."
|
||||
@$(GO) mod download
|
||||
@echo "Installing frontend dependencies..."
|
||||
@cd $(WEB_DIR) && npm ci
|
||||
|
||||
# Building
|
||||
build: build-backend build-frontend ## Build everything for production
|
||||
|
||||
build-backend: ## Build Go backend binary
|
||||
@echo "Building backend $(VERSION)..."
|
||||
@mkdir -p $(BUILD_DIR)
|
||||
@CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(GOFLAGS) -o $(BUILD_DIR)/$(APP_NAME) $(SERVER_DIR)
|
||||
@echo "Backend built: $(BUILD_DIR)/$(APP_NAME)"
|
||||
|
||||
build-frontend: ## Build React frontend
|
||||
@echo "Building frontend..."
|
||||
@cd $(WEB_DIR) && npm run build
|
||||
@echo "Frontend built: $(DIST_DIR)"
|
||||
|
||||
# Testing
|
||||
test: test-backend test-frontend ## Run all tests
|
||||
|
||||
test-backend: ## Run Go tests
|
||||
@echo "Running Go tests..."
|
||||
@$(GO) test -v -race -coverprofile=coverage.out ./...
|
||||
@$(GO) tool cover -func=coverage.out | tail -1
|
||||
|
||||
test-frontend: ## Run frontend tests
|
||||
@echo "Running frontend tests..."
|
||||
@cd $(WEB_DIR) && npm test -- --run
|
||||
|
||||
# Linting
|
||||
lint: lint-backend lint-frontend ## Run all linters
|
||||
|
||||
lint-backend: ## Run Go linters
|
||||
@which golangci-lint > /dev/null || $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
@golangci-lint run ./...
|
||||
|
||||
lint-frontend: ## Run frontend linters
|
||||
@echo "Running frontend linters..."
|
||||
@cd $(WEB_DIR) && npm run lint
|
||||
|
||||
fmt: ## Format all code
|
||||
@echo "Formatting Go code..."
|
||||
@$(GO) fmt ./...
|
||||
@echo "Formatting frontend code..."
|
||||
@cd $(WEB_DIR) && npm run format
|
||||
|
||||
vet: ## Run go vet
|
||||
@$(GO) vet ./...
|
||||
|
||||
tidy: ## Run go mod tidy
|
||||
@$(GO) mod tidy
|
||||
|
||||
# Docker
|
||||
docker-build: ## Build Docker image
|
||||
@echo "Building Docker image $(DOCKER_IMAGE):$(DOCKER_TAG)..."
|
||||
@docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) -t $(DOCKER_IMAGE):latest .
|
||||
@echo "Built: $(DOCKER_IMAGE):$(DOCKER_TAG)"
|
||||
|
||||
docker-run: ## Run Docker container locally
|
||||
@echo "Running Docker container..."
|
||||
@docker run --rm -p 8080:8080 \
|
||||
-e SERVER_MODE=release \
|
||||
--env-file .env.local \
|
||||
$(DOCKER_IMAGE):$(DOCKER_TAG)
|
||||
|
||||
docker-push: ## Push Docker image to registry
|
||||
@echo "Pushing Docker image..."
|
||||
@docker push $(DOCKER_IMAGE):$(DOCKER_TAG)
|
||||
@docker push $(DOCKER_IMAGE):latest
|
||||
|
||||
# Deployment
|
||||
deploy: ## Deploy to production (requires kubectl/helm configured)
|
||||
@echo "Deploying to production..."
|
||||
@./deploy/deploy.sh production
|
||||
|
||||
deploy-staging: ## Deploy to staging
|
||||
@echo "Deploying to staging..."
|
||||
@./deploy/deploy.sh staging
|
||||
|
||||
# Maintenance
|
||||
clean: ## Clean build artifacts
|
||||
@echo "Cleaning build artifacts..."
|
||||
@rm -rf $(BUILD_DIR)
|
||||
@rm -rf $(DIST_DIR)
|
||||
@$(GO) clean -cache
|
||||
|
||||
clean-all: clean ## Clean everything including dependencies
|
||||
@echo "Cleaning all..."
|
||||
@rm -rf $(WEB_DIR)/node_modules
|
||||
@$(GO) clean -modcache
|
||||
|
||||
generate: ## Generate code (mocks, etc.)
|
||||
@which mockgen > /dev/null || $(GO) install github.com/golang/mock/mockgen@latest
|
||||
@echo "Generating mocks..."
|
||||
@$(GO) generate ./...
|
||||
|
||||
# CI/CD helpers
|
||||
ci-install: ## Install CI dependencies
|
||||
@$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
@$(GO) install github.com/air-verse/air@latest
|
||||
@$(GO) install github.com/golang/mock/mockgen@latest
|
||||
|
||||
ci-test: ## Run CI tests
|
||||
@$(MAKE) lint
|
||||
@$(MAKE) test
|
||||
|
||||
ci-build: ## Build for CI
|
||||
@$(MAKE) build
|
||||
|
||||
# Release
|
||||
release-patch: ## Bump patch version
|
||||
@git tag -a v$(shell semver bump patch) -m "Release patch version"
|
||||
@git push origin --tags
|
||||
|
||||
release-minor: ## Bump minor version
|
||||
@git tag -a v$(shell semver bump minor) -m "Release minor version"
|
||||
@git push origin --tags
|
||||
|
||||
release-major: ## Bump major version
|
||||
@git tag -a v$(shell semver bump major) -m "Release major version"
|
||||
@git push origin --tags
|
||||
|
||||
# Database (if using migrations)
|
||||
db-migrate-up: ## Run database migrations up
|
||||
@which migrate > /dev/null || $(GO) install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
|
||||
@migrate -path ./migrations -database "$(shell grep -A5 'database:' config.yaml | grep 'dsn' | cut -d: -f2- | xargs)" up
|
||||
|
||||
db-migrate-down: ## Run database migrations down
|
||||
@migrate -path ./migrations -database "$(shell grep -A5 'database:' config.yaml | grep 'dsn' | cut -d: -f2- | xargs)" down
|
||||
|
||||
db-migrate-create: ## Create new migration (usage: make db-migrate-create name=add_users_table)
|
||||
@migrate create -ext sql -dir ./migrations -seq $(name)
|
||||
|
||||
# Utilities
|
||||
version: ## Show version info
|
||||
@echo "Version: $(VERSION)"
|
||||
@echo "Build Time: $(BUILD_TIME)"
|
||||
@echo "Git Commit: $(GIT_COMMIT)"
|
||||
|
||||
check-deps: ## Check for outdated dependencies
|
||||
@$(GO) list -u -m all
|
||||
@cd $(WEB_DIR) && npm outdated
|
||||
|
||||
# Server management
|
||||
start: build ## Build and start production server
|
||||
@./$(BUILD_DIR)/$(APP_NAME)
|
||||
|
||||
stop: ## Stop running server (if using PID file)
|
||||
@pkill -f $(APP_NAME) || true
|
||||
|
||||
restart: stop start ## Restart server
|
||||
|
||||
logs: ## View server logs (if using systemd)
|
||||
@journalctl -u $(APP_NAME) -f
|
||||
|
||||
status: ## Check server status
|
||||
@systemctl status $(APP_NAME) || docker ps | grep $(APP_NAME)
|
||||
|
||||
# SSL/Certificates (using Let's Encrypt)
|
||||
cert-renew: ## Renew SSL certificates
|
||||
@certbot renew --nginx
|
||||
|
||||
cert-status: ## Check certificate status
|
||||
@certbot certificates
|
||||
Loading…
Add table
Add a link
Reference in a new issue