Add files via upload

This commit is contained in:
Tomáš Dvořák
2025-05-22 12:01:13 +02:00
committed by GitHub
parent a10848bc72
commit 3ac3e9e407
2 changed files with 60 additions and 141 deletions
+31 -134
View File
@@ -1,141 +1,38 @@
# Contact Scrape Makefile
.PHONY: build run clean install dev test help
# Root Makefile for PROG+HTML project
.PHONY: all dev run build clean help
# Variables
BINARY_NAME=contact-scrape
MAIN_PORT ?= 80
KONTAKT_PORT ?= 8081
BUILD_DIR = build
PORT=8080
##@ Development
alldev: ## Start both main and kontakt services
@echo "Starting all services..."
@make -j2 main-dev kontakt-dev
main-dev: ## Start main service
@echo "Starting main service on port $(MAIN_PORT)..."
@PORT=$(MAIN_PORT) go run main.go
kontakt-dev: ## Start kontakt service
@echo "Starting kontakt service on port $(KONTAKT_PORT)..."
@cd kontakt && PORT=$(KONTAKT_PORT) make dev
##@ Build
build: ## Build all services
@echo "Building all services..."
@mkdir -p $(BUILD_DIR)
@go build -o $(BUILD_DIR)/main main.go
@cd kontakt && make build
##@ Clean
clean: ## Clean all build artifacts
@rm -rf $(BUILD_DIR)
@cd kontakt && make clean
@echo "All build artifacts removed"
##@ Help
help: ## Show this help message
@echo "Available commands:"
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
dev: ## Run the application in development mode
@echo "Starting development server..."
@go run .
run: build ## Build and run the application
@echo "Starting $(BINARY_NAME)..."
@./$(BUILD_DIR)/$(BINARY_NAME)
test: ## Run tests
@echo "Running tests..."
@go test -v ./...
##@ Build
build: ## Build the application
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
@go build -o $(BUILD_DIR)/$(BINARY_NAME) .
@echo "Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
build-linux: ## Build for Linux (useful for deployment)
@echo "Building $(BINARY_NAME) for Linux..."
@mkdir -p $(BUILD_DIR)
@GOOS=linux GOARCH=amd64 go build -o $(BUILD_DIR)/$(BINARY_NAME)-linux .
@echo "Linux binary built: $(BUILD_DIR)/$(BINARY_NAME)-linux"
##@ Dependencies
deps: ## Download dependencies
@echo "Downloading dependencies..."
@go mod download
@go mod tidy
##@ Deployment
install: build ## Install the service (requires sudo)
@echo "Installing contact-scrape service..."
@sudo mkdir -p /opt/contact-scrape
@sudo cp $(BUILD_DIR)/$(BINARY_NAME) /opt/contact-scrape/
@sudo cp index.html /opt/contact-scrape/
@sudo mkdir -p /opt/contact-scrape/data
@sudo chown -R www-data:www-data /opt/contact-scrape
@sudo cp contact-scrape.service /etc/systemd/system/
@sudo systemctl daemon-reload
@sudo systemctl enable contact-scrape
@echo "Service installed. Start with: sudo systemctl start contact-scrape"
uninstall: ## Uninstall the service (requires sudo)
@echo "Uninstalling contact-scrape service..."
@sudo systemctl stop contact-scrape 2>/dev/null || true
@sudo systemctl disable contact-scrape 2>/dev/null || true
@sudo rm -f /etc/systemd/system/contact-scrape.service
@sudo systemctl daemon-reload
@sudo rm -rf /opt/contact-scrape
@echo "Service uninstalled."
status: ## Check service status
@sudo systemctl status contact-scrape
start: ## Start the service
@sudo systemctl start contact-scrape
stop: ## Stop the service
@sudo systemctl stop contact-scrape
restart: ## Restart the service
@sudo systemctl restart contact-scrape
logs: ## View service logs
@sudo journalctl -u contact-scrape -f
##@ File Management
upload-xlsx: ## Upload contacts.xlsx to server (set SERVER variable)
@if [ -z "$(SERVER)" ]; then echo "Usage: make upload-xlsx SERVER=user@hostname"; exit 1; fi
@echo "Uploading contacts.xlsx to $(SERVER)..."
@scp contacts.xlsx $(SERVER):/opt/contact-scrape/
@ssh $(SERVER) "sudo chown www-data:www-data /opt/contact-scrape/contacts.xlsx"
@ssh $(SERVER) "sudo systemctl restart contact-scrape"
@echo "File uploaded and service restarted."
##@ Monitoring
monitor: ## Monitor the service with file watching
@echo "Monitoring contacts.xlsx for changes..."
@while true; do \
inotifywait -e modify contacts.xlsx 2>/dev/null && \
echo "File changed, reloading..." && \
curl -X POST http://localhost:$(PORT)/kontakt/reload; \
sleep 1; \
done
##@ Utilities
clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
@rm -f data/contacts.json
setup-dirs: ## Create necessary directories
@mkdir -p data
@mkdir -p $(BUILD_DIR)
check-file: ## Check if contacts.xlsx exists and show info
@if [ -f "contacts.xlsx" ]; then \
echo "✓ contacts.xlsx found"; \
ls -lh contacts.xlsx; \
else \
echo "✗ contacts.xlsx not found"; \
echo "Please place your Excel file in the current directory"; \
fi
##@ Docker (Optional)
docker-build: ## Build Docker image
@echo "Building Docker image..."
@docker build -t contact-scrape .
docker-run: ## Run in Docker container
@echo "Running Docker container..."
@docker run -p $(PORT):$(PORT) -v $(PWD)/contacts.xlsx:/app/contacts.xlsx -v $(PWD)/data:/app/data contact-scrape
##@ Information
info: ## Show application information
@echo "Contact Scrape Application"
@echo "========================="
@echo "Port: $(PORT)"
@echo "Binary: $(BINARY_NAME)"
@echo "Build dir: $(BUILD_DIR)"
@echo ""
@echo "Endpoints:"
@echo " http://localhost:$(PORT)/kontakt - Web interface"
@echo " http://localhost:$(PORT)/kontakt/contacts - JSON API"
@echo " http://localhost:$(PORT)/kontakt/reload - Reload data (POST)"
+22
View File
@@ -0,0 +1,22 @@
# Makefile for kontakt service
.PHONY: dev run build clean
PORT ?= 8081
BINARY_NAME := kontakt-service
BUILD_DIR := build
##@ Development
dev: ## Run in development mode
@echo "Starting kontakt service..."
@go run contact-scrape.go
run: build ## Run built binary
@$(BUILD_DIR)/$(BINARY_NAME)
build: ## Build the application
@echo "Building kontakt service..."
@go build -o $(BUILD_DIR)/$(BINARY_NAME) contact-scrape.go
clean: ## Clean build artifacts
@rm -rf $(BUILD_DIR)
@echo "Build artifacts removed"