Skip to content

Commit 98b8ece

Browse files
committed
feat(workflow): add meilisearch config and initialization
1 parent 58f11f4 commit 98b8ece

File tree

2 files changed

+137
-4
lines changed

2 files changed

+137
-4
lines changed

.github/scripts/medusa-config.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
const dotenv = require("dotenv");
2+
3+
let ENV_FILE_NAME = "";
4+
switch (process.env.NODE_ENV) {
5+
case "production":
6+
ENV_FILE_NAME = ".env.production";
7+
break;
8+
case "staging":
9+
ENV_FILE_NAME = ".env.staging";
10+
break;
11+
case "test":
12+
ENV_FILE_NAME = ".env.test";
13+
break;
14+
case "development":
15+
default:
16+
ENV_FILE_NAME = ".env";
17+
break;
18+
}
19+
20+
try {
21+
dotenv.config({ path: process.cwd() + "/" + ENV_FILE_NAME });
22+
} catch (e) {}
23+
24+
// CORS when consuming Medusa from admin
25+
const ADMIN_CORS =
26+
process.env.ADMIN_CORS || "http://localhost:7000,http://localhost:7001";
27+
28+
// CORS to avoid issues when consuming Medusa from a client
29+
const STORE_CORS = process.env.STORE_CORS || "http://localhost:8000";
30+
31+
const DATABASE_URL =
32+
process.env.DATABASE_URL || "postgres://medusa:password@localhost/medusa";
33+
34+
const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379";
35+
36+
const plugins = [
37+
`medusa-fulfillment-manual`,
38+
`medusa-payment-manual`,
39+
{
40+
resolve: `@medusajs/file-local`,
41+
options: {
42+
upload_dir: "uploads",
43+
},
44+
},
45+
{
46+
resolve: "@medusajs/admin",
47+
/** @type {import('@medusajs/admin').PluginOptions} */
48+
options: {
49+
autoRebuild: true,
50+
develop: {
51+
open: process.env.OPEN_BROWSER !== "false",
52+
},
53+
},
54+
},
55+
{
56+
resolve: `medusa-plugin-meilisearch`,
57+
options: {
58+
config: {
59+
host: process.env.MEILISEARCH_HOST,
60+
apiKey: process.env.MEILISEARCH_API_KEY,
61+
},
62+
settings: {
63+
products: {
64+
indexSettings: {
65+
searchableAttributes: [
66+
"title",
67+
"description",
68+
"variant_sku",
69+
],
70+
displayedAttributes: [
71+
"id",
72+
"title",
73+
"description",
74+
"variant_sku",
75+
"thumbnail",
76+
"handle",
77+
],
78+
},
79+
primaryKey: "id",
80+
},
81+
},
82+
},
83+
},
84+
];
85+
86+
const modules = {
87+
/*eventBus: {
88+
resolve: "@medusajs/event-bus-redis",
89+
options: {
90+
redisUrl: REDIS_URL
91+
}
92+
},
93+
cacheService: {
94+
resolve: "@medusajs/cache-redis",
95+
options: {
96+
redisUrl: REDIS_URL
97+
}
98+
},*/
99+
};
100+
101+
/** @type {import('@medusajs/medusa').ConfigModule["projectConfig"]} */
102+
const projectConfig = {
103+
jwtSecret: process.env.JWT_SECRET,
104+
cookieSecret: process.env.COOKIE_SECRET,
105+
store_cors: STORE_CORS,
106+
database_url: DATABASE_URL,
107+
admin_cors: ADMIN_CORS,
108+
// Uncomment the following lines to enable REDIS
109+
redis_url: REDIS_URL
110+
};
111+
112+
/** @type {import('@medusajs/medusa').ConfigModule} */
113+
module.exports = {
114+
projectConfig,
115+
plugins,
116+
modules,
117+
};

.github/workflows/test-e2e.yaml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ env:
2929
DATABASE_TYPE: "postgres"
3030
REDIS_URL: redis://localhost:6379
3131
DATABASE_URL: postgres://test_medusa_user:password@localhost/test_medusa_db
32+
MEILISEARCH_HOST: http://localhost:7700
33+
MEILISEARCH_API_KEY: meili_api_key
34+
3235
NEXT_PUBLIC_BASE_URL: http://localhost:8000
36+
NEXT_PUBLIC_DEFAULT_REGION: us
37+
NEXT_PUBLIC_MEDUSA_BACKEND_URL: http://localhost:9000
38+
NEXT_PUBLIC_INDEX_NAME: products
39+
NEXT_PUBLIC_SEARCH_ENDPOINT: http://127.0.0.1:7700
40+
NEXT_PUBLIC_SEARCH_API_KEY: meili_api_key
41+
REVALIDATE_SECRET: supersecret
3342

3443
jobs:
3544
e2e-test-runner:
@@ -53,6 +62,9 @@ jobs:
5362
5463
meilisearch:
5564
image: getmeili/meilisearch:v1.7
65+
env:
66+
MEILI_MASTER_KEY: meili_api_key
67+
MEILI_ENV: development
5668
ports:
5769
- 7700:7700
5870
options: >-
@@ -100,11 +112,18 @@ jobs:
100112
--db-database ${{ env.TEST_POSTGRES_DATABASE }} \
101113
--db-host ${{ env.TEST_POSTGRES_HOST }} \
102114
--db-port ${{ env.TEST_POSTGREST_PORT }}
103-
115+
104116
- name: Build the backend
105117
working-directory: ../backend
106118
run: yarn build:admin
107119

120+
- name: Setup search in the backend
121+
working-directory: ../backend
122+
run: yarn add medusa-plugin-meilisearch
123+
124+
- name: Move custom medusa config to the backend
125+
run: cp .github/scripts/medusa-config.js ../backend/medusa-config.js
126+
108127
- name: Seed data from default seed file
109128
working-directory: ../backend
110129
run: medusa seed --seed-file=data/seed.json
@@ -119,9 +138,6 @@ jobs:
119138
- name: Install playwright
120139
run: yarn playwright install --with-deps
121140

122-
- name: Copy environment
123-
run: cp .env.template .env
124-
125141
- name: Setup frontend
126142
run: yarn build
127143

0 commit comments

Comments
 (0)