Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

create-spree-app: Add Meilisearch to docker-compose.yml for built-in … (#13798)

Damian Legawieccd85b6d4a4f6
diff --git a/docker-compose.yml b/docker-compose.yml
index 965e538053..9dcfa00b66 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -8,12 +8,15 @@ x-app: &app
condition: service_healthy
redis:
condition: service_healthy
+ meilisearch:
+ condition: service_healthy
environment: &app-env
DATABASE_URL: postgres://postgres@postgres:5432/spree_development
REDIS_URL: redis://redis:6379/0
SECRET_KEY_BASE: development_secret_key_base_not_for_production_use_only
RAILS_FORCE_SSL: "false"
RAILS_ASSUME_SSL: "false"
+ MEILISEARCH_URL: http://meilisearch:7700
SMTP_HOST: mailpit
SMTP_PORT: "1025"
@@ -44,6 +47,18 @@ services:
timeout: 5s
retries: 5
+ meilisearch:
+ image: getmeili/meilisearch:latest
+ volumes:
+ - meilisearch_data:/meili_data
+ ports:
+ - "7700:7700"
+ healthcheck:
+ test: curl -f http://localhost:7700/health || exit 1
+ interval: 5s
+ timeout: 5s
+ retries: 5
+
mailpit:
image: axllent/mailpit
ports:
@@ -68,3 +83,4 @@ services:
volumes:
postgres_data:
redis_data:
+ meilisearch_data:
diff --git a/packages/create-spree-app/CHANGELOG.md b/packages/create-spree-app/CHANGELOG.md
index 592000ec7f..c05662e9e7 100644
--- a/packages/create-spree-app/CHANGELOG.md
+++ b/packages/create-spree-app/CHANGELOG.md
@@ -1,5 +1,11 @@
# create-spree-app
+## 0.5.0
+
+### Minor Changes
+
+- Add Meilisearch to docker-compose.yml for built-in full-text search with typo tolerance, relevance ranking, and faceted filtering. Meilisearch runs automatically alongside PostgreSQL and Redis — no additional setup needed for development.
+
## 0.4.0
### Minor Changes
diff --git a/packages/create-spree-app/package.json b/packages/create-spree-app/package.json
index fe1658a529..1f8dc23842 100644
--- a/packages/create-spree-app/package.json
+++ b/packages/create-spree-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-spree-app",
- "version": "0.4.0",
+ "version": "0.5.0",
"description": "Create a new Spree Commerce project with a single command",
"type": "module",
"bin": "./dist/index.js",
diff --git a/packages/create-spree-app/src/constants.ts b/packages/create-spree-app/src/constants.ts
index a64f30dc06..348b657b20 100644
--- a/packages/create-spree-app/src/constants.ts
+++ b/packages/create-spree-app/src/constants.ts
@@ -1,5 +1,3 @@
-export const SPREE_IMAGE = 'ghcr.io/spree/spree'
-export const SPREE_VERSION_TAG = 'latest'
export const DEFAULT_SPREE_PORT = 3000
export const STOREFRONT_PORT = 3001
diff --git a/packages/create-spree-app/src/scaffold.ts b/packages/create-spree-app/src/scaffold.ts
index 71af7d6db2..310181ae9c 100644
--- a/packages/create-spree-app/src/scaffold.ts
+++ b/packages/create-spree-app/src/scaffold.ts
@@ -6,7 +6,6 @@ import { execa } from 'execa'
import type { ScaffoldOptions } from './types.js'
import { DEFAULT_ADMIN_EMAIL, DEFAULT_ADMIN_PASSWORD } from './constants.js'
import { generateSecretKeyBase, isDockerRunning } from './utils.js'
-import { dockerComposeContent, dockerComposeDevContent } from './templates/docker-compose.js'
import { envContent } from './templates/env.js'
import { rootPackageJsonContent } from './templates/package-json.js'
import { readmeContent } from './templates/readme.js'
@@ -36,14 +35,30 @@ export async function scaffold(options: ScaffoldOptions): Promise<void> {
}
}
- // Phase 1: Generate project files
const s = p.spinner()
+ fs.mkdirSync(projectDir, { recursive: true })
+
+ // Phase 1: Download backend (always included)
+ s.start('Downloading backend template...')
+ await downloadBackend(projectDir)
+ s.stop('Backend template downloaded.')
+
+ // Phase 2: Generate project files
s.start('Creating project structure...')
- fs.mkdirSync(projectDir, { recursive: true })
- fs.writeFileSync(path.join(projectDir, 'docker-compose.yml'), dockerComposeContent())
- fs.writeFileSync(path.join(projectDir, 'docker-compose.dev.yml'), dockerComposeDevContent())
+ // Copy compose files from backend template and adjust paths for project root
+ const backendDir = path.join(projectDir, 'backend')
+ const compose = fs.readFileSync(path.join(backendDir, 'docker-compose.yml'), 'utf-8')
+ const composeDev = fs.readFileSync(path.join(backendDir, 'docker-compose.dev.yml'), 'utf-8')
+
+ fs.writeFileSync(path.join(projectDir, 'docker-compose.yml'), compose)
+ // Adjust build context from current dir to ./backend for the wrapper project
+ fs.writeFileSync(
+ path.join(projectDir, 'docker-compose.dev.yml'),
+ composeDev.replace('context: .', 'context: ./backend'),
+ )
+
fs.writeFileSync(path.join(projectDir, '.env'), envContent(generateSecretKeyBase(), port))
fs.writeFileSync(path.join(projectDir, 'package.json'), rootPackageJsonContent(projectName))
fs.writeFileSync(path.join(projectDir, 'README.md'), readmeContent(projectName, storefront, port))
@@ -56,11 +71,6 @@ export async function scaffold(options: ScaffoldOptions): Promise<void> {
await installRootDeps(projectDir, options.packageManager)
s.stop('Dependencies installed.')
- // Phase 2: Backend (always included)
- s.start('Downloading backend template...')
- await downloadBackend(projectDir)
- s.stop('Backend template downloaded.')
-
// Phase 3: Storefront (optional)
if (storefront) {
s.start('Downloading storefront template...')
diff --git a/packages/create-spree-app/src/templates/docker-compose.ts b/packages/create-spree-app/src/templates/docker-compose.ts
deleted file mode 100644
index 48c111470f..0000000000
--- a/packages/create-spree-app/src/templates/docker-compose.ts
+++ /dev/null
@@ -1,86 +0,0 @@
-import { SPREE_IMAGE, SPREE_VERSION_TAG } from '../constants.js'
-
-function appAnchor(useImage: boolean): string {
- if (useImage) {
- return ` image: ${SPREE_IMAGE}:\${SPREE_VERSION_TAG:-${SPREE_VERSION_TAG}}`
- }
- return ` build:
- context: ./backend
- dockerfile: Dockerfile`
-}
-
-function composeBody(appSection: string): string {
- return `x-app: &app
-${appSection}
- depends_on:
- postgres:
- condition: service_healthy
- redis:
- condition: service_healthy
- env_file: .env
- environment: &app-env
- DATABASE_URL: postgres://postgres@postgres:5432/spree_production
- REDIS_URL: redis://redis:6379/0
- SECRET_KEY_BASE: \${SECRET_KEY_BASE}
- RAILS_FORCE_SSL: "false"
- RAILS_ASSUME_SSL: "false"
- SMTP_HOST: mailpit
- SMTP_PORT: "1025"
-
-services:
- postgres:
- image: postgres:18-alpine
- environment:
- POSTGRES_HOST_AUTH_METHOD: trust
- volumes:
- - postgres_data:/var/lib/postgresql/data
- healthcheck:
- test: pg_isready -U postgres
- interval: 5s
- timeout: 5s
- retries: 5
-
- redis:
- image: redis:7-alpine
- volumes:
- - redis_data:/data
- healthcheck:
- test: redis-cli ping
- interval: 5s
- timeout: 5s
- retries: 5
-
- mailpit:
- image: axllent/mailpit
- ports:
- - "8025:8025"
- - "1025:1025"
-
- web:
- <<: *app
- ports:
- - "\${SPREE_PORT:-3000}:3000"
- healthcheck:
- test: curl -f http://localhost:3000/up || exit 1
- interval: 10s
- timeout: 5s
- retries: 10
- start_period: 30s
-
- worker:
- <<: *app
- command: bundle exec sidekiq
-
-volumes:
- postgres_data:
- redis_data:
-`
-}
-
-export function dockerComposeContent(): string {
- return composeBody(appAnchor(true))
-}
-
-export function dockerComposeDevContent(): string {
- return composeBody(appAnchor(false))
-}
diff --git a/packages/create-spree-app/tests/scaffold.test.ts b/packages/create-spree-app/tests/scaffold.test.ts
index c4a2c0a4ca..9a4472d57e 100644
--- a/packages/create-spree-app/tests/scaffold.test.ts
+++ b/packages/create-spree-app/tests/scaffold.test.ts
@@ -4,6 +4,57 @@ import path from 'node:path'
import os from 'node:os'
import { scaffold } from '../src/scaffold'
+const FAKE_COMPOSE = `x-app: &app
+ image: ghcr.io/spree/spree:\${SPREE_VERSION_TAG:-latest}
+ depends_on:
+ postgres:
+ condition: service_healthy
+ env_file: .env
+ environment: &app-env
+ DATABASE_URL: postgres://postgres@postgres:5432/spree_production
+ REDIS_URL: redis://redis:6379/0
+ SECRET_KEY_BASE: \${SECRET_KEY_BASE}
+ MEILISEARCH_URL: http://meilisearch:7700
+
+services:
+ postgres:
+ image: postgres:18-alpine
+ web:
+ <<: *app
+ ports:
+ - "\${SPREE_PORT:-3000}:3000"
+ worker:
+ <<: *app
+ command: bundle exec sidekiq
+volumes:
+ postgres_data:
+`
+
+const FAKE_COMPOSE_DEV = `x-app: &app
+ build:
+ context: .
+ dockerfile: Dockerfile
+ depends_on:
+ postgres:
+ condition: service_healthy
+ env_file: .env
+ environment: &app-env
+ DATABASE_URL: postgres://postgres@postgres:5432/spree_production
+
+services:
+ postgres:
+ image: postgres:18-alpine
+ web:
+ <<: *app
+ ports:
+ - "\${SPREE_PORT:-3000}:3000"
+ worker:
+ <<: *app
+ command: bundle exec sidekiq
+volumes:
+ postgres_data:
+`
+
vi.mock('../src/storefront', async (importOriginal) => {
const mod = await importOriginal<typeof import('../src/storefront')>()
return {
@@ -16,7 +67,13 @@ vi.mock('../src/storefront', async (importOriginal) => {
})
vi.mock('../src/backend', () => ({
- downloadBackend: vi.fn(),
+ downloadBackend: vi.fn(async (projectDir: string) => {
+ // Simulate what downloadBackend does: create backend/ with compose files
+ const backendDir = path.join(projectDir, 'backend')
+ fs.mkdirSync(backendDir, { recursive: true })
+ fs.writeFileSync(path.join(backendDir, 'docker-compose.yml'), FAKE_COMPOSE)
+ fs.writeFileSync(path.join(backendDir, 'docker-compose.dev.yml'), FAKE_COMPOSE_DEV)
+ }),
}))
function createTempDir(): string {
@@ -60,7 +117,7 @@ describe('scaffold (no-start)', () => {
expect(fs.existsSync(path.join(projectDir, '.gitignore'))).toBe(true)
})
- it('generates docker-compose with Spree image', async () => {
+ it('copies docker-compose.yml from backend template', async () => {
const projectDir = getTempProjectDir()
await scaffold({
@@ -74,9 +131,10 @@ describe('scaffold (no-start)', () => {
const compose = fs.readFileSync(path.join(projectDir, 'docker-compose.yml'), 'utf-8')
expect(compose).toContain('ghcr.io/spree/spree')
+ expect(compose).toContain('MEILISEARCH_URL')
})
- it('generates docker-compose.dev.yml with build context', async () => {
+ it('adjusts docker-compose.dev.yml build context to ./backend', async () => {
const projectDir = getTempProjectDir()
await scaffold({
diff --git a/packages/create-spree-app/tests/templates.test.ts b/packages/create-spree-app/tests/templates.test.ts
index e5a9ac1c0e..79d8cfe0de 100644
--- a/packages/create-spree-app/tests/templates.test.ts
+++ b/packages/create-spree-app/tests/templates.test.ts
@@ -1,82 +1,9 @@
import { describe, it, expect } from 'vitest'
-import { dockerComposeContent, dockerComposeDevContent } from '../src/templates/docker-compose'
import { envContent, storefrontEnvContent } from '../src/templates/env'
import { rootPackageJsonContent } from '../src/templates/package-json'
import { readmeContent } from '../src/templates/readme'
import { gitignoreContent } from '../src/templates/gitignore'
-describe('dockerComposeContent', () => {
- const content = dockerComposeContent()
-
- it('includes the Spree image', () => {
- expect(content).toContain('ghcr.io/spree/spree')
- })
-
- it('includes postgres service', () => {
- expect(content).toContain('postgres:18-alpine')
- })
-
- it('includes healthcheck for web service', () => {
- expect(content).toContain('curl -f http://localhost:3000/up')
- })
-
- it('includes worker service with sidekiq command', () => {
- expect(content).toContain('command: bundle exec sidekiq')
- })
-
- it('includes volume definition', () => {
- expect(content).toContain('postgres_data:')
- })
-
- it('uses DATABASE_URL pointing to postgres service', () => {
- expect(content).toContain('DATABASE_URL: postgres://postgres@postgres:5432/spree_production')
- })
-
- it('includes redis service and REDIS_URL', () => {
- expect(content).toContain('redis:7-alpine')
- expect(content).toContain('REDIS_URL: redis://redis:6379/0')
- })
-
- it('includes mailpit service for local email', () => {
- expect(content).toContain('axllent/mailpit')
- expect(content).toContain('SMTP_HOST: mailpit')
- })
-
- it('disables SSL for local dev', () => {
- expect(content).toContain('RAILS_FORCE_SSL: "false"')
- expect(content).toContain('RAILS_ASSUME_SSL: "false"')
- })
-
- it('loads env_file', () => {
- expect(content).toContain('env_file: .env')
- })
-
- it('uses SPREE_PORT variable for port mapping', () => {
- expect(content).toContain('${SPREE_PORT:-3000}:3000')
- })
-
- it('includes SECRET_KEY_BASE from env', () => {
- expect(content).toContain('SECRET_KEY_BASE: ${SECRET_KEY_BASE}')
- })
-})
-
-describe('dockerComposeDevContent', () => {
- const content = dockerComposeDevContent()
-
- it('uses build context instead of image', () => {
- expect(content).toContain('context: ./backend')
- expect(content).toContain('dockerfile: Dockerfile')
- expect(content).not.toContain('ghcr.io/spree/spree')
- })
-
- it('has same services as production compose', () => {
- expect(content).toContain('postgres:18-alpine')
- expect(content).toContain('redis:7-alpine')
- expect(content).toContain('axllent/mailpit')
- expect(content).toContain('command: bundle exec sidekiq')
- })
-})
-
describe('envContent', () => {
it('includes the provided secret key', () => {
const content = envContent('my-secret-123', 3000)