Skip to content

fix: pushkin-prep should gracefully handle containers already existing and non-Pushkin templates#372

Merged
cherriechang merged 4 commits intomainfrom
fix/prep-graceful-handle-container-exist
Mar 26, 2026
Merged

fix: pushkin-prep should gracefully handle containers already existing and non-Pushkin templates#372
cherriechang merged 4 commits intomainfrom
fix/prep-graceful-handle-container-exist

Conversation

@cherriechang
Copy link
Copy Markdown
Contributor

1) Failing for existing container
When running pushkin-dev prep with existing database containers from a previous run, the command would fail with a misleading "password authentication failed" error. This happened because the existing containers were using different credentials than the current pushkin.yaml config.

This commit implements Option 1 from the issue: automatic detection and cleanup of stale database containers.

Changes:

  • Added ensureCleanState() function that checks for existing database containers before setup
  • If containers exist, displays a warning and removes them cleanly
  • Uses docker ps -a to detect both running and stopped containers
  • Follows the same pattern as killLocal() using compose.stop() and compose.rm()
  • Includes proper error handling to avoid failing the entire setup

Benefits:

  • Makes prep command idempotent - safe to run multiple times
  • Eliminates confusing password authentication errors
  • Improves developer experience by avoiding manual cleanup steps
  • No waiting through 10 failed connection attempts (~2+ minutes)

Fixes pushkin-dev prep fails cryptically when database containers already exist

2) Failing for non-Pushkin site templates

When running `pushkin-dev prep` with existing database containers from a
previous run, the command would fail with a misleading "password
authentication failed" error. This happened because the existing containers
were using different credentials than the current pushkin.yaml config.

This commit implements Option 1 from the issue: automatic detection and
cleanup of stale database containers.

Changes:
- Added `ensureCleanState()` function that checks for existing database
  containers before setup
- If containers exist, displays a warning and removes them cleanly
- Uses `docker ps -a` to detect both running and stopped containers
- Follows the same pattern as `killLocal()` using compose.stop() and
  compose.rm()
- Includes proper error handling to avoid failing the entire setup

Benefits:
- Makes `prep` command idempotent - safe to run multiple times
- Eliminates confusing password authentication errors
- Improves developer experience by avoiding manual cleanup steps
- No waiting through 10 failed connection attempts (~2+ minutes)

Fixes pushkin-dev prep fails cryptically when database containers already exist
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Nov 24, 2025

⚠️ No Changeset found

Latest commit: 55c4cb3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cherriechang cherriechang self-assigned this Nov 24, 2025
@cherriechang cherriechang added the bug Something isn't working label Nov 24, 2025
@cherriechang cherriechang changed the title Fix: Auto-cleanup existing database containers before running prep Fix prep to gracefully handle containers already existing and non-Pushkin templates Nov 24, 2025
@cherriechang cherriechang added the pushkin-cli Relates to the CLI label Nov 24, 2025
@cherriechang cherriechang changed the title Fix prep to gracefully handle containers already existing and non-Pushkin templates fix: pushkin-prep should gracefully handle containers already existing and non-Pushkin templates Nov 24, 2025
@becky-gilbert
Copy link
Copy Markdown
Contributor

@cherriechang I've been hitting this issue while reviewing #373, so it would be nice to merge this ASAP! Is it ready for review?

@cherriechang
Copy link
Copy Markdown
Contributor Author

cherriechang commented Feb 6, 2026

@cherriechang I've been hitting this issue while reviewing #373, so it would be nice to merge this ASAP! Is it ready for review?

I think so!

@jkhartshorne
Copy link
Copy Markdown
Collaborator

@becky-gilbert -- what's the status on this?

@becky-gilbert
Copy link
Copy Markdown
Contributor

@jkhartshorne sorry, I've been focused on #383 and #376. This fix did work for me when I hit the issue but I'd like to take a closer look at the changes before approving. Will do ASAP!

Copy link
Copy Markdown
Contributor

@becky-gilbert becky-gilbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I happy this looks good and is working. @cherriechang do you want to test my changes before merging?

Comment on lines +363 to +366
await compose.down({
cwd: dockerPath,
config: dockerConfig,
commandOptions: ["--volumes"], // removes named volumes (e.g. test_transaction_db_volume)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -v flag on compose.rm only removes anonymous volumes, so I switched from compose.stop/compose.rm to compose.down in order to also remove named volumes: pushkin_test_db_volume, pushkin_test_transaction_db_volume. I ran into the same "password authentication failed" error with the original fix on this branch, which was because my test volumes survived the slate-cleaning process. The new container mounted the the old volume, which contained the PostgreSQL data directory with the old password.
The original fix did work for me before, but that was probably because either those named volumes hadn't been created yet or I'd cleared them.
Volume auth error before this change:
Image
After:
Image

config: "docker-compose.dev.yml",
});
} catch {
} catch (e) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug wasn't introduced here, just cleaning it up anyway!

@cherriechang cherriechang merged commit 7de7450 into main Mar 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working pushkin-cli Relates to the CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pushkin prep fails for non-Pushkin site templates pushkin prep hangs when docker containers are not built properly

4 participants