ln-733-env-configurator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ln-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

输入项

InputSourceDescription
Project NameDirectory nameUsed for database/service naming
Backend PortStack-dependent5000 (.NET), 8000 (Python)
Frontend PortDefault3000
Database PortDefault5432
Detected VarsCode analysisEnvironment variables found in code

输入项来源描述
项目名称目录名称用于数据库/服务命名
后端端口依赖技术栈5000(.NET)、8000(Python)
前端端口默认值3000
数据库端口默认值5432
探测到的变量代码分析在代码中发现的环境变量

Outputs

输出项

FilePurposeTemplate
.env.example
Documented templateenv_example.template
.env.development
Local development defaultsenv_development.template
.env.production
Production placeholdersenv_production.template
.gitignore
(append)
Secrets protectiongitignore_secrets.template

文件用途模板
.env.example
带文档的模板env_example.template
.env.development
本地开发默认配置env_development.template
.env.production
生产环境占位符env_production.template
.gitignore
(追加)
密钥保护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.environ
    ,
    Configuration[]
  • Identify which variables are secrets vs configuration
Output: List of required environment variables with types
扫描项目中已有的环境变量使用情况:
  • 检查是否存在现有.env文件
  • 在代码中搜索
    process.env
    os.environ
    Configuration[]
  • 区分哪些变量是密钥,哪些是配置项
输出: 带类型的必填环境变量列表

Phase 2: Variable Classification

阶段2:变量分类

Classify discovered variables:
CategoryExamplesTreatment
DatabaseDATABASE_URL, POSTGRES_*Auto-generate with project name
API ConfigAPI_PORT, LOG_LEVELUse detected or defaults
SecurityJWT_SECRET, API_KEYPlaceholder with warning
ExternalREDIS_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:
  1. Apply variable substitution
  2. Include all discovered variables
  3. Add comments for undocumented variables
基于模板生成环境文件:
  1. 替换变量值
  2. 包含所有探测到的变量
  3. 为未文档化的变量添加注释

Phase 4: Gitignore Update

阶段4:更新Gitignore

Append secrets protection to .gitignore:
  1. Read existing .gitignore (if exists)
  2. Check if secrets patterns already present
  3. Append missing patterns from template
  4. Preserve existing entries

向.gitignore中追加密钥保护规则:
  1. 读取现有的.gitignore(如果存在)
  2. 检查密钥相关规则是否已存在
  3. 从模板中追加缺失的规则
  4. 保留现有条目

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:
  • ${VARIABLE}
    syntax for deployment substitution
  • Comments indicating required secrets
  • Production-appropriate defaults (Warning log level)

生产环境占位符文件:
  • 使用
    ${VARIABLE}
    语法用于部署时替换
  • 注释标记必填密钥
  • 适合生产环境的默认值(警告级日志)

Security Best Practices

安全最佳实践

PracticeImplementation
No real secretsPlaceholder values only in templates
Gitignore protectionAll .env files except .env.example
Development warningsMark dev secrets as insecure
Production guidanceComments about secrets manager usage
Key rotation reminderNote about regular secret rotation

实践措施实现方式
不包含真实密钥模板中仅使用占位符值
Gitignore保护除.env.example外,所有.env文件均被忽略
开发环境警告标记开发环境密钥为不安全
生产环境指导添加关于使用密钥管理器的注释
密钥轮换提醒备注定期轮换密钥的注意事项

Security Notes

安全注意事项

Generated files include these security reminders:
  1. Never commit real secrets - .gitignore prevents accidental commits
  2. Use secrets manager - GitHub Secrets, AWS Secrets Manager for production
  3. Rotate secrets regularly - Especially JWT secrets
  4. Strong JWT secrets - Minimum 256 bits (32 bytes)
  5. Restrict CORS - Only allow necessary origins in production

生成的文件包含以下安全提醒:
  1. 绝不要提交真实密钥 - .gitignore可防止意外提交
  2. 使用密钥管理器 - 生产环境使用GitHub Secrets、AWS Secrets Manager等
  3. 定期轮换密钥 - 尤其是JWT密钥
  4. 强JWT密钥 - 至少256位(32字节)
  5. 限制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

重要注意事项

  1. Template-based: Use templates from references/. Do NOT hardcode file contents.
  2. Idempotent: Check file existence. Append to .gitignore, don't overwrite.
  3. No Real Secrets: Never generate files with actual passwords or API keys.
  4. Development Safety: Development defaults should work out-of-box with docker-compose.

  1. 基于模板: 使用references/目录下的模板。请勿硬编码文件内容。
  2. 幂等性: 检查文件是否存在。仅向.gitignore追加内容,不覆盖。
  3. 无真实密钥: 绝不生成包含实际密码或API密钥的文件。
  4. 开发环境易用性: 开发环境默认值应可直接与docker-compose配合使用。

Reference Files

参考文件

FilePurpose
env_example.templateDocumented .env template
env_development.templateDevelopment defaults
env_production.templateProduction 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