agentleFS
medy-gribkovmedy-gribkov/arcana/skills/env-config/SKILL.md

env-config

Skill1 starsChanged 9 months agoApache-2.0View on GitHub

Environment and configuration management covering .env patterns, runtime validation with zod and envalid, secret handling, 12-factor config principles, and Docker env injection.

  • Reads credentials
  • Installs packages

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

21 rules. About 0 are common, 14 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈14

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Use SCREAMING_SNAKE_CASE. No dots, no dashes.

    line 22
  2. Very specific:

    Use placeholder values that make the expected format obvious: MYAPP_API_KEY=sk_test_xxxxxxxxxxxx.

    line 29
  3. Distinctive:

    Call this at application startup, before any other initialization.

    line 48
  4. Very specific:

    Use z.coerce for numbers and booleans since env vars are always strings.

    line 51
  5. Distinctive:

    Never commit secrets to version control.

    line 75
  6. Distinctive:

    Use short-lived tokens over long-lived API keys.

    line 77
  7. Very specific:

    Local dev: Use .env.local (gitignored) or a secrets manager CLI.

    line 82
  8. Distinctive:

    CI/CD: Use the platform's built-in secrets (GitHub Actions secrets, GitLab CI variables).

    line 83
  9. Distinctive:

    Production: Use a dedicated secrets manager: HashiCorp Vault, AWS Secrets Manager, GCP Secret Manager, or Doppler.

    line 84
  10. Distinctive:

    Encryption at rest: Use SOPS or age to encrypt secrets files that must live in the repo.

    line 85
  11. Distinctive:

    Add a pre-commit hook with gitleaks or trufflehog to scan for secrets.

    line 89
  12. Distinctive:

    If a secret is committed accidentally, rotate it immediately.

    line 91
  13. Distinctive:

    Never group config into named environments inside the app ("the staging config object").

    line 99
  14. Distinctive:

    Default values should be safe for local development, never for production.

    line 104
  15. Very specific:

    Use env_file for bulk variables.

    line 128
  16. Very specific:

    Never put secrets in docker-compose.yml.

    line 129
  17. Very specific:

    Do not copy .env files into Docker images.

    line 133
  18. Distinctive:

    Use different values per environment (Production, Preview, Development).

    line 188
  19. Distinctive:

    Use environment-level secrets for deploy targets that need different credentials.

    line 195
  20. Distinctive:

    Use ConfigMaps for non-sensitive config, Secrets for sensitive data.

    line 199
  21. Distinctive:

    Use External Secrets Operator to sync from cloud secret managers.

    line 201

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Purpose

Prevent misconfigurations from reaching production. Validate environment variables at startup, manage secrets safely, and keep config portable across local dev, CI, and production.

.env File Patterns

File Hierarchy

  • .env holds shared defaults. Commit this to the repo with safe placeholder values.
  • .env.local holds developer-specific overrides. Add to .gitignore.
  • .env.production, .env.staging, .env.test hold environment-specific values.
  • Load order (most frameworks): .env < .env.local < .env.[environment] < .env.[environment].local.

Naming Conventions

  • Prefix variables with the app or service name: MYAPP_DATABASE_URL, not just DATABASE_URL.
  • Use SCREAMING_SNAKE_CASE. No dots, no dashes.
  • Boolean values: use true/false, not 1/0 or yes/no.
  • Group related variables with a common prefix: MYAPP_REDIS_HOST, MYAPP_REDIS_PORT.

Template Files

  • Maintain a .env.example with every variable, documented with comments.
  • Use placeholder values that make the expected format obvious: MYAPP_API_KEY=sk_test_xxxxxxxxxxxx.
  • Script a setup step that copies .env.example to .env if .env does not exist.

Validation with Zod

import { z } from 'zod';

const envSchema = z.object({
  NODE_ENV: z.enum(['development', 'staging', 'production']),
  PORT: z.coerce.number().int().min(1).max(65535).default(3000),
  DATABASE_URL: z.string().url(),
  API_KEY: z.string().min(10),
  ENABLE_CACHE: z.coerce.boolean().default(false),
});

export const env = envSchema.parse(process.env);
  • Call this at application startup, before any other initialization.
  • Fail fast with a clear error listing all missing or invalid variables.
  • Export the parsed result as a typed object. Never access process.env directly elsewhere.
  • Use z.coerce for numbers and booleans since env vars are always strings.

Validation with Envalid

import { cleanEnv, str, port, bool, url } from 'envalid';

export const env = cleanEnv(process.env, {
  NODE_ENV: str({ choices: ['development', 'staging', 'production'] }),
  PORT: port({ default: 3000 }),
  DATABASE_URL: url(),
  API_KEY: str(),
  ENABLE_CACHE: bool({ default: false }),
});
  • Envalid strips NODE_ENV awareness into the validator. Use env.isDev, env.isProd.
  • Built-in validators: str, bool, num, port, url, email, json, host.
  • Custom validators: pass a function to makeValidator.

Secret Management

Principles

  • Never commit secrets to version control. Not even in private repos.
  • Rotate secrets on a schedule. Automate rotation where possible.
  • Use short-lived tokens over long-lived API keys.
  • Audit secret access. Log who accessed what and when.

Tools

  • Local dev: Use .env.local (gitignored) or a secrets manager CLI.
  • CI/CD: Use the platform's built-in secrets (GitHub Actions secrets, GitLab CI variables).
  • Production: Use a dedicated secrets manager: HashiCorp Vault, AWS Secrets Manager, GCP Secret Manager, or Doppler.
  • Encryption at rest: Use SOPS or age to encrypt secrets files that must live in the repo.

Git Protection

  • Add a pre-commit hook with gitleaks or trufflehog to scan for secrets.
  • Configure .gitignore to exclude all .env* files except .env.example.
  • If a secret is committed accidentally, rotate it immediately. Removing it from history is not enough.

12-Factor Config

Core Principles

  • Store config in environment variables, not in code or config files baked into the image.
  • Config varies between deploys (staging, production). Code does not.
  • Never group config into named environments inside the app ("the staging config object"). Use individual env vars.

Implementation

  • One env var per config value. Compose connection strings from parts if needed.
  • Default values should be safe for local development, never for production.
  • Validate all config at startup. Log which config source was used (env var, default, file).

Docker Environment Injection

Build-time vs Runtime

  • ARG in Dockerfile: available only during build. Use for build tools, versions.
  • ENV in Dockerfile: baked into the image. Use for static defaults.
  • Runtime env vars (docker run -e): override ENV values. Use for secrets and deploy-specific config.

Compose

services:
  app:
    environment:
      - NODE_ENV=production
      - PORT=3000
    env_file:
      - .env.production
  • environment in compose takes precedence over env_file.
  • Use env_file for bulk variables. Use environment for overrides.
  • Never put secrets in docker-compose.yml. Use Docker secrets or an external env file.

Multi-stage Builds

  • Do not copy .env files into Docker images.
  • Pass build-time config via ARG and --build-arg.
  • Inject runtime config via environment variables at container start.

dotenv-vault

Encrypted .env files for teams. Alternative to secrets managers for small projects.

# Install
npm install dotenv-vault-core

# Setup
npx dotenv-vault new
npx dotenv-vault push production  # Upload .env to vault

# In production, use DOTENV_KEY instead of .env file
DOTENV_KEY="dotenv://vault-key-here" node server.js
// Load in app
require('dotenv-vault-core').config();
console.log(process.env.DATABASE_URL);  // Decrypted from vault

When to use: Small teams (< 10 people), need encryption at rest, want git-based workflow without committing secrets.

Cloud Provider Env Patterns

AWS Systems Manager (SSM) Parameter Store

// Fetch secrets at startup
import { SSMClient, GetParametersCommand } from "@aws-sdk/client-ssm";

const client = new SSMClient({ region: "us-east-1" });
const response = await client.send(new GetParametersCommand({
  Names: ["/myapp/database-url", "/myapp/api-key"],
  WithDecryption: true,
}));

const env = {};
for (const param of response.Parameters) {
  const key = param.Name.split('/').pop().toUpperCase().replace('-', '_');
  env[key] = param.Value;
}

// Now use env.DATABASE_URL, env.API_KEY

Vercel Environment Variables

  • Set env vars in the Vercel dashboard or via vercel env add.
  • Prefix client-exposed vars with NEXT_PUBLIC_ in Next.js.
  • Use different values per environment (Production, Preview, Development).
  • Pull env vars to local: vercel env pull .env.local.

GitHub Actions

  • Store secrets in Settings > Secrets and variables > Actions.
  • Access via ${{ secrets.MY_SECRET }} in workflow files.
  • Use environment-level secrets for deploy targets that need different credentials.

Kubernetes

  • Use ConfigMaps for non-sensitive config, Secrets for sensitive data.
  • Mount as environment variables or files depending on the consumer.
  • Use External Secrets Operator to sync from cloud secret managers.

Troubleshooting

  • Variable not loading: check file encoding (must be UTF-8, no BOM), line endings (LF not CRLF).
  • Variable undefined in browser: ensure the framework prefix is correct (NEXT_PUBLIC_, VITE_, REACT_APP_).
  • Docker env not applying: check that env_file path is relative to the compose file, not the build context.
  • Validation failing in CI: ensure CI secrets are set for the correct environment (not just production).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.