diff --git a/.github/scripts/medusa-config.js b/.github/scripts/medusa-config.js new file mode 100644 index 000000000..5a2c69042 --- /dev/null +++ b/.github/scripts/medusa-config.js @@ -0,0 +1,117 @@ +const dotenv = require("dotenv"); + +let ENV_FILE_NAME = ""; +switch (process.env.NODE_ENV) { + case "production": + ENV_FILE_NAME = ".env.production"; + break; + case "staging": + ENV_FILE_NAME = ".env.staging"; + break; + case "test": + ENV_FILE_NAME = ".env.test"; + break; + case "development": + default: + ENV_FILE_NAME = ".env"; + break; +} + +try { + dotenv.config({ path: process.cwd() + "/" + ENV_FILE_NAME }); +} catch (e) {} + +// CORS when consuming Medusa from admin +const ADMIN_CORS = + process.env.ADMIN_CORS || "http://localhost:7000,http://localhost:7001"; + +// CORS to avoid issues when consuming Medusa from a client +const STORE_CORS = process.env.STORE_CORS || "http://localhost:8000"; + +const DATABASE_URL = + process.env.DATABASE_URL || "postgres://medusa:password@localhost/medusa"; + +const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379"; + +const plugins = [ + `medusa-fulfillment-manual`, + `medusa-payment-manual`, + { + resolve: `@medusajs/file-local`, + options: { + upload_dir: "uploads", + }, + }, + { + resolve: "@medusajs/admin", + /** @type {import('@medusajs/admin').PluginOptions} */ + options: { + autoRebuild: true, + develop: { + open: process.env.OPEN_BROWSER !== "false", + }, + }, + }, + { + resolve: `medusa-plugin-meilisearch`, + options: { + config: { + host: process.env.MEILISEARCH_HOST, + apiKey: process.env.MEILISEARCH_API_KEY, + }, + settings: { + products: { + indexSettings: { + searchableAttributes: [ + "title", + "description", + "variant_sku", + ], + displayedAttributes: [ + "id", + "title", + "description", + "variant_sku", + "thumbnail", + "handle", + ], + }, + primaryKey: "id", + }, + }, + }, + }, +]; + +const modules = { + /*eventBus: { + resolve: "@medusajs/event-bus-redis", + options: { + redisUrl: REDIS_URL + } + }, + cacheService: { + resolve: "@medusajs/cache-redis", + options: { + redisUrl: REDIS_URL + } + },*/ +}; + +/** @type {import('@medusajs/medusa').ConfigModule["projectConfig"]} */ +const projectConfig = { + jwtSecret: process.env.JWT_SECRET, + cookieSecret: process.env.COOKIE_SECRET, + store_cors: STORE_CORS, + database_url: DATABASE_URL, + admin_cors: ADMIN_CORS, + // Uncomment the following lines to enable REDIS + redis_url: REDIS_URL +}; + +/** @type {import('@medusajs/medusa').ConfigModule} */ +module.exports = { + projectConfig, + plugins, + modules, +}; diff --git a/.github/workflows/test-e2e.yaml b/.github/workflows/test-e2e.yaml index 136a748cd..789445114 100644 --- a/.github/workflows/test-e2e.yaml +++ b/.github/workflows/test-e2e.yaml @@ -29,7 +29,16 @@ env: DATABASE_TYPE: "postgres" REDIS_URL: redis://localhost:6379 DATABASE_URL: postgres://test_medusa_user:password@localhost/test_medusa_db + MEILISEARCH_HOST: http://localhost:7700 + MEILISEARCH_API_KEY: meili_api_key + NEXT_PUBLIC_BASE_URL: http://localhost:8000 + NEXT_PUBLIC_DEFAULT_REGION: us + NEXT_PUBLIC_MEDUSA_BACKEND_URL: http://localhost:9000 + NEXT_PUBLIC_INDEX_NAME: products + NEXT_PUBLIC_SEARCH_ENDPOINT: http://127.0.0.1:7700 + NEXT_PUBLIC_SEARCH_API_KEY: meili_api_key + REVALIDATE_SECRET: supersecret jobs: e2e-test-runner: @@ -53,6 +62,9 @@ jobs: meilisearch: image: getmeili/meilisearch:v1.7 + env: + MEILI_MASTER_KEY: meili_api_key + MEILI_ENV: development ports: - 7700:7700 options: >- @@ -100,11 +112,18 @@ jobs: --db-database ${{ env.TEST_POSTGRES_DATABASE }} \ --db-host ${{ env.TEST_POSTGRES_HOST }} \ --db-port ${{ env.TEST_POSTGREST_PORT }} - + - name: Build the backend working-directory: ../backend run: yarn build:admin + - name: Setup search in the backend + working-directory: ../backend + run: yarn add medusa-plugin-meilisearch + + - name: Move custom medusa config to the backend + run: cp .github/scripts/medusa-config.js ../backend/medusa-config.js + - name: Seed data from default seed file working-directory: ../backend run: medusa seed --seed-file=data/seed.json @@ -119,9 +138,6 @@ jobs: - name: Install playwright run: yarn playwright install --with-deps - - name: Copy environment - run: cp .env.template .env - - name: Setup frontend run: yarn build