Makefile 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. BIN := venv/bin/activate
  2. PYTHON := python
  3. export LOG_HOME := $(shell echo ~/.local/share/darkfi/explorer_site)
  4. help:
  5. @echo "Explorer Site Makefile Commands:"
  6. @echo ""
  7. @echo "Installation and cleanup:"
  8. @echo " make install - Install Python dependencies in a virtual environment"
  9. @echo " make clean - Remove the virtual environment and installed dependencies"
  10. @echo ""
  11. @echo "Server management:"
  12. @echo " make start-localnet - Start explorer site on localnet environment"
  13. @echo " make start-testnet - Start explorer site on testnet environment"
  14. @echo " make start-mainnet - Start explorer site on mainnet environment"
  15. @echo " make stop - Stop running explorer site"
  16. install: $(BIN)
  17. # Create the virtual environment and install dependencies
  18. $(BIN): requirements.txt
  19. @echo "Installing dependencies..."
  20. @if [ ! -d venv ]; then \
  21. $(PYTHON) -m venv venv; \
  22. fi; \
  23. . venv/bin/activate && pip install -q -r requirements.txt
  24. # Remove virtual environment
  25. clean:
  26. @rm -rf venv
  27. @echo "Cleaned the virtual environment!"
  28. # Start the server for the specified network (localnet, testnet, mainnet)
  29. start-%: install
  30. @if [ "$*" != "localnet" ] && [ "$*" != "testnet" ] && [ "$*" != "mainnet" ]; then \
  31. echo "Error: Unsupported environment '$*'. Supported values are 'localnet', 'testnet', and 'mainnet'."; \
  32. exit 1; \
  33. fi
  34. @if [ -f flask.pid ] && [ "$*" = "localnet" ]; then \
  35. echo "Explorer site is already running (PID=$$(cat flask.pid)). Stop it first before starting."; \
  36. exit 1; \
  37. elif [ -f gunicorn.pid ] && { [ "$*" = "testnet" ] || [ "$*" = "mainnet" ]; }; then \
  38. echo "Explorer site is already running (PID=$$(cat gunicorn.pid)). Stop it first before starting."; \
  39. exit 1; \
  40. fi
  41. @. venv/bin/activate && if [ "$*" = "testnet" ] || [ "$*" = "mainnet" ]; then \
  42. FLASK_ENV=$* gunicorn --config gunicorn_config.py wsgi:app & PID=$$!; \
  43. echo $$PID > gunicorn.pid; \
  44. echo "Explorer site started on $* network (PID=$$PID)"; \
  45. if [ "$*" = "testnet" ]; then \
  46. echo "See site logfile $(LOG_HOME)/testnet/app.log for server startup details"; \
  47. fi; \
  48. if [ "$*" = "mainnet" ]; then \
  49. echo "See site logfile $(LOG_HOME)/mainnet/app.log for server startup details"; \
  50. fi; \
  51. else \
  52. FLASK_ENV=$* python -m flask run & PID=$$!; \
  53. echo $$PID > flask.pid; \
  54. echo "Started explorer site on $* network (PID=$$PID)"; \
  55. fi
  56. # Stop the explorer sites that are running
  57. stop:
  58. @if [ -f flask.pid ] || [ -f gunicorn.pid ]; then \
  59. [ -f flask.pid ] && kill $$(cat flask.pid) 2>/dev/null || true; \
  60. rm -f flask.pid; \
  61. [ -f gunicorn.pid ] && kill $$(cat gunicorn.pid) 2>/dev/null || true; \
  62. rm -f gunicorn.pid; \
  63. echo "Stopped running explorer sites"; \
  64. else \
  65. echo "An explorer site is not running, nothing to stop."; \
  66. fi
  67. # Declare PHONY targets
  68. .PHONY: all start-% install clean stop-server