Add configuration file and update server settings
- Introduced a new `config.yaml` file for managing server, database, cache, queue, AI, scraping, logging, and rate limiting configurations. - Updated `docker-compose.yml` to reflect the new server port (8081) and adjusted health check endpoints accordingly. - Modified `Dockerfile` to expose the new server port. - Updated `README.md` to reflect changes in server configuration and added documentation for the new configuration structure. - Added test scripts for server and Swagger documentation testing. - Refactored customer domain structure to align with new configuration settings and improve maintainability.
This commit is contained in:
@@ -1,225 +1,90 @@
|
||||
.PHONY: help build test clean run docker-build docker-run dev-up dev-down lint fmt vet
|
||||
# Tender Management Backend Makefile
|
||||
|
||||
.PHONY: help build run test clean docker-build docker-run
|
||||
|
||||
# Default target
|
||||
help: ## Show this help message
|
||||
@echo 'Usage: make [target]'
|
||||
@echo ''
|
||||
@echo 'Targets:'
|
||||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
||||
help:
|
||||
@echo "Available targets:"
|
||||
@echo " build - Build the web server"
|
||||
@echo " run - Run the web server"
|
||||
@echo " test - Run tests"
|
||||
@echo " clean - Clean build artifacts"
|
||||
@echo " docker-build - Build Docker image"
|
||||
@echo " docker-run - Run Docker container"
|
||||
|
||||
# Build Configuration
|
||||
BINARY_NAME=tm-api
|
||||
MAIN_PATH=./cmd/api/main.go
|
||||
BUILD_DIR=./bin
|
||||
# Build the web server
|
||||
build:
|
||||
@echo "Building web server..."
|
||||
@mkdir -p bin
|
||||
@go build -o bin/web ./cmd/web
|
||||
@echo "Build completed successfully!"
|
||||
|
||||
# Go Configuration
|
||||
GOCMD=go
|
||||
GOBUILD=$(GOCMD) build
|
||||
GOCLEAN=$(GOCMD) clean
|
||||
GOTEST=$(GOCMD) test
|
||||
GOGET=$(GOCMD) get
|
||||
GOMOD=$(GOCMD) mod
|
||||
GOFMT=gofmt
|
||||
GOVET=$(GOCMD) vet
|
||||
# Run the web server
|
||||
run: build
|
||||
@echo "Starting web server..."
|
||||
@./bin/web
|
||||
|
||||
# Build flags
|
||||
LDFLAGS=-ldflags "-w -s"
|
||||
BUILD_FLAGS=-a -installsuffix cgo
|
||||
# Run tests
|
||||
test:
|
||||
@echo "Running tests..."
|
||||
@go test ./...
|
||||
|
||||
# Development
|
||||
dev-up: ## Start development environment with Docker Compose
|
||||
docker-compose up -d mongodb redis rabbitmq elasticsearch
|
||||
@echo "Development services started. Waiting for services to be ready..."
|
||||
@sleep 10
|
||||
@echo "Services should be ready. Run 'make run' to start the API."
|
||||
# Clean build artifacts
|
||||
clean:
|
||||
@echo "Cleaning build artifacts..."
|
||||
@rm -rf bin/
|
||||
@go clean
|
||||
|
||||
dev-down: ## Stop development environment
|
||||
docker-compose down
|
||||
docker-compose down --volumes --remove-orphans
|
||||
# Build Docker image
|
||||
docker-build:
|
||||
@echo "Building Docker image..."
|
||||
@docker build -t tender-management-api .
|
||||
|
||||
dev-logs: ## Show logs from development services
|
||||
docker-compose logs -f
|
||||
# Run Docker container
|
||||
docker-run:
|
||||
@echo "Running Docker container..."
|
||||
@docker run -p 8081:8081 tender-management-api
|
||||
|
||||
dev-status: ## Show status of development services
|
||||
docker-compose ps
|
||||
# Development with hot reload (requires air)
|
||||
dev:
|
||||
@echo "Starting development server with hot reload..."
|
||||
@air
|
||||
|
||||
# Building
|
||||
build: ## Build the application
|
||||
mkdir -p $(BUILD_DIR)
|
||||
CGO_ENABLED=0 GOOS=linux $(GOBUILD) $(LDFLAGS) $(BUILD_FLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
|
||||
# Install development dependencies
|
||||
install-dev:
|
||||
@echo "Installing development dependencies..."
|
||||
@go install github.com/cosmtrek/air@latest
|
||||
|
||||
build-local: ## Build for local development
|
||||
mkdir -p $(BUILD_DIR)
|
||||
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
|
||||
# Format code
|
||||
fmt:
|
||||
@echo "Formatting code..."
|
||||
@go fmt ./...
|
||||
|
||||
# Running
|
||||
run: ## Run the application locally
|
||||
$(GOCMD) run $(MAIN_PATH)
|
||||
# Vet code
|
||||
vet:
|
||||
@echo "Vetting code..."
|
||||
@go vet ./...
|
||||
|
||||
run-binary: build-local ## Build and run the binary
|
||||
$(BUILD_DIR)/$(BINARY_NAME)
|
||||
# Lint code (requires golangci-lint)
|
||||
lint:
|
||||
@echo "Linting code..."
|
||||
@golangci-lint run
|
||||
|
||||
# Testing
|
||||
test: ## Run tests
|
||||
$(GOTEST) -v ./...
|
||||
|
||||
test-coverage: ## Run tests with coverage
|
||||
$(GOTEST) -v -coverprofile=coverage.out ./...
|
||||
$(GOCMD) tool cover -html=coverage.out -o coverage.html
|
||||
@echo "Coverage report generated: coverage.html"
|
||||
|
||||
test-race: ## Run tests with race detection
|
||||
$(GOTEST) -race -v ./...
|
||||
|
||||
benchmark: ## Run benchmarks
|
||||
$(GOTEST) -bench=. -benchmem ./...
|
||||
|
||||
# Code Quality
|
||||
lint: ## Run golangci-lint
|
||||
golangci-lint run
|
||||
|
||||
fmt: ## Format Go code
|
||||
$(GOFMT) -s -w .
|
||||
$(GOCMD) fmt ./...
|
||||
|
||||
vet: ## Run go vet
|
||||
$(GOVET) ./...
|
||||
|
||||
check: fmt vet lint test ## Run all code quality checks
|
||||
|
||||
# Dependencies
|
||||
deps: ## Download dependencies
|
||||
$(GOMOD) download
|
||||
|
||||
deps-update: ## Update dependencies
|
||||
$(GOMOD) tidy
|
||||
$(GOGET) -u ./...
|
||||
$(GOMOD) tidy
|
||||
|
||||
deps-vendor: ## Vendor dependencies
|
||||
$(GOMOD) vendor
|
||||
|
||||
# Docker
|
||||
docker-build: ## Build Docker image
|
||||
docker build -t $(BINARY_NAME):latest .
|
||||
|
||||
docker-run: ## Run Docker container
|
||||
docker run -p 8080:8080 --name $(BINARY_NAME) $(BINARY_NAME):latest
|
||||
|
||||
docker-stop: ## Stop Docker container
|
||||
docker stop $(BINARY_NAME) || true
|
||||
docker rm $(BINARY_NAME) || true
|
||||
|
||||
docker-push: ## Push Docker image (requires DOCKER_REGISTRY env var)
|
||||
@if [ -z "$(DOCKER_REGISTRY)" ]; then \
|
||||
echo "Error: DOCKER_REGISTRY environment variable is not set"; \
|
||||
exit 1; \
|
||||
fi
|
||||
docker tag $(BINARY_NAME):latest $(DOCKER_REGISTRY)/$(BINARY_NAME):latest
|
||||
docker push $(DOCKER_REGISTRY)/$(BINARY_NAME):latest
|
||||
|
||||
# Docker Compose
|
||||
compose-up: ## Start all services with Docker Compose
|
||||
docker-compose up --build
|
||||
|
||||
compose-up-d: ## Start all services in background
|
||||
docker-compose up -d --build
|
||||
|
||||
compose-down: ## Stop all services
|
||||
docker-compose down
|
||||
|
||||
compose-logs: ## Show logs from all services
|
||||
docker-compose logs -f
|
||||
|
||||
compose-restart: ## Restart all services
|
||||
docker-compose restart
|
||||
|
||||
# Database
|
||||
db-migrate: ## Run database migrations (TODO: implement)
|
||||
@echo "Database migration not implemented yet"
|
||||
|
||||
db-seed: ## Seed database with test data (TODO: implement)
|
||||
@echo "Database seeding not implemented yet"
|
||||
|
||||
db-reset: ## Reset database (TODO: implement)
|
||||
@echo "Database reset not implemented yet"
|
||||
|
||||
# Monitoring
|
||||
logs: ## Show application logs (when running locally)
|
||||
tail -f ./logs/app.log
|
||||
|
||||
logs-live: ## Follow live application logs
|
||||
tail -f ./logs/app.log
|
||||
|
||||
logs-clean: ## Clean application logs
|
||||
rm -f ./logs/*.log
|
||||
rm -f ./logs/*.log.gz
|
||||
|
||||
health: ## Check application health
|
||||
curl -f http://localhost:8080/health || echo "Health check failed"
|
||||
|
||||
# Cleanup
|
||||
clean: ## Clean build artifacts
|
||||
$(GOCLEAN)
|
||||
rm -rf $(BUILD_DIR)
|
||||
rm -f coverage.out coverage.html
|
||||
|
||||
clean-all: logs-clean clean ## Clean everything including logs
|
||||
@echo "All artifacts cleaned"
|
||||
|
||||
clean-docker: ## Clean Docker images and containers
|
||||
docker-compose down --volumes --remove-orphans
|
||||
docker system prune -af
|
||||
|
||||
# Release (TODO: implement proper versioning)
|
||||
release: check build docker-build ## Build release version
|
||||
@echo "Release build completed"
|
||||
|
||||
# Production deployment (example)
|
||||
deploy-staging: ## Deploy to staging environment
|
||||
@echo "Deploying to staging..."
|
||||
# Add your staging deployment commands here
|
||||
|
||||
deploy-prod: ## Deploy to production environment
|
||||
@echo "Deploying to production..."
|
||||
# Add your production deployment commands here
|
||||
|
||||
# Generate documentation
|
||||
docs: ## Generate API documentation
|
||||
# Generate API documentation
|
||||
docs:
|
||||
@echo "Generating API documentation..."
|
||||
# Add swagger/openapi generation here
|
||||
@swag init -g cmd/web/main.go -o cmd/web/docs
|
||||
@echo "Swagger documentation generated successfully!"
|
||||
|
||||
# Security
|
||||
security-scan: ## Run security scan on dependencies
|
||||
$(GOCMD) list -json -deps ./... | nancy sleuth
|
||||
# Run server with documentation
|
||||
run-docs: docs run
|
||||
|
||||
# Installation
|
||||
install: ## Install the application globally
|
||||
$(GOCMD) install $(MAIN_PATH)
|
||||
# Database migrations (placeholder)
|
||||
migrate:
|
||||
@echo "Running database migrations..."
|
||||
@echo "TODO: Implement database migrations"
|
||||
|
||||
# Environment setup for new developers
|
||||
setup: ## Setup development environment
|
||||
@echo "Setting up development environment..."
|
||||
$(GOMOD) download
|
||||
@echo "Installing development tools..."
|
||||
$(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
@echo "Setup completed! Run 'make dev-up' to start services and 'make run' to start the API."
|
||||
|
||||
# Show build information
|
||||
info: ## Show build information
|
||||
@echo "Binary Name: $(BINARY_NAME)"
|
||||
@echo "Main Path: $(MAIN_PATH)"
|
||||
@echo "Build Directory: $(BUILD_DIR)"
|
||||
@echo "Go Version: $(shell $(GOCMD) version)"
|
||||
@echo "Git Commit: $(shell git rev-parse --short HEAD 2>/dev/null || echo 'N/A')"
|
||||
@echo "Build Time: $(shell date)"
|
||||
|
||||
# All-in-one development start
|
||||
dev: deps dev-up ## Setup and start complete development environment
|
||||
@echo "Development environment is ready!"
|
||||
@echo "API will be available at: http://localhost:8080"
|
||||
@echo "MongoDB: localhost:27017"
|
||||
@echo "Redis: localhost:6379"
|
||||
@echo "RabbitMQ Management: http://localhost:15672 (admin/password)"
|
||||
@echo "Elasticsearch: http://localhost:9200"
|
||||
@echo "Kibana: http://localhost:5601"
|
||||
# Seed database (placeholder)
|
||||
seed:
|
||||
@echo "Seeding database..."
|
||||
@echo "TODO: Implement database seeding"
|
||||
Reference in New Issue
Block a user