Balis 情報マガジン

envdev

📅 October 29, 2026📖 Verified Publication

EnvDev: The Complete Developer’s Guide to Environment Management

Key Takeaways

  • EnvDev is the practice of managing application configurations across multiple environments (Dev, Staging, Prod) to ensure consistency and reduce deployment failures.
  • Use environment-specific files (e.g., .env.development, .env.production) to isolate secrets and configurations, never committing production keys to version control.
  • Implement fail-fast validation to check for missing variables at startup, preventing runtime crashes due to misconfiguration.
  • Adopt 12-Factor App principles: separate config from code, and manage credentials via secure secret managers (e.g., Vault, AWS Secrets Manager) for production.
  • Use IDE integration and Docker to replicate the local development environment accurately, minimizing "works on my machine" issues.

What is EnvDev?

EnvDev (Environment Development/Management) refers to the set of tools, patterns, and workflows used to handle application configuration across different runtime environments. It solves the classic problem where an application behaves differently in development versus production due to variable discrepancies.

Effective EnvDev focuses on three core pillars:

  1. Isolation: Keeping secrets and sensitive data out of source code.
  2. Consistency: Ensuring the same variable names and structures exist across all environments.
  3. Automation: Automating the injection of correct variables during CI/CD pipelines.

Core Principles of EnvDev

1. The 12-Factor Standard

EnvDev is built on the 12-Factor App methodology. Specifically, Factor II (Config) states: "Store config in the environment." This means your code should not contain environment-specific values like database URLs or API keys. Instead, these values are injected at runtime.

2. Secrets vs. Configuration

  • Configuration: Non-sensitive settings like log levels, feature flags, or cache sizes. These can often live in version-controlled .env files for non-prod environments.
  • Secrets: API keys, database passwords, and TLS certificates. These must be managed via a dedicated secret manager and never committed to Git.

3. Fail-Fast Validation

Applications should validate required environment variables at startup. If a critical variable is missing, the application should crash immediately with a clear error message, rather than failing unexpectedly during runtime.

Practical Playbook: Implementing EnvDev

Follow this checklist to establish a robust EnvDev workflow for your project.

Step 1: Structure Your Environment Files

  • Create a .env.example file that lists all required variables with placeholder values. This serves as documentation for new developers.
  • Create specific files for different contexts:
    • .env.development (local dev defaults)
    • .env.staging (pre-prod testing)
    • .env.production (never commit this; manage via secrets manager)
  • Add .env, .env.local, and .env.production to your .gitignore.

Step 2: Standardize Variable Naming

  • Use uppercase snake_case for variable names (e.g., DATABASE_HOST, API_KEY).
  • Prefix variables with the project name to avoid collisions in monorepos (e.g., MYAPP_DB_USER).
  • Document each variable in .env.example with a comment explaining its purpose and valid values.

Step 3: Implement Startup Validation

Write a small bootstrap script that runs before your main application logic. It should check for required variables and exit with an error if any are missing or empty.

  • Check for presence of critical variables (e.g., DATABASE_URL).
  • Validate data types where appropriate (e.g., port numbers should be integers).
  • Log a helpful message indicating which variable is missing.

Step 4: Integrate with CI/CD and Docker

  • Store secrets in your CI/CD provider’s secret store (e.g., GitHub Secrets, GitLab CI Variables).
  • For Docker, use docker-compose to inject environment variables into containers, or use --env-file for local development.
  • Ensure your deployment scripts do not rely on hardcoded paths or variables.

Comparison: Tools for EnvDev

Choosing the right tool depends on your team size and infrastructure complexity. Here is a comparison of common approaches:

Approach Best For Pros Cons
Plain .env Files Small teams, simple apps Easy to set up, no external dependencies, widely supported Security risk if mismanaged, no rotation, limited access control
Docker Secrets Containerized microservices Isolated per container, encrypted at rest in some setups Complexity in orchestration (Swarm/K8s), not suitable for non-Docker apps
Secret Managers (Vault, AWS Secrets Manager) Enterprise, multi-environment, dynamic secrets Centralized access, audit logs, automatic rotation, dynamic credentials Higher operational complexity, cost, requires client integration

Frequently Asked Questions

Q1: Should I commit my .env file to Git?

No. Never commit .env files that contain real secrets or production data. Instead, commit a .env.example file that lists required variables with placeholder values. This keeps your repository safe and provides clear documentation for new team members.

Q2: How do I handle different configurations for frontend and backend?

Frontend applications (like React or Vue) often cannot read system environment variables directly in the browser. Instead, use build-time injection (e.g., process.env in Create React App or import.meta.env in Vite). Backend applications can read system environment variables at runtime. Ensure both share the same variable naming convention where possible to reduce confusion.

Q3: What is the difference between configuration and secrets?

Configuration refers to non-sensitive settings that change between environments, such as log levels, feature flags, or service URLs. Secrets are sensitive data that grant access to resources, such as API keys, database passwords, and TLS certificates. Secrets require stricter access controls, auditing, and rotation policies, and should be stored in dedicated secret managers rather than plain text files.