|
1 | | -# Storedog Backend |
| 1 | +# Storedog |
| 2 | + |
| 3 | +This a dockerized [Spree Commerce](https://spreecommerce.org) application consumed by a NextJS frontend. |
2 | 4 |
|
3 | | -This a dockerized [Spree Commerce](https://spreecommerce.org) application consumed by [Storedog - Frontend](https://github.com/DataDog/storedog-frontend). |
4 | 5 | ## Local development |
5 | 6 |
|
6 | | -**1.** Before starting the containers, you will need to define the required env vars. Run the following command to copy the env var template to the `.env` file: |
| 7 | +**1.** Before starting the containers, you will need to define the required env vars. Run the following command to copy the env var template: |
| 8 | + |
| 9 | +`cp .env.template .env && cp .env.template ./deploy/docker-compose/.env && cp .env.template ./services/frontend/site/.env.local` |
| 10 | + |
| 11 | +**2.** |
| 12 | +Open the `.env` file under the project root and enter the values for the variables. The default values should all work except for the empty `DD_API_KEY`, which is required to run the DD agent. |
7 | 13 |
|
8 | | -`cp .env.template .env && cp .env.template ./deploy/docker-compose/.env` |
| 14 | +**3.** |
| 15 | +Open the `./services/frontend/site/.env.local` file and enter the values for the variables. The default values should all work except for the empty `NEXT_PUBLIC_DD_APPLICATION_KEY` and `NEXT_PUBLIC_CLIENT_TOKEN`, which are required to enable RUM. |
9 | 16 |
|
10 | | -Then, open the `.env` file and enter the values for the variables. The default values should all work except for the empty `DD_API_KEY`, which is required to run the DD agent. |
| 17 | +**4.** Start the app: `docker-compose up` |
11 | 18 |
|
12 | | -**2a.** To start the backend containers using the local build context, run: |
13 | | -`docker-compose up` |
| 19 | +## Image publication |
| 20 | +Images are stored in our public ECR repo `public.ecr.aws/x2b9z2t7`. On PR merges, only the affected services will be pushed to the ECR repo, using the `latest` tag. For example, if you only made changes to the `backend` service, then only the `backend` Github workflow will trigger and publish `public.ecr.aws/x2b9z2t7/storedog/backend:latest`. |
14 | 21 |
|
15 | | -**2b.** To start the backend containers using the published images in ECR, run: |
16 | | -`docker-compose -f ./deploy/docker-compose/docker-compose.yml -p storedog-backend up` |
| 22 | +Separately, we tag and publish *all* images when a new release is created with the corresponding release tag e.g. `public.ecr.aws/x2b9z2t7/storedog/backend:1.0.1`. New releases are made on an ad-hoc basis, depending on the recent features that are added. |
17 | 23 |
|
18 | | -To build the frontend, please see the README in the [Storedog - Frontend](https://github.com/DataDog/storedog-frontend) repo. |
| 24 | +# Backend |
19 | 25 | ## Database rebuild |
20 | 26 |
|
21 | 27 | The current database is based off sample data provided by the Spree starter kit. To create a new `.sql` dump file, run the following command while the application is running. |
|
58 | 64 | Password: spree123 |
59 | 65 | ``` |
60 | 66 |
|
61 | | -## Image publication |
62 | | -Images are stored in our public ECR repo `public.ecr.aws/x2b9z2t7`. On PR merges, only the affected services will be pushed to the ECR repo, using the `latest` tag. For example, if you only made changes to the `backend` service, then only the `backend` Github workflow will trigger and publish `public.ecr.aws/x2b9z2t7/storedog/backend:latest`. |
63 | 67 |
|
64 | | -Separately, we tag and publish *all* images when a new release is created with the corresponding release tag e.g. `public.ecr.aws/x2b9z2t7/storedog/backend:1.0.1`. New releases are made on an ad-hoc basis, depending on the recent features that are added. |
| 68 | +# Frontend |
| 69 | + |
| 70 | +## Considerations |
| 71 | + |
| 72 | +- `packages/commerce` contains all types, helpers and functions to be used as base to build a new **provider**. |
| 73 | +- **Providers** live under `packages`'s root folder and they will extend Next.js Commerce types and functionality (`packages/commerce`). |
| 74 | +- We have a **Features API** to ensure feature parity between the UI and the Provider. The UI should update accordingly and no extra code should be bundled. All extra configuration for features will live under `features` in `commerce.config.json` and if needed it can also be accessed programatically. |
| 75 | +- Each **provider** should add its corresponding `next.config.js` and `commerce.config.json` adding specific data related to the provider. For example in case of BigCommerce, the images CDN and additional API routes. |
| 76 | + |
| 77 | +## Configuration |
| 78 | + |
| 79 | +### Enable RUM |
| 80 | + |
| 81 | +To enable RUM, generate a new RUM application in DD and then set the `NEXT_PUBLIC_DD_APPLICATION_KEY` and `NEXT_PUBLIC_CLIENT_TOKEN` values in `./site/.env.local`. Then start the app, click around the site, and you should start to see RUM metrics populating in DD. |
| 82 | + |
| 83 | +### Features |
| 84 | + |
| 85 | +Every provider defines the features that it supports under `packages/{provider}/src/commerce.config.json` |
| 86 | + |
| 87 | +#### Features Available |
| 88 | + |
| 89 | +The following features can be enabled or disabled. This means that the UI will remove all code related to the feature. |
| 90 | +For example: Turning `cart` off will disable Cart capabilities. |
| 91 | + |
| 92 | +- cart |
| 93 | +- search |
| 94 | +- wishlist |
| 95 | +- customerAuth |
| 96 | +- customCheckout |
| 97 | + |
| 98 | +#### How to turn Features on and off |
| 99 | + |
| 100 | +> NOTE: The selected provider should support the feature that you are toggling. (This means that you can't turn wishlist on if the provider doesn't support this functionality out the box) |
| 101 | +
|
| 102 | +- Open `site/commerce.config.json` |
| 103 | +- You'll see a config file like this: |
| 104 | + ```json |
| 105 | + { |
| 106 | + "features": { |
| 107 | + "wishlist": false, |
| 108 | + "customCheckout": true |
| 109 | + } |
| 110 | + } |
| 111 | + ``` |
| 112 | +- Turn `wishlist` on by setting `wishlist` to `true`. |
| 113 | +- Run the app and the wishlist functionality should be back on. |
| 114 | + |
| 115 | +## Troubleshoot |
| 116 | + |
| 117 | +<details> |
| 118 | +<summary>When run locally I get `Error: Cannot find module '...@vercel/commerce/dist/config'`</summary> |
| 119 | + |
| 120 | +```bash |
| 121 | +commerce/site |
| 122 | +❯ yarn dev |
| 123 | +yarn run v1.22.17 |
| 124 | +$ next dev |
| 125 | +ready - started server on 0.0.0.0:3000, url: http://localhost:3000 |
| 126 | +info - Loaded env from /commerce/site/.env.local |
| 127 | +error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error |
| 128 | +Error: Cannot find module '/Users/dom/work/vercel/commerce/node_modules/@vercel/commerce/dist/config.cjs' |
| 129 | + at createEsmNotFoundErr (node:internal/modules/cjs/loader:960:15) |
| 130 | + at finalizeEsmResolution (node:internal/modules/cjs/loader:953:15) |
| 131 | + at resolveExports (node:internal/modules/cjs/loader:482:14) |
| 132 | + at Function.Module._findPath (node:internal/modules/cjs/loader:522:31) |
| 133 | + at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27) |
| 134 | + at Function.mod._resolveFilename (/Users/dom/work/vercel/commerce/node_modules/next/dist/build/webpack/require-hook.js:179:28) |
| 135 | + at Function.Module._load (node:internal/modules/cjs/loader:778:27) |
| 136 | + at Module.require (node:internal/modules/cjs/loader:1005:19) |
| 137 | + at require (node:internal/modules/cjs/helpers:102:18) |
| 138 | + at Object.<anonymous> (/Users/dom/work/vercel/commerce/site/commerce-config.js:9:14) { |
| 139 | + code: 'MODULE_NOT_FOUND', |
| 140 | + path: '/Users/dom/work/vercel/commerce/node_modules/@vercel/commerce/package.json' |
| 141 | +} |
| 142 | +error Command failed with exit code 1. |
| 143 | +info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. |
| 144 | +``` |
| 145 | + |
| 146 | +The error usually occurs when running yarn dev inside of the `/site/` folder after installing a fresh repository. |
| 147 | + |
| 148 | +In order to fix this, run `yarn dev` in the monorepo root folder first. |
| 149 | + |
| 150 | +> Using `yarn dev` from the root is recommended for developing, which will run watch mode on all packages. |
| 151 | +
|
| 152 | +</details> |
| 153 | + |
| 154 | +<details> |
| 155 | +<summary>When run locally I get `Error: Spree API cannot be reached'`</summary> |
| 156 | + |
| 157 | +The error usually occurs when the backend containers are not yet fully healthy, but the frontend has already started making API requests. |
| 158 | + |
| 159 | +In the docker logs output for storedog-backend, check to see if the backend has fully started. You should see the following log for the `web` container: |
| 160 | +``` |
| 161 | +web_1 | [1] * Listening on http://0.0.0.0:4000 |
| 162 | +``` |
| 163 | + |
| 164 | +</details> |
0 commit comments