Skip to content

Contain local-dev env state inside .devcontainer/#1

Merged
justinmerrell merged 2 commits into
mainfrom
polish/env-template
May 11, 2026
Merged

Contain local-dev env state inside .devcontainer/#1
justinmerrell merged 2 commits into
mainfrom
polish/env-template

Conversation

@justinmerrell
Copy link
Copy Markdown
Contributor

Summary

  • Wire .devcontainer/.env into both Docker Compose (auto-discovery) and the dev container itself (runArgs --env-file), with a new host-side initializeCommand that creates the file from the template before docker run and strips CRLF for Windows/WSL safety.
  • Restructure .env.example with section banners and a three-state grammar (filled defaults / required-empty / optional override), and document the convention.
  • Add Taskfile.yml (env:check, env:required, env:diff, env:reset), an env-check.sh library, MOTD warnings for drift or unfilled required keys, and a lefthook.yml pre-commit guard against accidentally committing .devcontainer/.env.

Result: rm -rf .devcontainer/.env followed by a container rebuild fully resets local-dev env state with no other files touched.

Test plan

  • Rebuild container without cache; verify .devcontainer/.env is created on the host and echo $POSTGRES_USER inside the container returns postgres.
  • Delete .devcontainer/.env and rebuild; same outcome.
  • Add a FOO=bar line to .env.example only; reopen shell — MOTD shows yellow Environment block listing FOO; task env:check exits non-zero.
  • Run task env:reset and confirm yes; .env re-synced; MOTD warning clears.
  • On WSL: write .devcontainer/.env with CRLF endings; rebuild; container still starts cleanly.
  • Stage .devcontainer/.env and try to commit; lefthook rejects.
  • CI: Validate workflow (ShellCheck, Compose Config, Env Template Sync, Devcontainer Build) all green.

🤖 Generated with Claude Code

justinmerrell and others added 2 commits May 11, 2026 18:21
Wire `.devcontainer/.env` into both Compose (auto-discovery) and the
dev container itself (`runArgs --env-file`), with a host-side
`initializeCommand` that creates the file from the template before
`docker run` and strips CRLF for Windows/WSL.

Adds Taskfile env:* commands, an env-check library + MOTD warnings
for drift and unfilled required keys, and a lefthook pre-commit
guard against accidentally staging the gitignored .env.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Quiet ShellCheck SC2001 ("use parameter expansion instead of sed")
without changing behavior. The awk form is also slightly cleaner.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@justinmerrell justinmerrell merged commit 2770332 into main May 11, 2026
4 checks passed
@justinmerrell justinmerrell deleted the polish/env-template branch May 11, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant