Examples¶
Real-world examples showing how to use RunLy in different types of projects.
Python Projects¶
Basic Python Package¶
# Variables
package := "mypackage"
python := "python"
# Install development dependencies
install:
pip install -e .[dev]
# Format code
format:
black src/ tests/
isort src/ tests/
# Lint code
lint:
flake8 src/ tests/
mypy src/
# Run tests
*test: install
pytest tests/ --cov=src/{{package}} --cov-report=html
# Check everything
check: format lint test
echo "All checks passed!"
# Build package
build: check
python -m build
# Publish to PyPI
publish: build
twine upload dist/*
# Clean build artifacts
clean:
rm -rf build/ dist/ *.egg-info/ .coverage htmlcov/
Django Project¶
# Variables
manage := "python manage.py"
# Install dependencies
install:
pip install -r requirements.txt
# Database migrations
migrate: install
{{manage}} migrate
# Run development server
*serve port="8000": migrate
{{manage}} runserver {{port}}
# Run tests
test: install
{{manage}} test
# Collect static files
collectstatic: install
{{manage}} collectstatic --noinput
# Run production server
production: migrate collectstatic
gunicorn myproject.wsgi:application
Flask API¶
# Variables
app := "app.py"
host := "localhost"
port := "5000"
# Install dependencies
install:
pip install -r requirements.txt
# Run development server
*dev: install
FLASK_ENV=development flask run --host {{host}} --port {{port}}
# Run production server
prod: install
gunicorn -w 4 -b {{host}}:{{port}} app:app
# Run tests
test: install
pytest tests/ --cov=src/
JavaScript/Node.js Projects¶
React Application¶
# Install dependencies
install:
npm ci
# Start development server
*dev: install
npm start
# Build for production
build: install
npm run build
# Run tests
test: install
npm test
# Lint code
lint: install
npm run lint
# Deploy to production
deploy: build
npm run deploy
Express API¶
# Variables
port := env_var_or_default("PORT", "3000")
node_env := env_var_or_default("NODE_ENV", "development")
# Install dependencies
install:
npm ci
# Start development server with hot reload
*dev: install
NODE_ENV=development nodemon src/index.js
# Start production server
start: install
NODE_ENV=production node src/index.js
# Run tests
test: install
npm test
Docker Projects¶
Multi-service Application¶
# Variables
compose_file := "docker-compose.yml"
# Build all services
build:
docker-compose -f {{compose_file}} build
# Start all services
*up:
docker-compose -f {{compose_file}} up -d
# Stop all services
down:
docker-compose -f {{compose_file}} down
# View logs
logs service="":
@if [ -z "{{service}}" ]; then \
docker-compose -f {{compose_file}} logs -f; \
else \
docker-compose -f {{compose_file}} logs -f {{service}}; \
fi
# Execute command in service
exec service cmd:
docker-compose -f {{compose_file}} exec {{service}} {{cmd}}
# Clean up
clean:
docker-compose -f {{compose_file}} down -v --rmi all --remove-orphans
docker system prune -f
DevOps and CI/CD¶
Infrastructure as Code¶
# Variables
env := "dev"
region := "us-west-2"
# Initialize Terraform
init:
terraform init
# Plan infrastructure changes
plan env=env:
terraform plan -var-file="environments/{{env}}.tfvars"
# Apply infrastructure changes
apply env=env: (plan env)
terraform apply -var-file="environments/{{env}}.tfvars" -auto-approve
# Destroy infrastructure
destroy env=env:
terraform destroy -var-file="environments/{{env}}.tfvars" -auto-approve
# Validate Terraform files
validate:
terraform validate
terraform fmt -check
Kubernetes Deployment¶
# Variables
namespace := "default"
context := "minikube"
# Set kubectl context
set-context:
kubectl config use-context {{context}}
# Deploy application
*deploy: set-context
kubectl apply -f k8s/ -n {{namespace}}
# Delete deployment
delete: set-context
kubectl delete -f k8s/ -n {{namespace}}
# Scale deployment
scale replicas: set-context
kubectl scale deployment/myapp --replicas={{replicas}} -n {{namespace}}
# Get pod status
status: set-context
kubectl get pods -n {{namespace}}
Testing and Quality Assurance¶
Comprehensive Testing Suite¶
# Variables
coverage_threshold := "80"
# Install all dependencies
install:
pip install -e .[dev,test]
# Run unit tests
test-unit:
pytest tests/unit/ -v
# Run integration tests
test-integration:
pytest tests/integration/ -v
# Run all tests with coverage
*test: test-unit test-integration
pytest tests/ --cov=src/ --cov-report=html --cov-fail-under={{coverage_threshold}}
# Lint all code
lint:
flake8 src/ tests/
mypy src/
black --check src/ tests/
isort --check-only src/ tests/
# Fix formatting
format:
black src/ tests/
isort src/ tests/
# Pre-commit hooks
pre-commit: lint test
echo "All pre-commit checks passed!"
Monorepo Management¶
Multi-language Monorepo¶
# Install all dependencies
install:
@echo "Installing dependencies for all services..."
cd frontend && npm ci
cd backend && pip install -r requirements.txt
# Run all tests
*test:
@echo "Running tests for all services..."
cd frontend && npm test
cd backend && pytest
# Build all services
build:
@echo "Building all services..."
cd frontend && npm run build
cd backend && python -m build
# Deploy all services
deploy env:
@echo "Deploying all services to {{env}}..."
cd infrastructure && terraform apply -var="env={{env}}"
cd backend && runly deploy {{env}}
cd frontend && runly deploy {{env}}
# Lint all code
lint:
@echo "Linting all services..."
cd frontend && npm run lint
cd backend && flake8 src/
# Clean all build artifacts
clean:
@echo "Cleaning all services..."
cd frontend && rm -rf node_modules build
cd backend && rm -rf dist build *.egg-info