GitLab Stack Config Generator by rknall/claude-skills
npx skills add https://github.com/rknall/claude-skills --skill 'GitLab Stack Config Generator'此技能为 GitLab 栈项目生成和管理特定服务的配置文件,确保配置遵循正确的模式,对所有变量使用 .env 文件,且绝不包含密钥。
当用户请求以下内容时激活此技能:
关键规则:
./config/service-name/ 目录步骤 1:确定生成内容
询问用户(或推断):
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
步骤 2:检查当前状态
步骤 1:创建 ./config 目录
mkdir -p ./config
chmod 755 ./config
步骤 2:创建服务目录
对于每个服务(例如 nginx、postgres、redis):
mkdir -p ./config/nginx
mkdir -p ./config/postgres
mkdir -p ./config/redis
chmod 755 ./config/*
目录结构:
./config/
├── nginx/
│ ├── nginx.conf
│ ├── ssl/
│ │ └── (SSL 配置,非证书)
│ └── conf.d/
│ └── default.conf
├── postgres/
│ ├── postgresql.conf
│ └── init.sql
├── redis/
│ └── redis.conf
└── app/
└── settings.yml
原则:
关键:始终确保这些文件存在
步骤 1:生成 CLAUDE.md
在项目根目录创建 CLAUDE.md:
# CLAUDE.md
此文件提供在此代码库中工作时的指导。
## 代码库目的
[栈项目的简要描述]
## 栈架构
这是一个遵循以下原则的 GitLab 栈项目:
- **配置**:所有变量在 .env 中,配置在 ./config 中
- **密钥**:所有密钥通过 Docker secrets 在 ./secrets 中管理
- **结构**:标准目录(./config、./secrets、./_temporary)
- **Docker**:现代 Docker Compose(无版本字段)
- **所有权**:无 root 拥有的文件
## 使用此栈
### 配置文件
所有服务配置都在 `./config/[service-name]/` 目录中。
配置值从 `.env` 文件加载。
### 环境变量
- `.env` 包含所有配置(非密钥)
- `.env.example` 必须与 `.env` 完全一致(关键要求)
- 添加新变量时更新两个文件
### 密钥管理
所有密钥都通过 Docker secrets 管理:
- 位置:`./secrets/` 目录
- 切勿放在 .env 或 docker-compose.yml 中
- 对密钥操作使用 secrets-manager 技能
### Docker 命令
```bash
# 启动栈
docker compose up -d
# 查看日志
docker compose logs -f
# 停止栈
docker compose down
关键:创建提交信息时,切勿在提交信息中提到 "Claude" 或 "Claude Code"。
良好的提交信息:
不良的提交信息:
所有文件必须由当前用户拥有(非 root):
# 检查所有权
find . -user root -type f
# 如果需要修复
sudo chown -R $(id -u):$(id -g) .
部署前,始终运行:
# 验证整个栈
[validation command]
# 检查密钥
[secrets validation command]
./
├── docker-compose.yml # 主 compose 文件(无版本字段)
├── .env # 配置变量
├── .env.example # 模板(必须与 .env 一致)
├── CLAUDE.md # 此文件
├── .gitignore # Git 排除项
├── .dockerignore # Docker 构建排除项
├── config/ # 服务配置
│ ├── nginx/
│ ├── postgres/
│ └── redis/
├── secrets/ # Docker secrets(不在 git 中)
│ └── .gitkeep
└── _temporary/ # 临时文件(不在 git 中)
最后更新:[日期]
**步骤 2:生成/更新 .gitignore**
```gitignore
# 密钥 - 切勿提交
/secrets/
/secrets/*
!secrets/.gitkeep
# 环境
.env
.env.local
.env.*.local
# 临时文件
/_temporary/
/_temporary/*
# Docker
.dockerignore
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# 操作系统
.DS_Store
Thumbs.db
# 日志
*.log
logs/
# 构建产物
dist/
build/
node_modules/
vendor/
# 备份文件
*.backup
*.old
*.bak
步骤 3:生成 .dockerignore
# Git
.git/
.gitignore
# 环境
.env
.env.*
# 密钥
secrets/
# 临时文件
_temporary/
# 文档
*.md
CLAUDE.md
# IDE
.vscode/
.idea/
# 操作系统
.DS_Store
Thumbs.db
# 依赖项(如果构建中不需要)
node_modules/
vendor/
# 日志
*.log
logs/
常见服务:nginx、PostgreSQL、Redis
对于每个服务,遵循此模式:
步骤 1:确定配置需求
询问用户:
步骤 2:识别所需的 .env 变量
对于每个服务,列出所有需要的 .env 变量:
nginx 示例:
步骤 3:生成配置文件
关键:使用环境变量占位符(${VAR_NAME})
nginx.conf 示例:
# Nginx 配置
# 从 .env 加载变量
upstream app {
server ${APP_HOST}:${APP_PORT};
}
server {
listen ${NGINX_PORT};
server_name ${NGINX_HOST};
# SSL 配置
# SSL 证书从 Docker secrets 加载
# ssl_certificate /run/secrets/ssl_cert;
# ssl_certificate_key /run/secrets/ssl_key;
location / {
proxy_pass http://app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
步骤 4:更新 .env
添加所有必需的变量:
# Nginx 配置
NGINX_PORT=80
NGINX_HOST=localhost
NGINX_SSL_ENABLED=false
APP_HOST=app
APP_PORT=8080
步骤 5:更新 .env.example
关键:必须与 .env 完全一致:
# Nginx 配置
NGINX_PORT=80
NGINX_HOST=localhost
NGINX_SSL_ENABLED=false
APP_HOST=app
APP_PORT=8080
步骤 6:更新 docker-compose.yml
为配置添加卷挂载:
services:
nginx:
image: nginx:alpine
ports:
- "${NGINX_PORT}:80"
volumes:
- ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
environment:
# 变量自动从 .env 加载
NGINX_HOST: ${NGINX_HOST}
APP_HOST: ${APP_HOST}
APP_PORT: ${APP_PORT}
步骤 1:语法验证
对于每种配置文件类型:
Nginx:
# 测试 nginx 配置
docker run --rm -v $(pwd)/config/nginx:/etc/nginx:ro nginx:alpine nginx -t
PostgreSQL:
# 检查 SQL 语法
# 解析 init.sql 中的语法错误
Redis:
# 测试 redis 配置
docker run --rm -v $(pwd)/config/redis:/usr/local/etc/redis:ro redis:alpine redis-server --test-memory 1024
步骤 2:密钥检测(关键)
扫描所有配置文件中的密钥:
# 检查常见的密钥模式
grep -r -iE "(password|secret|key|token|api_key)" ./config/
# 如果找到,这是关键安全问题
# 必须使用 secrets-manager 修复
步骤 3:路径验证
检查所有引用的路径是否存在:
步骤 4:.env 同步(关键)
# 从 .env 提取变量名
env_vars=$(grep -E "^[A-Z_]+" .env | cut -d'=' -f1 | sort)
# 从 .env.example 提取
example_vars=$(grep -E "^[A-Z_]+" .env.example | cut -d'=' -f1 | sort)
# 比较
diff <(echo "$env_vars") <(echo "$example_vars")
# 如果有任何差异,这是关键错误
步骤 5:Docker 验证
关键:使用 docker-validation 技能:
"使用 docker-validation 技能验证 docker-compose.yml"
在完成前解决所有发现的问题。
步骤 1:提供模板
对于 nginx、PostgreSQL、Redis,提供以下选项:
Nginx 模板:
简单反向代理(默认)
SSL 终止
静态文件 + 代理
自定义
PostgreSQL 模板:
基础(默认)
生产环境
带扩展
自定义
Redis 模板:
缓存(默认)
持久化
发布/订阅
自定义
步骤 2:从模板生成
根据用户选择,生成适当的配置,包含:
生成后,提供全面的报告:
📝 配置生成报告
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ 元文件
✅ CLAUDE.md 已创建
✅ .gitignore 已更新
✅ .dockerignore 已创建
✅ 目录结构
✅ ./config/nginx 已创建
✅ ./config/postgres 已创建
✅ ./config/redis 已创建
📄 生成的配置
Nginx(简单反向代理):
✅ ./config/nginx/nginx.conf
✅ 变量已添加到 .env(3 个)
✅ .env.example 已同步
✅ docker-compose.yml 已更新
✅ 语法验证:通过
PostgreSQL(基础):
✅ ./config/postgres/postgresql.conf
✅ ./config/postgres/init.sql
✅ 变量已添加到 .env(5 个)
✅ .env.example 已同步
✅ docker-compose.yml 已更新
Redis(缓存):
✅ ./config/redis/redis.conf
✅ 变量已添加到 .env(2 个)
✅ .env.example 已同步
✅ docker-compose.yml 已更新
🔐 安全验证
✅ 配置文件中无密钥
✅ 所有密钥在 ./secrets 中(通过 secrets-manager)
✅ 配置仅使用 .env 变量
✅ 路径验证
✅ 所有引用的路径存在
✅ 卷挂载有效
✅ .env 同步
✅ .env 和 .env.example 匹配(10 个变量)
🐳 Docker 验证
✅ docker-compose.yml 语法有效
✅ 所有卷挂载存在
✅ 无已弃用的语法
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ 配置生成完成!
后续步骤:
1. 查看生成的配置
2. 根据需要自定义
3. 运行:docker compose config(验证)
4. 运行:docker compose up -d
始终包含:
切勿包含:
示例变量:
NGINX_PORT=80
NGINX_HOST=localhost
NGINX_WORKER_PROCESSES=auto
NGINX_WORKER_CONNECTIONS=1024
APP_BACKEND_HOST=app
APP_BACKEND_PORT=8080
始终包含:
切勿包含:
示例变量:
POSTGRES_DB=myapp_db
POSTGRES_USER=myapp_user
# POSTGRES_PASSWORD 在 ./secrets/db_password 中
POSTGRES_MAX_CONNECTIONS=100
POSTGRES_SHARED_BUFFERS=256MB
始终包含:
切勿包含:
示例变量:
REDIS_PORT=6379
REDIS_MAXMEMORY=256mb
REDIS_MAXMEMORY_POLICY=allkeys-lru
REDIS_SAVE_ENABLED=false
何时调用:
何时调用:
何时调用:
用户:"生成 nginx 和 PostgreSQL 配置"
1. 检查当前状态
- ./config 缺失 → 创建它
- .env 存在
- .env.example 存在
- CLAUDE.md 缺失 → 创建它
2. 生成元文件
- 创建 CLAUDE.md
- 更新 .gitignore
- 创建 .dockerignore
3. 询问用户模板
"您想要哪些模板?
- Nginx:[简单反向代理]、SSL 终止、静态文件 + 代理、自定义
- PostgreSQL:[基础]、生产环境、带扩展、自定义"
4. 用户选择:简单反向代理、基础
5. 生成 nginx 配置
- 创建 ./config/nginx/nginx.conf
- 添加变量到 .env
- 同步 .env.example
- 更新 docker-compose.yml
- 验证语法
6. 生成 PostgreSQL 配置
- 创建 ./config/postgres/postgresql.conf
- 创建 ./config/postgres/init.sql
- 添加变量到 .env
- 同步 .env.example
- 更新 docker-compose.yml
7. 运行验证
- 密钥检测:通过
- 路径验证:通过
- .env 同步检查:通过
- Docker 验证(通过 docker-validation 技能):通过
8. 生成报告
- 显示所有创建的文件
- 列出添加的 .env 变量
- 确认验证通过
9. 后续步骤
- 建议测试:docker compose config
- 推荐:docker compose up -d
此技能生成遵循 GitLab 栈模式并经过严格验证的服务配置。
每周安装次数
–
代码库
GitHub 星标数
33
首次出现时间
–
安全审计
This skill generates and manages service-specific configuration files for GitLab stack projects, ensuring configurations follow proper patterns, use .env for all variables, and never contain secrets.
Activate this skill when the user requests:
CRITICAL RULES :
./config/service-name/ directoryStep 1: Determine What to Generate
Ask the user (or infer):
Step 2: Check Current State
Step 1: Create ./config Directory
mkdir -p ./config
chmod 755 ./config
Step 2: Create Service Directories
For each service (e.g., nginx, postgres, redis):
mkdir -p ./config/nginx
mkdir -p ./config/postgres
mkdir -p ./config/redis
chmod 755 ./config/*
Directory Structure :
./config/
├── nginx/
│ ├── nginx.conf
│ ├── ssl/
│ │ └── (SSL configs, not certificates)
│ └── conf.d/
│ └── default.conf
├── postgres/
│ ├── postgresql.conf
│ └── init.sql
├── redis/
│ └── redis.conf
└── app/
└── settings.yml
Principles :
CRITICAL : Always ensure these files exist
Step 1: Generate CLAUDE.md
Create CLAUDE.md in project root:
# CLAUDE.md
This file provides guidance when working with code in this repository.
## Repository Purpose
[Brief description of the stack project]
## Stack Architecture
This is a GitLab stack project following these principles:
- **Configuration**: All variables in .env, configs in ./config
- **Secrets**: All secrets in ./secrets via Docker secrets
- **Structure**: Standard directories (./config, ./secrets, ./_temporary)
- **Docker**: Modern Docker Compose (no version field)
- **Ownership**: No root-owned files
## Working with This Stack
### Configuration Files
All service configurations are in `./config/[service-name]/` directories.
Configuration values are loaded from `.env` file.
### Environment Variables
- `.env` contains all configuration (NOT secrets)
- `.env.example` must match `.env` exactly (critical requirement)
- Update both files when adding new variables
### Secrets Management
All secrets are managed via Docker secrets:
- Location: `./secrets/` directory
- Never in .env or docker-compose.yml
- Use secrets-manager skill for secret operations
### Docker Commands
```bash
# Start stack
docker compose up -d
# View logs
docker compose logs -f
# Stop stack
docker compose down
CRITICAL : When creating commit messages, NEVER mention "Claude" or "Claude Code" in the commit message.
Good commit messages:
Bad commit messages:
All files must be owned by the current user (not root):
# Check ownership
find . -user root -type f
# Fix if needed
sudo chown -R $(id -u):$(id -g) .
Before deployment, always run:
# Validate entire stack
[validation command]
# Check secrets
[secrets validation command]
./
├── docker-compose.yml # Main compose file (NO version field)
├── .env # Configuration variables
├── .env.example # Template (must match .env)
├── CLAUDE.md # This file
├── .gitignore # Git exclusions
├── .dockerignore # Docker build exclusions
├── config/ # Service configurations
│ ├── nginx/
│ ├── postgres/
│ └── redis/
├── secrets/ # Docker secrets (NOT in git)
│ └── .gitkeep
└── _temporary/ # Transient files (NOT in git)
Last updated: [date]
**Step 2: Generate/Update .gitignore**
```gitignore
# Secrets - NEVER commit
/secrets/
/secrets/*
!secrets/.gitkeep
# Environment
.env
.env.local
.env.*.local
# Temporary
/_temporary/
/_temporary/*
# Docker
.dockerignore
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# OS
.DS_Store
Thumbs.db
# Logs
*.log
logs/
# Build artifacts
dist/
build/
node_modules/
vendor/
# Backup files
*.backup
*.old
*.bak
Step 3: Generate .dockerignore
# Git
.git/
.gitignore
# Environment
.env
.env.*
# Secrets
secrets/
# Temporary
_temporary/
# Documentation
*.md
CLAUDE.md
# IDE
.vscode/
.idea/
# OS
.DS_Store
Thumbs.db
# Dependencies (if not needed in build)
node_modules/
vendor/
# Logs
*.log
logs/
Common Services : nginx, PostgreSQL, Redis
For each service, follow this pattern:
Step 1: Determine Configuration Needs
Ask user:
Step 2: Identify Required .env Variables
For each service, list all .env variables needed:
Example for nginx:
Step 3: Generate Configuration File
CRITICAL : Use environment variable placeholders (${VAR_NAME})
Example nginx.conf:
# Nginx Configuration
# Loads variables from .env
upstream app {
server ${APP_HOST}:${APP_PORT};
}
server {
listen ${NGINX_PORT};
server_name ${NGINX_HOST};
# SSL configuration
# SSL certificates loaded from Docker secrets
# ssl_certificate /run/secrets/ssl_cert;
# ssl_certificate_key /run/secrets/ssl_key;
location / {
proxy_pass http://app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Step 4: Update .env
Add all required variables:
# Nginx Configuration
NGINX_PORT=80
NGINX_HOST=localhost
NGINX_SSL_ENABLED=false
APP_HOST=app
APP_PORT=8080
Step 5: Update .env.example
CRITICAL : Must match .env exactly:
# Nginx Configuration
NGINX_PORT=80
NGINX_HOST=localhost
NGINX_SSL_ENABLED=false
APP_HOST=app
APP_PORT=8080
Step 6: Update docker-compose.yml
Add volume mount for config:
services:
nginx:
image: nginx:alpine
ports:
- "${NGINX_PORT}:80"
volumes:
- ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
environment:
# Variables loaded from .env automatically
NGINX_HOST: ${NGINX_HOST}
APP_HOST: ${APP_HOST}
APP_PORT: ${APP_PORT}
Step 1: Syntax Validation
For each config file type:
Nginx :
# Test nginx config
docker run --rm -v $(pwd)/config/nginx:/etc/nginx:ro nginx:alpine nginx -t
PostgreSQL :
# Check SQL syntax
# Parse init.sql for syntax errors
Redis :
# Test redis config
docker run --rm -v $(pwd)/config/redis:/usr/local/etc/redis:ro redis:alpine redis-server --test-memory 1024
Step 2: Secret Detection (CRITICAL)
Scan all config files for secrets:
# Check for common secret patterns
grep -r -iE "(password|secret|key|token|api_key)" ./config/
# If found, this is CRITICAL SECURITY ISSUE
# Must use secrets-manager to fix
Step 3: Path Validation
Check that all referenced paths exist:
Step 4: .env Synchronization (CRITICAL)
# Extract variable names from .env
env_vars=$(grep -E "^[A-Z_]+" .env | cut -d'=' -f1 | sort)
# Extract from .env.example
example_vars=$(grep -E "^[A-Z_]+" .env.example | cut -d'=' -f1 | sort)
# Compare
diff <(echo "$env_vars") <(echo "$example_vars")
# If any difference, this is CRITICAL ERROR
Step 5: Docker Validation
CRITICAL : Use docker-validation skill:
"Validate docker-compose.yml using docker-validation skill"
Address all findings before completing.
Step 1: Offer Templates
For nginx, PostgreSQL, Redis, offer these options:
Nginx Templates :
Simple Reverse Proxy (default)
SSL Termination
Static + Proxy
Custom
PostgreSQL Templates :
Basic (default)
Production
With Extensions
Custom
Redis Templates :
Cache (default)
Persistent
Pub/Sub
Custom
Step 2: Generate from Template
Based on user selection, generate appropriate config with:
After generation, provide comprehensive report:
📝 Configuration Generation Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Meta Files
✅ CLAUDE.md created
✅ .gitignore updated
✅ .dockerignore created
✅ Directory Structure
✅ ./config/nginx created
✅ ./config/postgres created
✅ ./config/redis created
📄 Generated Configurations
Nginx (Simple Reverse Proxy):
✅ ./config/nginx/nginx.conf
✅ Variables added to .env (3)
✅ .env.example synced
✅ docker-compose.yml updated
✅ Syntax validation: PASS
PostgreSQL (Basic):
✅ ./config/postgres/postgresql.conf
✅ ./config/postgres/init.sql
✅ Variables added to .env (5)
✅ .env.example synced
✅ docker-compose.yml updated
Redis (Cache):
✅ ./config/redis/redis.conf
✅ Variables added to .env (2)
✅ .env.example synced
✅ docker-compose.yml updated
🔐 Security Validation
✅ No secrets in config files
✅ All secrets in ./secrets (via secrets-manager)
✅ Configs use .env variables only
✅ Path Validation
✅ All referenced paths exist
✅ Volume mounts valid
✅ .env Synchronization
✅ .env and .env.example match (10 variables)
🐳 Docker Validation
✅ docker-compose.yml syntax valid
✅ All volume mounts exist
✅ No deprecated syntax
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Configuration generation complete!
Next Steps:
1. Review generated configurations
2. Customize as needed
3. Run: docker compose config (validate)
4. Run: docker compose up -d
Always include :
Never include :
Example variables :
NGINX_PORT=80
NGINX_HOST=localhost
NGINX_WORKER_PROCESSES=auto
NGINX_WORKER_CONNECTIONS=1024
APP_BACKEND_HOST=app
APP_BACKEND_PORT=8080
Always include :
Never include :
Example variables :
POSTGRES_DB=myapp_db
POSTGRES_USER=myapp_user
# POSTGRES_PASSWORD in ./secrets/db_password
POSTGRES_MAX_CONNECTIONS=100
POSTGRES_SHARED_BUFFERS=256MB
Always include :
Never include :
Example variables :
REDIS_PORT=6379
REDIS_MAXMEMORY=256mb
REDIS_MAXMEMORY_POLICY=allkeys-lru
REDIS_SAVE_ENABLED=false
When to call :
When to call :
When to call :
User: "Generate nginx and PostgreSQL configs"
1. Check current state
- ./config missing → create it
- .env exists
- .env.example exists
- CLAUDE.md missing → create it
2. Generate meta files
- Create CLAUDE.md
- Update .gitignore
- Create .dockerignore
3. Ask user for templates
"Which templates would you like?
- Nginx: [Simple Reverse Proxy], SSL Termination, Static + Proxy, Custom
- PostgreSQL: [Basic], Production, With Extensions, Custom"
4. User selects: Simple Reverse Proxy, Basic
5. Generate nginx config
- Create ./config/nginx/nginx.conf
- Add variables to .env
- Sync .env.example
- Update docker-compose.yml
- Validate syntax
6. Generate PostgreSQL config
- Create ./config/postgres/postgresql.conf
- Create ./config/postgres/init.sql
- Add variables to .env
- Sync .env.example
- Update docker-compose.yml
7. Run validations
- Secret detection: PASS
- Path validation: PASS
- .env sync check: PASS
- Docker validation (via docker-validation skill): PASS
8. Generate report
- Show all created files
- List .env variables added
- Confirmation that validations passed
9. Next steps
- Suggest testing: docker compose config
- Recommend: docker compose up -d
This skill generates service configurations following GitLab stack patterns with strict validation.
Weekly Installs
–
Repository
GitHub Stars
33
First Seen
–
Security Audits
Azure Data Explorer (Kusto) 查询技能:KQL数据分析、日志遥测与时间序列处理
114,200 周安装