Files
step-ca_postgres/Makefile

65 lines
2.3 KiB
Makefile

.PHONY: help configure clean
# Colors for output
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m # No Color
help: ## Show this help message
@echo "$(BLUE)Step-CA Docker Stack - Available commands:$(NC)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-15s$(NC) %s\n", $$1, $$2}'
configure: ## Create secret files from .env if they don't exist
@echo "$(BLUE)Configuring secrets...$(NC)"
@if [ ! -f .env ]; then \
echo "$(RED)Error: .env file not found. Please copy .env.example to .env and configure it.$(NC)"; \
exit 1; \
fi
@mkdir -p secrets
@if [ ! -f secrets/postgres_password.txt ]; then \
echo "$(YELLOW)Creating secrets/postgres_password.txt$(NC)"; \
grep '^POSTGRES_PASSWORD=' .env | cut -d '=' -f2- | tr -d '"' > secrets/postgres_password.txt; \
chmod 600 secrets/postgres_password.txt; \
echo "$(GREEN)✓ Created secrets/postgres_password.txt$(NC)"; \
else \
echo "$(GREEN)✓ secrets/postgres_password.txt already exists$(NC)"; \
fi
@if [ ! -f secrets/step_pwd.txt ]; then \
echo "$(YELLOW)Creating secrets/step_pwd.txt$(NC)"; \
if grep -q '^STEP_CA_PASSWORD=' .env; then \
grep '^STEP_CA_PASSWORD=' .env | cut -d '=' -f2- | tr -d '"' > secrets/step_pwd.txt; \
else \
openssl rand -base64 32 > secrets/step_pwd.txt; \
echo "$(YELLOW)No STEP_CA_PASSWORD in .env, generated random password$(NC)"; \
fi; \
chmod 600 secrets/step_pwd.txt; \
echo "$(GREEN)✓ Created secrets/step_pwd.txt$(NC)"; \
else \
echo "$(GREEN)✓ secrets/step_pwd.txt already exists$(NC)"; \
fi
@echo "$(GREEN)✓ Configuration complete$(NC)"
clean:
docker compose down
@echo "$(RED)WARNING: This will destroy all data (certificates, database)$(NC)"
@read -p "Are you sure? [y/N] " -n 1 -r; \
echo; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
echo "$(BLUE)Removing volumes...$(NC)"; \
docker compose down -v; \
echo "$(GREEN)✓ Volumes removed$(NC)"; \
else \
echo "$(YELLOW)Cancelled$(NC)"; \
fi
exec-ca: ## Execute ash in step-ca container
docker compose exec step-ca sh
exec-db: ## Execute psql in postgres container
docker compose exec postgres psql -U stepca -d stepca
fingerprint: ## Get CA root certificate fingerprint
@docker compose exec step-ca step certificate fingerprint /home/step/certs/root_ca.crt 2>/dev/null || echo "$(RED)CA not initialized yet$(NC)"