Skip to content

Commit 2646018

Browse files
authored
chore: add docker:clean script and fix docker:start reliability (#16000)
`docker:start` fails with a container name conflict when orphan containers exist from a previous run or different compose, since `docker compose down` only removes containers it manages. This adds a `docker:clean` script that force-removes all named test containers first. It's a node script rather than inline shell because suppressing the exit code of `docker rm -f` on missing containers requires platform-specific syntax. Also removes `docker:stop` in favor of `docker:clean`.
1 parent a188556 commit 2646018

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Payload is a monorepo structured around Next.js, containing the core CMS platfor
8282
- Auto-login is enabled by default with credentials: `dev@payloadcms.com` / `test`
8383
- To disable: pass `--no-auto-login` flag or set `PAYLOAD_PUBLIC_DISABLE_AUTO_LOGIN=false`
8484
- Default database is MongoDB (in-memory). Switch to Postgres with `PAYLOAD_DATABASE=postgres`
85-
- Docker services: `pnpm docker:start` / `pnpm docker:stop` / `pnpm docker:test`
85+
- Docker services: `pnpm docker:start` / `pnpm docker:clean` / `pnpm docker:test`
8686

8787
### Playwright MCP
8888

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ Then use Docker to start your databases and storage emulators.
145145
On MacOS, the easiest way to install Docker is to use brew. Simply run `brew install --cask docker`, open the docker desktop app, apply the recommended settings and you're good to go.
146146

147147
```bash
148-
pnpm docker:start # Start all services (PostgreSQL, MongoDB, storage emulators) with fresh data
149-
pnpm docker:stop # Stop all services
148+
pnpm docker:start # Clean + start all services (PostgreSQL, MongoDB, storage emulators) with fresh data
149+
pnpm docker:clean # Stop and remove all services
150150
pnpm docker:test # Test database connections
151151
```
152152

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
"dev:prod": "cross-env NODE_OPTIONS=--no-deprecation tsx ./test/dev.ts --prod",
8383
"dev:vercel-postgres": "cross-env PAYLOAD_DATABASE=vercel-postgres pnpm runts ./test/dev.ts",
8484
"devsafe": "node ./scripts/delete-recursively.js '**/.next' && pnpm dev",
85-
"docker:start": "docker compose -f test/docker-compose.yml --profile all down -v --remove-orphans 2>/dev/null; docker compose -f test/docker-compose.yml --profile all up -d --wait",
86-
"docker:stop": "docker compose -f test/docker-compose.yml --profile all down --remove-orphans",
85+
"docker:clean": "node ./scripts/docker-clean.js",
86+
"docker:start": "pnpm docker:clean && docker compose -f test/docker-compose.yml --profile all up -d --wait",
8787
"docker:test": "pnpm runts test/__helpers/shared/db/mongodb/run-test-connection.ts && pnpm runts test/__helpers/shared/db/mongodb-atlas/run-test-connection.ts",
8888
"force:build": "pnpm run build:core:force",
8989
"lint": "turbo run lint --log-order=grouped --continue --filter \"!blank\" --filter \"!website\" --filter \"!ecommerce\"",

scripts/docker-clean.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { execSync } from 'child_process'
2+
3+
try {
4+
execSync(
5+
'docker rm -f postgres-payload-test mongodb-payload-test mongot-payload-test mongodb-atlas-payload-test localstack_demo',
6+
{ stdio: 'ignore' },
7+
)
8+
} catch {
9+
// Some or all containers don't exist
10+
}
11+
12+
try {
13+
execSync('docker compose -f test/docker-compose.yml --profile all down -v --remove-orphans', {
14+
stdio: 'inherit',
15+
})
16+
} catch {}

test/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: payload-monorepo
33
# Unified Docker Compose for all Payload test services
44
#
55
# Usage:
6-
# pnpm docker:start - Start ALL services with fresh data
7-
# pnpm docker:stop - Stop all services
6+
# pnpm docker:start - Clean + start ALL services with fresh data
7+
# pnpm docker:clean - Force-remove containers, volumes, and orphans
88
#
99
# Profiles (used by CI to start individual services):
1010
# --profile all - Everything

0 commit comments

Comments
 (0)