make_post_sell/Makefile

355 lines
14 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Makefile for operating the make_post_sell server using either PyPI packages or source
# Variables (using the current working directory)
VENV_DIR = $(shell pwd)/env
DATA_DIR = $(shell pwd)/data
CONFIG_FILE = development.ini
# Using the provided configuration URL.
CONFIG_URL = https://git.unturf.com/engineering/make-post-sell/make_post_sell/-/raw/master/development.ini
PYTHON = $(VENV_DIR)/bin/python
PIP = $(VENV_DIR)/bin/pip
PSERVE = $(VENV_DIR)/bin/pserve
ALEMBIC = $(VENV_DIR)/bin/alembic
MPS_INIT = $(VENV_DIR)/bin/initialize_make_post_sell_db
# Default target: show help
.DEFAULT_GOAL := help
# Help target - shows all available commands
help:
@echo "Make Post Sell - Available Commands"
@echo "==================================="
@echo ""
@echo "SETUP & INSTALLATION:"
@echo " make venv - Create Python virtual environment"
@echo " make config - Download configuration file"
@echo " make install-from-pypi - Complete setup using PyPI packages"
@echo " make install-from-source - Complete setup from source (dev mode)"
@echo " make install-from-source-prod - Production install from source"
@echo ""
@echo "DATABASE:"
@echo " make init-db - Initialize the database"
@echo ""
@echo "DEVELOPMENT:"
@echo " make serve - Start development server with auto-reload"
@echo " make test - Run test suite"
@echo " make test-coverage - Run tests with coverage report"
@echo " make http - Start simple HTTP server on port 8000"
@echo " make activate - Show how to activate virtual environment"
@echo ""
@echo "CRYPTOCURRENCY (MONERO):"
@echo " make check-monero - Check if Monero tools are installed"
@echo " make install-monero - Install Monero tools automatically"
@echo " make monero-wallet-create - Create new Monero wallet (first time)"
@echo " make monero-node - Start local Monero node (150GB required)"
@echo " make monero-wallet - Start wallet RPC with local node"
@echo " make monero-wallet-remote - Start wallet RPC with remote node (dev)"
@echo " make monero-full-stack - Show instructions for complete setup"
@echo " make crypto-watcher - Start payment monitoring service"
@echo " make crypto-watcher-once - Run payment check once (testing)"
@echo ""
@echo "WALLET MANAGEMENT:"
@echo " make sweep-check - Check hot wallet balances (dry run)"
@echo " make sweep - Sweep funds to cold storage"
@echo ""
@echo "CLEANUP:"
@echo " make clean - Remove virtual environment"
@echo ""
@echo "For more info, see README.md and CRYPTO.rst"
# -----------------------------------------------------------------------------
# Environment Setup Targets
# -----------------------------------------------------------------------------
# Create virtual environment if not present.
$(VENV_DIR)/bin/activate:
@echo "Creating virtual environment in $(VENV_DIR)..."
python3 -m venv $(VENV_DIR)
venv: $(VENV_DIR)/bin/activate
# Create data directory and download configuration file if missing.
$(DATA_DIR)/$(CONFIG_FILE):
@echo "Creating data directory in $(DATA_DIR) and downloading configuration file..."
mkdir -p $(DATA_DIR)
cd $(DATA_DIR) && wget -O $(CONFIG_FILE) $(CONFIG_URL)
config: $(DATA_DIR)/$(CONFIG_FILE)
# -----------------------------------------------------------------------------
# Package Installation Targets for PyPI Installation
# -----------------------------------------------------------------------------
# Install the make_post_sell core package from PyPI.
install-core: venv
@echo "Installing make_post_sell core package from PyPI..."
$(PIP) install make_post_sell
# Install development extras from PyPI.
install-dev: venv
@echo "Installing make_post_sell development extras from PyPI..."
$(PIP) install make_post_sell[dev]
# Combined PyPI installation target.
install: install-core install-dev
# -----------------------------------------------------------------------------
# Package Installation Targets for Source Installation
# -----------------------------------------------------------------------------
# Install from source (editable mode) for development and testing.
install-source-dev-and-test: venv
@echo "Installing make_post_sell from source (editable mode) for development..."
$(PIP) install --editable .
$(PIP) install --upgrade -r requirements-dev.txt
$(PIP) install --upgrade -r requirements-test.txt
# Install from source for production (non‑editable).
install-source-prod: venv
@echo "Deleting tests from source code for production..."
rm -rf make_post_sell/tests
@echo "Installing make_post_sell from source for production (non‑editable)..."
$(PIP) install .
$(PIP) install --upgrade -r requirements-prod.txt
# -----------------------------------------------------------------------------
# Database Initialization and Server Targets
# -----------------------------------------------------------------------------
# Initialize the database using the configuration file.
init-db: venv config
@echo "Initializing the make_post_sell database..."
$(MPS_INIT) $(DATA_DIR)/$(CONFIG_FILE)
$(ALEMBIC) -c $(DATA_DIR)/$(CONFIG_FILE) stamp head
# Start the development server with auto-reload.
serve: venv config
@echo "Starting the make_post_sell development server..."
$(PSERVE) $(DATA_DIR)/$(CONFIG_FILE) --reload
# -----------------------------------------------------------------------------
# Combined Setup Targets
# -----------------------------------------------------------------------------
# Install and set up using PyPI packages.
install-from-pypi: venv config install init-db
# Install and set up from source (editable mode) for development and testing.
install-from-source: venv config install-source-dev-and-test init-db
# Install and set up from source for production (non‑editable).
install-from-source-prod: venv config install-source-prod init-db
# -----------------------------------------------------------------------------
# Additional Targets
# -----------------------------------------------------------------------------
# Print instructions for activating the virtual environment.
activate:
@echo "To activate the virtual environment, run:"
@echo " source $(VENV_DIR)/bin/activate"
# Run the test suite.
test: install-source-dev-and-test
@echo "Running tests..."
$(VENV_DIR)/bin/py.test
# Run tests with coverage for the full repository.
test-coverage: install-source-dev-and-test
@echo "Running tests with coverage..."
$(VENV_DIR)/bin/py.test --cov=make_post_sell --cov-report=term-missing --cov-report=html
# Start a simple HTTP server (if needed for static files).
http: venv
@echo "Starting simple HTTP server on port 8000..."
$(PYTHON) -m http.server 8000
# Run the crypto watcher service for monitoring Monero payments.
crypto-watcher: venv config
@echo "Starting crypto payment watcher..."
$(VENV_DIR)/bin/crypto_watcher $(DATA_DIR)/$(CONFIG_FILE)
# Run the crypto watcher once (for testing or manual processing).
crypto-watcher-once: venv config
@echo "Running crypto payment watcher once..."
$(VENV_DIR)/bin/crypto_watcher $(DATA_DIR)/$(CONFIG_FILE) --once
# Check hot wallet balance (dry run).
sweep-check: venv config
@echo "Checking hot wallet balance..."
@echo "IMPORTANT: Set COLD_WALLET_ADDRESS environment variable first!"
$(VENV_DIR)/bin/sweep_to_cold $(DATA_DIR)/$(CONFIG_FILE) $${COLD_WALLET_ADDRESS:-ADDRESS_NOT_SET} --dry-run
# Sweep excess funds to cold storage.
sweep: venv config
@echo "Sweeping excess funds to cold storage..."
@echo "IMPORTANT: Set COLD_WALLET_ADDRESS environment variable first!"
$(VENV_DIR)/bin/sweep_to_cold $(DATA_DIR)/$(CONFIG_FILE) $${COLD_WALLET_ADDRESS:-ADDRESS_NOT_SET}
# -----------------------------------------------------------------------------
# Monero Infrastructure Targets
# -----------------------------------------------------------------------------
# Start the Monero daemon (blockchain node) - requires ~150GB disk space
monero-node: venv config check-monero
@echo "Starting Monero daemon (monerod)..."
@echo "This will download ~150GB blockchain data and may take 1-2 days to sync"
@mkdir -p $(DATA_DIR)/monero-blockchain
@echo "Checking available disk space..."
@available=$$(df -BG $(DATA_DIR) | tail -1 | awk '{print $$4}' | sed 's/G//'); \
if [ $$available -lt 200 ]; then \
echo "ERROR: Insufficient disk space!"; \
echo "Available: $${available}GB"; \
echo "Required: 200GB+ (150GB blockchain + growth)"; \
exit 1; \
else \
echo "Disk space OK: $${available}GB available"; \
fi
@echo "Check sync status at: http://127.0.0.1:18081/get_info"
@echo "Press Ctrl+C to stop"
monerod --data-dir=$(DATA_DIR)/monero-blockchain \
--rpc-bind-ip=127.0.0.1 \
--rpc-bind-port=18081 \
--confirm-external-bind \
--log-level=1
# Start the Monero wallet RPC (requires monerod or remote node)
monero-wallet: venv config check-monero
@echo "Starting Monero wallet RPC..."
@echo "Make sure monerod is running and synced first!"
@echo "Wallet file: $(DATA_DIR)/mps-wallet"
@echo "RPC will be available at: http://127.0.0.1:18083"
monero-wallet-rpc \
--wallet-file=$(DATA_DIR)/mps-wallet \
--password-file=$(DATA_DIR)/wallet-password.txt \
--rpc-bind-ip=127.0.0.1 \
--rpc-bind-port=18083 \
--disable-rpc-login \
--daemon-address=127.0.0.1:18081 \
--trusted-daemon \
--log-level=1
# Development mode - use remote node (no blockchain download needed)
monero-wallet-remote: venv config check-monero
@echo "Starting wallet with REMOTE node (development/testing only)..."
@echo "Using public node - less private but no blockchain download"
@echo "Wallet file: $(DATA_DIR)/mps-wallet"
@echo "RPC will be available at: http://127.0.0.1:18083"
@echo ""
@echo "Trying primary node: opennode.xmr-tw.org:18089"
monero-wallet-rpc \
--wallet-file=$(DATA_DIR)/mps-wallet \
--password-file=$(DATA_DIR)/wallet-password.txt \
--rpc-bind-ip=127.0.0.1 \
--rpc-bind-port=18083 \
--disable-rpc-login \
--daemon-address=opennode.xmr-tw.org:18089 \
--trusted-daemon \
--log-level=1
# Install Monero tools automatically
install-monero:
@echo "Installing Monero tools..."
@if [ "$$(uname)" = "Linux" ]; then \
mkdir -p $(HOME)/.local/bin && \
cd /tmp && \
wget -q --show-progress https://downloads.getmonero.org/cli/linux64 && \
tar -xf linux64 && \
cp monero-x*/monero* $(HOME)/.local/bin/ && \
rm -rf monero-x* linux64 && \
echo "✓ Monero tools installed to $(HOME)/.local/bin/" && \
echo "" && \
echo "Add to your PATH by running:" && \
echo " export PATH=\"$(HOME)/.local/bin:\$$PATH\"" && \
echo "Or add that line to your ~/.bashrc or ~/.zshrc" && \
echo "" && \
echo "Then run 'make monero-wallet-create' to create a wallet"; \
elif [ "$$(uname)" = "Darwin" ]; then \
if command -v brew >/dev/null 2>&1; then \
brew install monero; \
else \
echo "Please install Homebrew first: https://brew.sh"; \
exit 1; \
fi; \
else \
echo "Unsupported OS. Please download manually from:"; \
echo "https://www.getmonero.org/downloads/"; \
exit 1; \
fi
# Check if Monero tools are installed and provide install instructions
check-monero:
@if command -v monero-wallet-rpc >/dev/null 2>&1; then \
echo "✓ Monero tools found: $$(monero-wallet-rpc --version | head -1)"; \
else \
echo "❌ Monero tools not found!"; \
echo ""; \
if [ "$$(uname)" = "Linux" ]; then \
echo "Install on Linux:"; \
echo "Download latest official release (recommended):"; \
echo " wget https://downloads.getmonero.org/cli/linux64"; \
echo " tar -xf linux64 && sudo cp monero-x*/monero* /usr/local/bin/"; \
echo ""; \
echo "Or install to user directory (no sudo):"; \
echo " mkdir -p $$HOME/.local/bin"; \
echo " wget https://downloads.getmonero.org/cli/linux64"; \
echo " tar -xf linux64 && cp monero-x*/monero* $$HOME/.local/bin/"; \
echo " export PATH=\"$$HOME/.local/bin:$$PATH\""; \
elif [ "$$(uname)" = "Darwin" ]; then \
echo "Install on macOS:"; \
echo " brew install monero"; \
echo ""; \
echo "Or download latest official release:"; \
echo " wget https://downloads.getmonero.org/cli/mac64"; \
echo " tar -xf mac64 && sudo cp monero-x*/monero* /usr/local/bin/"; \
else \
echo "Download latest official Monero CLI tools:"; \
echo " https://www.getmonero.org/downloads/"; \
echo " Extract and copy monero-* binaries to /usr/local/bin/"; \
fi; \
echo ""; \
echo "Package managers may have older versions. Official downloads are recommended."; \
echo "After installing, run this command again."; \
exit 1; \
fi
# Create a new Monero wallet for the shop
monero-wallet-create: check-monero
@echo "Creating new Monero wallet..."
@echo "IMPORTANT: Save the 25-word mnemonic seed that will be displayed!"
@echo "Enter a password for the wallet (or leave empty):"
@read -s password; echo $$password > $(DATA_DIR)/wallet-password.txt
monero-wallet-cli --generate-new-wallet=$(DATA_DIR)/mps-wallet \
--password-file=$(DATA_DIR)/wallet-password.txt
@echo "Wallet created at: $(DATA_DIR)/mps-wallet"
@echo "Password saved in: $(DATA_DIR)/wallet-password.txt"
@echo "Now run 'make monero-wallet' or 'make monero-wallet-remote' to start the RPC server"
# Instructions for running the full Monero stack
monero-full-stack:
@echo "=== Running Full Monero Payment Stack ==="
@echo ""
@echo "For PRODUCTION (most secure, requires ~150GB):"
@echo " Terminal 1: make monero-node # Start blockchain node"
@echo " Terminal 2: make monero-wallet # Start wallet RPC (after node syncs)"
@echo " Terminal 3: make crypto-watcher # Start payment watcher"
@echo " Terminal 4: make serve # Start web application"
@echo ""
@echo "For DEVELOPMENT (quick start, uses public node):"
@echo " Terminal 1: make monero-wallet-remote # Start wallet with remote node"
@echo " Terminal 2: make crypto-watcher # Start payment watcher"
@echo " Terminal 3: make serve # Start web application"
@echo ""
@echo "First time? Run 'make monero-wallet-create' to create a wallet"
# -----------------------------------------------------------------------------
# Cleanup Target
# -----------------------------------------------------------------------------
# Remove the virtual environment directories.
clean:
@echo "Cleaning up: removing $(VENV_DIR)"
rm -rf $(VENV_DIR)