ln-733-env-configurator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseln-733-env-configurator
ln-733-env-configurator
Type: L3 Worker
Category: 7XX Project Bootstrap
Parent: ln-730-devops-setup
Configures environment variables for development and production environments.
类型: L3 Worker
分类: 7XX 项目初始化
父项: ln-730-devops-setup
为开发和生产环境配置环境变量。
Purpose & Scope
目的与范围
Creates environment configuration files:
- Does: Generate .env files, update .gitignore for secrets protection
- Does NOT: Store secrets, manage external secrets managers, configure CI/CD secrets
创建环境配置文件:
- 支持: 生成.env文件,更新.gitignore以保护密钥
- 不支持: 存储密钥、管理外部密钥管理器、配置CI/CD密钥
Inputs
输入项
| Input | Source | Description |
|---|---|---|
| Project Name | Directory name | Used for database/service naming |
| Backend Port | Stack-dependent | 5000 (.NET), 8000 (Python) |
| Frontend Port | Default | 3000 |
| Database Port | Default | 5432 |
| Detected Vars | Code analysis | Environment variables found in code |
| 输入项 | 来源 | 描述 |
|---|---|---|
| 项目名称 | 目录名称 | 用于数据库/服务命名 |
| 后端端口 | 依赖技术栈 | 5000(.NET)、8000(Python) |
| 前端端口 | 默认值 | 3000 |
| 数据库端口 | 默认值 | 5432 |
| 探测到的变量 | 代码分析 | 在代码中发现的环境变量 |
Outputs
输出项
| File | Purpose | Template |
|---|---|---|
| Documented template | env_example.template |
| Local development defaults | env_development.template |
| Production placeholders | env_production.template |
| Secrets protection | gitignore_secrets.template |
| 文件 | 用途 | 模板 |
|---|---|---|
| 带文档的模板 | env_example.template |
| 本地开发默认配置 | env_development.template |
| 生产环境占位符 | env_production.template |
| 密钥保护 | gitignore_secrets.template |
Workflow
工作流程
Phase 1: Environment Discovery
阶段1:环境探测
Scan project for existing environment usage:
- Check for existing .env files
- Search code for ,
process.env,os.environConfiguration[] - Identify which variables are secrets vs configuration
Output: List of required environment variables with types
扫描项目中已有的环境变量使用情况:
- 检查是否存在现有.env文件
- 在代码中搜索、
process.env、os.environConfiguration[] - 区分哪些变量是密钥,哪些是配置项
输出: 带类型的必填环境变量列表
Phase 2: Variable Classification
阶段2:变量分类
Classify discovered variables:
| Category | Examples | Treatment |
|---|---|---|
| Database | DATABASE_URL, POSTGRES_* | Auto-generate with project name |
| API Config | API_PORT, LOG_LEVEL | Use detected or defaults |
| Security | JWT_SECRET, API_KEY | Placeholder with warning |
| External | REDIS_URL, SMTP_* | Comment out as optional |
对探测到的变量进行分类:
| 分类 | 示例 | 处理方式 |
|---|---|---|
| 数据库 | DATABASE_URL、POSTGRES_* | 结合项目名称自动生成 |
| API配置 | API_PORT、LOG_LEVEL | 使用探测到的值或默认值 |
| 安全类 | JWT_SECRET、API_KEY | 生成占位符并添加警告 |
| 外部服务 | REDIS_URL、SMTP_* | 注释为可选变量 |
Phase 3: Template Generation
阶段3:模板生成
Generate environment files from templates:
- Apply variable substitution
- Include all discovered variables
- Add comments for undocumented variables
基于模板生成环境文件:
- 替换变量值
- 包含所有探测到的变量
- 为未文档化的变量添加注释
Phase 4: Gitignore Update
阶段4:更新Gitignore
Append secrets protection to .gitignore:
- Read existing .gitignore (if exists)
- Check if secrets patterns already present
- Append missing patterns from template
- Preserve existing entries
向.gitignore中追加密钥保护规则:
- 读取现有的.gitignore(如果存在)
- 检查密钥相关规则是否已存在
- 从模板中追加缺失的规则
- 保留现有条目
Generated File Structure
生成的文件结构
.env.example
.env.example
Documented template with all variables:
- Section headers (Database, Backend, Frontend, Security, External)
- Descriptive comments for each variable
- Safe placeholder values (never real secrets)
- Optional variables commented out
包含所有变量的带文档模板:
- 章节标题(数据库、后端、前端、安全、外部服务)
- 每个变量的描述性注释
- 安全的占位符值(绝不包含真实密钥)
- 可选变量已注释
.env.development
.env.development
Ready-to-use development configuration:
- Pre-filled values that work with docker-compose
- Development-only secrets (clearly marked)
- Debug-level logging enabled
可直接使用的开发环境配置:
- 预填充可与docker-compose配合使用的值
- 明确标记的开发专用密钥
- 启用调试级日志
.env.production
.env.production
Production placeholder file:
- syntax for deployment substitution
${VARIABLE} - Comments indicating required secrets
- Production-appropriate defaults (Warning log level)
生产环境占位符文件:
- 使用语法用于部署时替换
${VARIABLE} - 注释标记必填密钥
- 适合生产环境的默认值(警告级日志)
Security Best Practices
安全最佳实践
| Practice | Implementation |
|---|---|
| No real secrets | Placeholder values only in templates |
| Gitignore protection | All .env files except .env.example |
| Development warnings | Mark dev secrets as insecure |
| Production guidance | Comments about secrets manager usage |
| Key rotation reminder | Note about regular secret rotation |
| 实践措施 | 实现方式 |
|---|---|
| 不包含真实密钥 | 模板中仅使用占位符值 |
| Gitignore保护 | 除.env.example外,所有.env文件均被忽略 |
| 开发环境警告 | 标记开发环境密钥为不安全 |
| 生产环境指导 | 添加关于使用密钥管理器的注释 |
| 密钥轮换提醒 | 备注定期轮换密钥的注意事项 |
Security Notes
安全注意事项
Generated files include these security reminders:
- Never commit real secrets - .gitignore prevents accidental commits
- Use secrets manager - GitHub Secrets, AWS Secrets Manager for production
- Rotate secrets regularly - Especially JWT secrets
- Strong JWT secrets - Minimum 256 bits (32 bytes)
- Restrict CORS - Only allow necessary origins in production
生成的文件包含以下安全提醒:
- 绝不要提交真实密钥 - .gitignore可防止意外提交
- 使用密钥管理器 - 生产环境使用GitHub Secrets、AWS Secrets Manager等
- 定期轮换密钥 - 尤其是JWT密钥
- 强JWT密钥 - 至少256位(32字节)
- 限制CORS - 生产环境仅允许必要的来源
Quality Criteria
质量标准
Generated files must:
- .env.example contains all required variables
- No real secrets or passwords in any file
- .gitignore updated with secrets patterns
- .env.development works with docker-compose
- .env.production uses placeholder syntax
生成的文件必须满足:
- .env.example包含所有必填变量
- 所有文件中均不包含真实密钥或密码
- .gitignore已更新密钥保护规则
- .env.development可与docker-compose配合使用
- .env.production使用占位符语法
Critical Notes
重要注意事项
- Template-based: Use templates from references/. Do NOT hardcode file contents.
- Idempotent: Check file existence. Append to .gitignore, don't overwrite.
- No Real Secrets: Never generate files with actual passwords or API keys.
- Development Safety: Development defaults should work out-of-box with docker-compose.
- 基于模板: 使用references/目录下的模板。请勿硬编码文件内容。
- 幂等性: 检查文件是否存在。仅向.gitignore追加内容,不覆盖。
- 无真实密钥: 绝不生成包含实际密码或API密钥的文件。
- 开发环境易用性: 开发环境默认值应可直接与docker-compose配合使用。
Reference Files
参考文件
| File | Purpose |
|---|---|
| env_example.template | Documented .env template |
| env_development.template | Development defaults |
| env_production.template | Production placeholders |
| gitignore_secrets.template | .gitignore additions |
Version: 1.1.0
Last Updated: 2026-01-10
| 文件 | 用途 |
|---|---|
| env_example.template | 带文档的.env模板 |
| env_development.template | 开发环境默认配置模板 |
| env_production.template | 生产环境占位符模板 |
| gitignore_secrets.template | .gitignore追加规则模板 |
版本: 1.1.0
最后更新: 2026-01-10