Skip to content

Commit

Permalink
explorer/site: Add Makefile for simplified Flask Explorer site manage…
Browse files Browse the repository at this point in the history
…ment

Introduced a Makefile to streamline the setup, startup, and shutdown of the Flask Explorer site across different networks (localnet, testnet, mainnet). It simplifies server management and cleanup with straightforward commands.

In future iterations, `testnet` and `mainnet` environments may transition to production-ready setups (e.g., running behind a reverse proxy). This implementation serves as a starting point and is expected to be expanded upon.

Summary of Updates:
- Automatic virtual environment setup and dependency installation (`all`, ``install` targets)
- Added targets to start the Flask server for localnet, testnet, and mainnet networks
- Implemented the use of a `flask.pid` file to track the Flask server’s process ID (PID), enabling proper process termination during the `stop-server` target
- Provided a `clean` target to remove the virtual environment and reset the workspace
  • Loading branch information
kalm committed Mar 8, 2025
1 parent 5a56634 commit a839603
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions bin/explorer/site/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
BIN := venv/bin/activate
PYTHON := /opt/tools/python/bin/python3.12

all: $(BIN)

# Create the virtual environment and install dependencies
$(BIN): requirements.txt
@echo "Installing dependencies..."
@if [ ! -d venv ]; then \
$(PYTHON) -m venv venv; \
fi; \
. venv/bin/activate && pip install -r requirements.txt

# Start the Flask server for the specified network (localnet, testnet, mainnet)
start-%: all
@if [ "$*" != "localnet" ] && [ "$*" != "testnet" ] && [ "$*" != "mainnet" ]; then \
echo "Error: Unsupported environment '$*'. Supported values are 'localnet', 'testnet', and 'mainnet'."; \
exit 1; \
fi
@if [ -f flask.pid ]; then \
echo "Flask server is already running (PID=$$(cat flask.pid)). Stop it first before starting."; \
exit 1; \
fi
@. venv/bin/activate && \
FLASK_ENV=$* python -m flask run & PID=$$!; \
echo $$PID > flask.pid; \
echo "Started flask server on $* network (PID=$$PID)"

# Stop the Flask server if running
stop-server:
@if [ -f flask.pid ]; then \
PID=$$(cat flask.pid); \
kill $$PID; \
rm -f flask.pid; \
echo "Stopped Flask server"; \
else \
echo "Flask server is not running, nothing to stop."; \
fi

# Install dependencies (alias for 'all')
install: all

# Remove virtual environment
clean:
@rm -rf venv
@echo "Cleaned the virtual environment!"

# Declare PHONY targets
.PHONY: all start-% install clean stop-server

0 comments on commit a839603

Please sign in to comment.