dist/codex/medusa-commerce/skills/medusa-deploy/SKILL.md
Deploy Medusa v2 to production — build process, server vs worker mode, environment variables, hosting options, Redis caching, database configuration, and production checklist. Use when deploying Medusa applications.
npx skillsauth add orcaqubits/agentic-commerce-claude-plugins medusa-deployInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Fetch live docs:
site:docs.medusajs.com deployment production for production deployment guidessite:docs.medusajs.com medusa build for build process detailshttps://docs.medusajs.com/learn/fundamentals/cli for CLI command referencesite:docs.medusajs.com environment variables configuration for env var referencesite:docs.medusajs.com redis cache events for Redis caching and event bus setup| Command | Purpose |
|---------|---------|
| npx medusa build | Compile server + admin dashboard for production |
| npx medusa db:migrate | Run pending database migrations |
| npx medusa start | Start the production server |
| npx medusa worker | Start the background worker process |
The build step compiles TypeScript, bundles admin extensions (Vite), and prepares the .medusa/ output directory.
.medusa/
├── server/ — Compiled server code
│ ├── src/ — Custom modules, routes, workflows
│ └── medusa-config.js
└── admin/ — Bundled admin dashboard (static)
Medusa v2 supports running the server and background workers as separate processes:
| Mode | Command | Handles |
|------|---------|---------|
| Server | npx medusa start | HTTP requests, API routes, admin dashboard |
| Worker | npx medusa worker | Workflows, scheduled jobs, event subscribers |
| Combined | Default start behavior | Both server and worker (single process) |
| Variable | Purpose | Example |
|----------|---------|---------|
| DATABASE_URL | PostgreSQL connection string | postgres://user:pass@host:5432/medusa |
| COOKIE_SECRET | Session cookie signing | Random 32+ character string |
| JWT_SECRET | JWT token signing | Random 32+ character string |
| NODE_ENV | Runtime environment | production |
| Variable | Purpose | Default |
|----------|---------|---------|
| REDIS_URL | Redis connection for cache/events/workers | None (in-memory) |
| STORE_CORS | Store API CORS origins | http://localhost:8000 |
| ADMIN_CORS | Admin API CORS origins | http://localhost:9000 |
| AUTH_CORS | Auth route CORS origins | Combination of store + admin |
| PORT | Server listen port | 9000 |
| MEDUSA_ADMIN_ONBOARDING_TYPE | Admin onboarding flow | default |
| MEDUSA_WORKER_MODE | server, worker, or shared | shared |
?sslmode=require to DATABASE_URL# Generate migration after DML model changes
npx medusa db:generate <module_name>
# Apply migrations
npx medusa db:migrate
Redis serves three roles in production Medusa:
| Role | Purpose | Required? | |------|---------|-----------| | Event Bus | Pub/sub for event-driven subscribers | Recommended | | Cache | Module data caching layer | Recommended | | Worker Queue | Job queue for background workflows | Required for worker mode |
Configure in medusa-config.ts by registering the Redis modules:
// Fetch live docs for Redis module registration
// in medusa-config.ts modules array
maxmemory and eviction policies for cache| Platform | Type | Notes | |----------|------|-------| | Railway | PaaS | One-click deploy, managed PostgreSQL and Redis | | DigitalOcean App Platform | PaaS | Managed infrastructure, auto-scaling | | AWS (EC2/ECS/Fargate) | IaaS/CaaS | Full control, use with RDS and ElastiCache | | Google Cloud Run | Serverless containers | Auto-scaling, pay-per-use | | Render | PaaS | Simple deploy, managed databases | | Self-hosted (Docker) | Container | Full control, use Docker Compose or Kubernetes | | Vercel | Serverless | Admin/storefront hosting only (not the Medusa server) |
# Fetch live docs for official Medusa Dockerfile
# and docker-compose.yml patterns
A typical Docker Compose setup includes three services: Medusa server, PostgreSQL, and Redis.
NODE_ENV=productionCOOKIE_SECRET and JWT_SECRETDATABASE_URL with SSL mode enabledREDIS_URL for events, cache, and worker queueSTORE_CORS, ADMIN_CORS, AUTH_CORS)npx medusa build successfullynpx medusa db:migrate against production database--max-old-space-size for Node.js memory limitsFetch the Medusa deployment documentation for exact build flags, Docker configuration, and platform-specific deployment guides before deploying.
development
Build with Spree's headless Next.js storefront — the official `spree/storefront` repo (Next.js 16 App Router with Server Actions and Turbopack, React 19 Server Components, Tailwind CSS 4, TypeScript 5, `@spree/sdk`, Sentry), server-only auth (httpOnly JWT cookies + publishable key), MeiliSearch faceted catalog, one-page checkout with Apple/Google Pay/Klarna/Affirm/SEPA, multi-region market routing, GA4 + JSON-LD SEO, and Vercel/Docker deployment. Use when forking or customizing the storefront, or evaluating headless adoption.
tools
Build Spree extensions as Rails engines — gem scaffolding, `bin/rails g spree:extension`, mounting routes/migrations/assets, the modern `prepend` decorator pattern (`*_decorator.rb` with `self.prepended(base)`), generators (`spree:model_decorator`, `spree:controller_decorator`), the four customization surfaces in preference order (Events > Webhooks > Dependencies > Decorators), Spree::Dependencies for swapping service objects, gem release/versioning, and the deprecated Deface engine. Use when building a reusable Spree extension or adding non-trivial customization to an app.
development
Build with Spree's event bus and Webhooks 2.0 — `Spree::Events` publication, `Spree::Subscriber` DSL with `subscribes_to` and `on`, wildcard matching, lifecycle events (`{model}.created/.updated/.deleted` via `publishes_lifecycle_events`), the canonical event catalog (order.*, payment.*, shipment.*, product.*), Webhooks 2.0 endpoints, HMAC-SHA256 signing (`X-Spree-Webhook-Signature`), exponential-backoff retries, and Sidekiq job orchestration. Use when wiring event-driven business logic, building webhook consumers, or replacing ActiveSupport callback chains.
tools
Cross-cutting Spree development patterns — the customization preference hierarchy (Events > Webhooks > Dependencies > Decorators), `Spree::Dependencies` service-object swapping, the `_decorator.rb` + `prepend` + `self.prepended` idiom, idempotent subscribers and webhook receivers, multi-store scoping discipline, prefixed IDs, calculator polymorphism (shipping/promotion/tax share the base), service-object composition with `dry-monads` or simple results, why to avoid `class_eval` reopening and Deface, and Spree-on-Rails idioms (Hotwire/Turbo Stimulus, ActiveStorage, Action Cable, Sidekiq). Use when designing the architecture of a Spree extension or solving cross-cutting concerns.