Skip to content

♻️ refactor(docker): read compose project name from .env, rename prod file#67

Merged
itisnotyourenv merged 6 commits intomainfrom
66-refactor-read-compose-project-name-from-env-instead-of-hardcoding-rename-prod-compose-file
Feb 22, 2026
Merged

♻️ refactor(docker): read compose project name from .env, rename prod file#67
itisnotyourenv merged 6 commits intomainfrom
66-refactor-read-compose-project-name-from-env-instead-of-hardcoding-rename-prod-compose-file

Conversation

@itisnotyourenv
Copy link
Copy Markdown
Owner

Summary

  • Renamed docker-compose.prod.ymldocker-compose-prod.yml for consistency with docker-compose-test.yml naming convention
  • Replaced hardcoded name: "production" with name: "${COMPOSE_PROJECT_NAME_PROD}" so the project name is read from .env
  • Added COMPOSE_PROJECT_NAME_PROD=production to .env.example
  • Removed hardcoded container_name: prod_postgres from the postgres service (lets Compose auto-generate it based on project name)
  • Updated all references in .github/README.md

Test plan

  • Verified no remaining references to old docker-compose.prod.yml filename
  • All 192 unit/integration tests pass (10 pre-existing integration DB errors unrelated to this change)
  • Ruff lint/format clean on changed files

Closes #66

🤖 Generated with Claude Code

…ml -> docker-compose-prod.yml & delete container_name from postgres service
@claude

This comment was marked as outdated.

@claude

This comment was marked as outdated.

@claude
Copy link
Copy Markdown

claude bot commented Feb 20, 2026

PR Review

Summary

The goals of this PR (consistent naming, env-driven project names) are sound. However there are two issues to address before merging.


Critical Issues

1. POSTGRES_PROD_PORT exposes the production database to the host

The original docker-compose.prod.yml deliberately had no ports mapping for the postgres service. In production, the database should only be reachable from within the Docker network. Adding a host port binding means that if the server firewall does not block 5432, the database is reachable from the internet. This is a security regression.

Fix: Remove the ports section from the postgres service in docker-compose-prod.yml and remove POSTGRES_PROD_PORT from .env.example. Alembic and app services connect via the Docker internal network and do not need the DB port exposed.

2. Re-adding the obsolete version: '3.8' field

The original prod file (without version) was already correct for Docker Compose v2+. The spec marks the top-level version field as obsolete — Compose v2 ignores it and emits a deprecation warning. Adding it back is a regression. Remove it from both docker-compose-prod.yml and docker-compose-test.yml.


Suggestions

3. Commit message quality

Two of four commits have non-descriptive messages: 'close minor requests from review' and 'resolve conflicts'. Consider squashing or rewriting to follow the project's conventional commit style.

4. Double blank line after name:

Both compose files have two blank lines between name and services. One is sufficient.


Positive Notes

  • Renaming docker-compose.prod.yml to docker-compose-prod.yml for consistency is correct.
  • Externalising COMPOSE_PROJECT_NAME_PROD/TEST into .env is good practice.
  • Removing hardcoded container_name: prod_postgres is cleaner.
  • README updates are accurate and complete.
  • Adding config-prod.yaml to .gitignore is a good catch.

Overall Assessment: Request Changes

The port exposure on the production postgres service is a security concern. Fix that and remove the obsolete version field, then this is good to merge.

…_NAME env var

- Replace COMPOSE_PROJECT_NAME_PROD, COMPOSE_PROJECT_NAME_TEST,
  and hardcoded "main" with ${APP_NAME}_prod, ${APP_NAME}_test,
  ${APP_NAME}_local respectively
- Standardize container_name to ${APP_NAME}_{env}_postgres across
  all compose files (add to prod & test, update in local)
- Remove deprecated `version: '3.8'` from prod and test compose files
- Remove exposed postgres port in prod compose (security hardening)

Refs: #66

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude bot commented Feb 22, 2026

Code Review — PR #67: refactor(docker): read compose project name from .env, rename prod file

The intent is good — standardising naming and making the project name configurable. However, there are several issues that need to be resolved before this can be merged.


🔴 Critical Issues

1. APP_NAME is used everywhere but never defined in .env.example

All three compose files now reference ${APP_NAME}:

# docker-compose.yml
name: ${APP_NAME}_local
container_name: ${APP_NAME}_local_postgres

# docker-compose-test.yml
name: ${APP_NAME}_test
container_name: ${APP_NAME}_test_postgres

# docker-compose-prod.yml
name: ${APP_NAME}_prod
container_name: ${APP_NAME}_prod_postgres

But APP_NAME does not appear in .env.example. Anyone cloning the repo and running docker compose up will get project/container names like _local, _local_postgres — effectively broken defaults. This must be added, e.g.:

APP_NAME=tma-template

2. COMPOSE_PROJECT_NAME_TEST and COMPOSE_PROJECT_NAME_PROD are defined but never consumed

.env.example adds:

COMPOSE_PROJECT_NAME_TEST=test
COMPOSE_PROJECT_NAME_PROD=production

But neither variable is referenced in any compose file. The PR description says the project name is read from these variables, but the actual implementation uses ${APP_NAME}_* instead. These are dead config values that will confuse developers. Either use them in the compose files or remove them.

3. PG_CONTAINER_NAME is still in .env.example but no longer used

docker-compose.yml previously used container_name: ${PG_CONTAINER_NAME}. That was replaced with ${APP_NAME}_local_postgres, but PG_CONTAINER_NAME=dev is still present in .env.example. It should be removed to avoid misleading anyone into thinking it still does something.


🟡 Suggestions

4. POSTGRES_PROD_PORT is declared but unused

.env.example adds POSTGRES_PROD_PORT=5432, but docker-compose-prod.yml doesn't expose any port (intentionally, for security). Either remove this variable or add a comment explaining it's there for reference and document where it would be wired in.

5. Justfile setup recipe references a stale connection string

@echo "Connection: postgresql://dev_user:dev_password@localhost:5432/ask_app"

The database name is now dev_db (changed in .env.example), not ask_app. This is a documentation inconsistency that will confuse first-time setup.

6. Justfile still uses old docker-compose binary name

Several recipes use docker-compose (v1 syntax) while the test and test-db-up recipes correctly use docker compose (v2 plugin syntax). This PR is a good opportunity to align them, though it's pre-existing rather than introduced here.


✅ What Looks Good

  • Renaming docker-compose.prod.ymldocker-compose-prod.yml is a clean consistency win matching the test file convention.
  • Adding config-prod.yaml to .gitignore prevents accidental credential commits.
  • README references are correctly updated.
  • PR description is clear and the test plan is documented.

Overall Assessment: Request Changes

The APP_NAME variable being missing from .env.example is a breaking issue for anyone following the setup docs. The variable/naming mismatch between .env.example and the compose files also needs to be resolved for clarity. Fix those three critical points and this is straightforward to approve.

- Replace PG_CONTAINER_NAME and dev_* credentials with APP_NAME=tma
  and tma_* naming in .env.example and config-example.yaml
- Remove stale COMPOSE_PROJECT_NAME_TEST, COMPOSE_PROJECT_NAME_PROD,
  and POSTGRES_PROD_PORT vars no longer referenced by compose files

Refs: #66

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude bot commented Feb 22, 2026

Code Review

Overall Assessment: Request Changes (minor)

The refactor achieves its goals cleanly — consistent naming, env-driven config, and a good security improvement. A few items need addressing before merge.


Critical Issues

1. PR description is stale and inaccurate

The summary says:

Added COMPOSE_PROJECT_NAME_PROD=production to .env.example

But the actual change adds APP_NAME=tma (not COMPOSE_PROJECT_NAME_PROD). The description appears to be from an earlier iteration. Please update it to reflect the final approach — reviewers and future maintainers rely on this.


Suggestions for Improvement

2. README does not mention APP_NAME as a deployment prerequisite

The README was updated to reflect the file rename, but the deployment setup section does not tell users to set APP_NAME in .env before running docker compose. All three compose files now fail silently (project and container names resolve to _prod, _local, _test) if .env is missing or APP_NAME is unset.

Suggest adding a step in the deployment section, e.g. a note that .env must be configured with APP_NAME before any compose command.

3. Commit history could be cleaner

The branch has 6 commits with some vague messages:

  • close minor requests from review — no context on what was changed
  • resolve conflicts — implementation details, not a meaningful change description
  • add config-prod.yaml to .gitignore — should have been part of the main commit

The last two commits (refactor(infra): and chore(infra):) follow the conventional commits convention properly. Squashing or rebasing the earlier commits would make the history easier to bisect.

4. Extra blank line in docker-compose-test.yml

After the name: field there are two blank lines instead of one. Cosmetic, but inconsistent with the other compose files.


What's Good

  • Security improvement: Removed exposed postgres port in the prod compose — postgres is no longer reachable from outside the Docker network. Not mentioned in the PR description but worth highlighting.
  • Naming consistency: All three environments (_local, _test, _prod) follow the same APP_NAME_{env} pattern for both project names and container names.
  • Removed deprecated version: '3.8' from prod and test compose files — correct, this field is obsolete in modern Compose.
  • config-prod.yaml added to .gitignore — important for keeping production secrets out of version control.
  • Example credentials renamed from ask_app/dev_user to tma/tma_user — consistent with the project name.

Breaking Change Note

Existing deployments must:

  1. Rename docker-compose.prod.yml to docker-compose-prod.yml
  2. Add APP_NAME=production (or preferred name) to their .env
  3. Remove PG_CONTAINER_NAME from .env (no longer used)

This is expected for a refactor, but worth mentioning explicitly in the PR description or a migration note.

@itisnotyourenv itisnotyourenv merged commit a030bc4 into main Feb 22, 2026
8 of 9 checks passed
@itisnotyourenv itisnotyourenv deleted the 66-refactor-read-compose-project-name-from-env-instead-of-hardcoding-rename-prod-compose-file branch February 22, 2026 21:28
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.

refactor: read compose project name from .env instead of hardcoding, rename prod compose file

1 participant