Files
projectmycelium/Makefile

208 lines
11 KiB
Makefile

build: ## Build and run the application locally
@$(MAKE) check-env
cargo build && cargo run --bin projectmycelium
# Run locally in fixtures mode (no mocks)
fixtures-run: ## Run the backend with APP_DATA_SOURCE=fixtures using ./user_data
APP_DATA_SOURCE=fixtures APP_FIXTURES_PATH=./user_data APP_ENABLE_MOCKS=0 cargo run --bin projectmycelium
# Quick compile check in fixtures mode
fixtures-check: ## Cargo check with fixtures active
APP_DATA_SOURCE=fixtures APP_FIXTURES_PATH=./user_data APP_ENABLE_MOCKS=0 cargo check
# Run tests in fixtures mode
test-fixtures: ## Run cargo tests with fixtures active
APP_DATA_SOURCE=fixtures APP_FIXTURES_PATH=./user_data APP_ENABLE_MOCKS=0 cargo test
# Error-only Rust diagnostics (writes to /tmp/cargo_errors_only.log)
check-errors: ## Run cargo check and write error-only log to /tmp/cargo_errors_only.log
scripts/dev/cargo-errors.sh
fixtures-errors: ## Run cargo check (fixtures) and write error-only log to /tmp/cargo_errors_only.log
APP_DATA_SOURCE=fixtures APP_FIXTURES_PATH=./user_data APP_ENABLE_MOCKS=0 scripts/dev/cargo-errors.sh
key: ## Generate a new SECRET_KEY in .env file
cp .env.example .env; \
KEY=$$(openssl rand -base64 64 | tr -d '\n'); \
awk -v key="$$KEY" '{gsub(/^SECRET_KEY=.*/, "SECRET_KEY=" key)}1' .env > .env.tmp && mv .env.tmp .env
# Check if .env exists and has a valid SECRET_KEY, generate if needed
check-env:
@if [ ! -f .env ]; then \
echo "INFO: .env file not found. Generating from template..."; \
$(MAKE) key; \
elif ! grep -q "^SECRET_KEY=" .env || grep -q "^SECRET_KEY=your_secret_key_here" .env; then \
echo "INFO: SECRET_KEY not set or using placeholder. Generating key..."; \
KEY=$$(openssl rand -base64 64 | tr -d '\n'); \
awk -v key="$$KEY" '{gsub(/^SECRET_KEY=.*/, "SECRET_KEY=" key)}1' .env > .env.tmp && mv .env.tmp .env; \
echo "INFO: SECRET_KEY generated. Please add your GITEA_USER and GITEA_TOKEN to .env"; \
fi
# Remote deployment targets
update-dev: ## Update development environment (git pull + restart)
@echo "🔄 Updating development environment..."
@echo "📥 Pulling latest development changes..."
@ssh root@info.ourworld.tf 'cd /root/code/git.ourworld.tf/tfgrid_research/dev/threefold-marketplace && git checkout development && git pull'
@echo "🔄 Restarting development service..."
@ssh root@info.ourworld.tf 'zinit restart projectmycelium-dev'
@echo "✅ Development update complete!"
update-prod: ## Update production environment (git pull + restart)
@echo "🔄 Updating production environment..."
@echo "📥 Pulling latest main changes..."
@ssh root@info.ourworld.tf 'cd /root/code/git.ourworld.tf/tfgrid_research/prod/threefold-marketplace && git checkout main && git pull'
@echo "🔄 Restarting production service..."
@ssh root@info.ourworld.tf 'zinit restart projectmycelium-prod'
@echo "✅ Production update complete!"
rm-dev: ## Remove development repo directory on server (DANGEROUS)
@echo "🧨 Removing development repo on server..."
@ssh root@info.ourworld.tf 'zinit stop projectmycelium-dev || true'
@ssh root@info.ourworld.tf 'rm -rf /root/code/git.ourworld.tf/tfgrid_research/dev/threefold-marketplace'
@ssh root@info.ourworld.tf 'test ! -d /root/code/git.ourworld.tf/tfgrid_research/dev/threefold-marketplace && echo "✅ Dev repo removed" || (echo "❌ Failed to remove dev repo" && exit 1)'
rm-prod: ## Remove production repo directory on server (DANGEROUS)
@echo "🧨 Removing production repo on server..."
@ssh root@info.ourworld.tf 'zinit stop projectmycelium-prod || true'
@ssh root@info.ourworld.tf 'rm -rf /root/code/git.ourworld.tf/tfgrid_research/prod/threefold-marketplace'
@ssh root@info.ourworld.tf 'test ! -d /root/code/git.ourworld.tf/tfgrid_research/prod/threefold-marketplace && echo "✅ Prod repo removed" || (echo "❌ Failed to remove prod repo" && exit 1)'
clone-dev: ## Clone development repo on server and start service
@echo "📥 Cloning development repository on server..."
@ssh root@info.ourworld.tf 'mkdir -p /root/code/git.ourworld.tf/tfgrid_research/dev && cd /root/code/git.ourworld.tf/tfgrid_research/dev && if [ -d threefold-marketplace ]; then echo "Repo already exists. Skipping clone."; else git clone https://git.ourworld.tf/tfgrid_research/threefold-marketplace.git; fi'
@ssh root@info.ourworld.tf 'cd /root/code/git.ourworld.tf/tfgrid_research/dev/threefold-marketplace && git checkout development || echo "Branch development not found, using default."'
@echo "🚀 Starting development service..."
@ssh root@info.ourworld.tf 'zinit start projectmycelium-dev'
clone-prod: ## Clone production repo on server and start service
@echo "📥 Cloning production repository on server..."
@ssh root@info.ourworld.tf 'mkdir -p /root/code/git.ourworld.tf/tfgrid_research/prod && cd /root/code/git.ourworld.tf/tfgrid_research/prod && if [ -d threefold-marketplace ]; then echo "Repo already exists. Skipping clone."; else git clone https://git.ourworld.tf/tfgrid_research/threefold-marketplace.git; fi'
@ssh root@info.ourworld.tf 'cd /root/code/git.ourworld.tf/tfgrid_research/prod/threefold-marketplace && git checkout main || echo "Branch main not found, using default."'
@echo "🚀 Starting production service..."
@ssh root@info.ourworld.tf 'zinit start projectmycelium-prod'
setup-dev: ## Setup development environment (first-time)
@echo "<22> Setting up development service on server..."
@if [ ! -f .env.deploy ]; then \
echo "❌ Error: .env.deploy file not found"; \
echo " Please create .env.deploy from .env.deploy.example with your Gitea credentials"; \
exit 1; \
fi
@if ! grep -q "^GITEA_USER=" .env.deploy || ! grep -q "^GITEA_TOKEN=" .env.deploy || grep -q "your_username" .env.deploy || grep -q "your_personal_access_token" .env.deploy; then \
echo "❌ Error: Please set your GITEA_USER and GITEA_TOKEN in .env.deploy file"; \
echo " Edit .env.deploy and set your Gitea credentials for deployment"; \
exit 1; \
fi
@echo "📋 Copying development deployment script..."
@scp scripts/projectmycelium-dev.sh root@info.ourworld.tf:/etc/zinit/cmds/projectmycelium-dev.sh
@ssh root@info.ourworld.tf 'chmod +x /etc/zinit/cmds/projectmycelium-dev.sh'
@echo "📋 Copying development service configuration..."
@scp config/zinit/projectmycelium-dev.yaml root@info.ourworld.tf:/etc/zinit/projectmycelium-dev.yaml
@echo "📋 Copying deployment credentials..."
@scp .env.deploy root@info.ourworld.tf:/tmp/projectmycelium-deploy.env
@echo "🔍 Setting up development monitoring..."
@ssh root@info.ourworld.tf 'zinit monitor projectmycelium-dev'
@echo "🚀 Starting development service..."
@ssh root@info.ourworld.tf 'zinit start projectmycelium-dev'
@echo "✅ Development setup complete!"
@echo "📊 Development service status:"
@ssh root@info.ourworld.tf 'zinit list | grep projectmycelium-dev'
setup-prod: ## Setup production environment (first-time)
@echo "🔧 Setting up production service on server..."
@if [ ! -f .env.deploy ]; then \
echo "❌ Error: .env.deploy file not found"; \
echo " Please create .env.deploy from .env.deploy.example with your Gitea credentials"; \
exit 1; \
fi
@if ! grep -q "^GITEA_USER=" .env.deploy || ! grep -q "^GITEA_TOKEN=" .env.deploy || grep -q "your_username" .env.deploy || grep -q "your_personal_access_token" .env.deploy; then \
echo "❌ Error: Please set your GITEA_USER and GITEA_TOKEN in .env.deploy file"; \
echo " Edit .env.deploy and set your Gitea credentials for deployment"; \
exit 1; \
fi
@echo "📋 Copying production deployment script..."
@scp scripts/projectmycelium-prod.sh root@info.ourworld.tf:/etc/zinit/cmds/projectmycelium-prod.sh
@ssh root@info.ourworld.tf 'chmod +x /etc/zinit/cmds/projectmycelium-prod.sh'
@echo "📋 Copying production service configuration..."
@scp config/zinit/projectmycelium-prod.yaml root@info.ourworld.tf:/etc/zinit/projectmycelium-prod.yaml
@echo "📋 Copying deployment credentials..."
@scp .env.deploy root@info.ourworld.tf:/tmp/projectmycelium-deploy.env
@echo "🔍 Setting up production monitoring..."
@ssh root@info.ourworld.tf 'zinit monitor projectmycelium-prod'
@echo "🚀 Starting production service..."
@ssh root@info.ourworld.tf 'zinit start projectmycelium-prod'
@echo "🔄 Restarting Caddy to load configurations..."
@ssh root@info.ourworld.tf 'zinit restart caddy'
@echo "✅ Production setup complete!"
@echo "📊 Production service status:"
@ssh root@info.ourworld.tf 'zinit list | grep projectmycelium-prod'
setup: ## Setup both dev and prod environments (complete setup)
@echo "🔧 Setting up both dev and prod services on server (complete setup)..."
@$(MAKE) setup-dev
@echo ""
@$(MAKE) setup-prod
@echo ""
@echo "✅ Complete setup finished!"
@echo "📊 All service status:"
@ssh root@info.ourworld.tf 'zinit list | grep projectmycelium'
status: ## Check service status on server
@echo "📊 Checking deployment status..."
@ssh root@info.ourworld.tf 'zinit list | grep projectmycelium'
logs-dev: ## View service logs from server
@echo "📋 Deployment logs:"
@echo "=== Development Logs ==="
@ssh root@info.ourworld.tf 'zinit log projectmycelium-dev'
@echo ""
logs-prod: ## View service logs from server
@echo "📋 Deployment logs:"
@echo "=== Production Logs ==="
@ssh root@info.ourworld.tf 'zinit log projectmycelium-prod'
@echo ""
help: ## Show this help message
@echo "🚀 ThreeFold Marketplace - Deployment Commands"
@echo ""
@echo "📋 Available commands:"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "🔧 Setup (first-time):"
@echo " setup-dev Setup development environment only"
@echo " setup-prod Setup production environment only"
@echo " setup Setup both dev and prod environments"
@echo ""
@echo "🔄 Updates (regular):"
@echo " update-dev Update development (git pull + restart)"
@echo " update-prod Update production (git pull + restart)"
@echo " clone-dev Clone dev repo on server and start service"
@echo " clone-prod Clone prod repo on server and start service"
@echo ""
@echo "⚠️ Dangerous:"
@echo " rm-dev Remove development repo directory on server"
@echo " rm-prod Remove production repo directory on server"
@echo ""
@echo "📊 Monitoring:"
@echo " status Check service status"
@echo " logs-dev View development service logs"
@echo " logs-prod View production service logs"
@echo ""
@echo "🛠️ Development:"
@echo " build Build and run locally"
@echo " fixtures-run Run locally with fixtures (APP_DATA_SOURCE=fixtures)"
@echo " fixtures-check Cargo check with fixtures configured"
@echo " test-fixtures Run tests with fixtures configured"
@echo " check-errors Run cargo check and write error-only log to /tmp/cargo_errors_only.log"
@echo " fixtures-errors Run cargo check (fixtures) and write error-only log"
@echo " key Generate SECRET_KEY"
@echo ""
@echo "💡 Quick start:"
@echo " 1. cp .env.deploy.example .env.deploy"
@echo " 2. Edit .env.deploy with your Gitea credentials"
@echo " 3. make setup-dev"
.PHONY: build fixtures-run fixtures-check test-fixtures check-errors fixtures-errors key check-env update-dev update-prod clone-dev clone-prod rm-dev rm-prod setup-dev setup-prod setup status logs help