Files
opsx 0936234623
CI / Backend (go vet + test) (push) Canceled after 0s
CI / Frontend (lint + build + test) (push) Canceled after 0s
feat(install): 零输入一条命令部署 + 双架构发布包
- docker compose up -d 直接启动:entrypoint 在未显式提供密钥时自动生成随机
  JWT_SECRET/ENCRYPTION_KEY 并持久化到数据卷 .secrets.env(0600,重启不变),
  显式环境变量优先(单显式不被持久化文件覆盖,四场景实测);compose 去掉 :? 强制
- build.sh --dist / make dist:linux amd64 + arm64 两个 tar.gz(二进制+docs+homepage+README),
  实测 15M/13M;安装文档重写为三方式(kubernetes/install.sh 一键、compose 一条命令、release 包)
- README 快速开始同步
2026-10-29 15:50:50 +08:00

128 lines
4.3 KiB
Makefile

# ============================================================
# lokistack - Makefile
# Convenient shortcuts for common operations
# ============================================================
.PHONY: help build start stop status logs clean prod-setup secrets
# Default target
help:
@echo "lokistack - Available Commands:"
@echo ""
@echo " make build - Build Docker image"
@echo " make start - Start with docker-compose (dev)"
@echo " make stop - Stop all services"
@echo " make status - Show container status and health"
@echo " make logs - Follow container logs"
@echo " make prod - Start production deployment"
@echo " make prod-stop - Stop production deployment"
@echo " make secrets - Generate secret files"
@echo " make clean - Remove containers, volumes, and images"
@echo " make shell - Open shell in running container"
@echo " make lint - Validate Docker and Compose files"
@echo ""
# Build Docker image
build:
@echo "Building lokistack image..."
@docker compose build --no-cache
# Development
start:
@echo "Starting lokistack (dev mode)..."
@echo ""
@if [ -z "$${JWT_SECRET:-}" ]; then \
echo "WARNING: JWT_SECRET not set!"; \
echo "Run: export JWT_SECRET=\$$(openssl rand -hex 32)"; \
echo " export ENCRYPTION_KEY=\$$(openssl rand -hex 32)"; \
echo ""; \
read -p "Continue without secrets? (y/N) " ans; \
[ "$$ans" != "y" ] && [ "$$ans" != "Y" ] && exit 1; \
fi
@docker compose up -d
@echo ""
@echo "lokistack started!"
@echo " URL: http://localhost:$${SERVER_PORT:-8080}"
@echo " Check status: make status"
stop:
@echo "Stopping lokistack..."
@docker compose down --timeout 15
status:
@echo "=== Container Status ==="
@docker compose ps
@echo ""
@echo "=== Health Checks ==="
@docker inspect --format='{{.Name}}: {{.State.Health.Status}}' lokistack 2>/dev/null || echo "lokistack: container not found"
@echo ""
@echo "=== Resource Usage ==="
@docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}" lokistack 2>/dev/null || true
logs:
@docker compose logs -f --tail=50
# Production
prod-setup: secrets
@echo "Setting up production environment..."
@mkdir -p secrets
@echo "Production secrets created in ./secrets/"
prod:
@echo "Starting lokistack (production mode)..."
@if [ ! -f secrets/jwt_secret.txt ] || [ ! -f secrets/encryption_key.txt ]; then \
echo "ERROR: Secrets not found. Run 'make secrets' first."; \
exit 1; \
fi
@docker compose -f docker-compose.prod.yml up -d
@echo "Production deployment started!"
@echo " Load Balancer: http://localhost:$${SERVER_PORT:-8080}"
@echo " Check status: docker compose -f docker-compose.prod.yml ps"
prod-stop:
@echo "Stopping production deployment..."
@docker compose -f docker-compose.prod.yml down --timeout 30
# Secrets generation
secrets:
@echo "Generating secret files..."
@mkdir -p secrets
@chmod 700 secrets
@openssl rand -hex 32 > secrets/jwt_secret.txt
@openssl rand -hex 32 > secrets/encryption_key.txt
@chmod 600 secrets/*.txt
@echo "Secrets created:"
@echo " - secrets/jwt_secret.txt"
@echo " - secrets/encryption_key.txt"
@echo ""
@echo "IMPORTANT: Keep these files secure and never commit them!"
# Maintenance
shell:
@docker compose exec lokistack /bin/sh
clean:
@echo "Cleaning up..."
@docker compose down --volumes --rmi local --timeout 15 2>/dev/null || true
@docker compose -f docker-compose.prod.yml down --volumes --rmi local --timeout 30 2>/dev/null || true
@echo "Cleanup complete."
# Linting
dist:
APP_VERSION=$$(git describe --tags --abbrev=0 2>/dev/null || echo dev) bash build.sh --dist
lint:
@echo "Validating Dockerfile..."
@docker run --rm -i hadolint/hadolint < Dockerfile 2>/dev/null || echo "hadolint not available, install from: https://github.com/hadolint/hadolint"
@echo ""
@echo "Validating docker-compose.yml..."
@docker compose config > /dev/null && echo "docker-compose.yml: OK"
@echo ""
@echo "Validating docker-compose.prod.yml..."
@docker compose -f docker-compose.prod.yml config > /dev/null && echo "docker-compose.prod.yml: OK"
@echo ""
@echo "Checking shell scripts..."
@bash -n run.sh && echo "run.sh: syntax OK"
@bash -n build.sh && echo "build.sh: syntax OK"
@bash -n docker-entrypoint.sh && echo "docker-entrypoint.sh: syntax OK"