Skip to content

Commit e0a2d06

Browse files
Merge frontend repo into backend repo (#31)
* merge frontend + nginx into backend * fix readme * add frontend * add in xss code
1 parent 968df02 commit e0a2d06

File tree

614 files changed

+40516
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

614 files changed

+40516
-20
lines changed

.env.template

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,41 @@ ATTACK_HOST=nginx
1111
ATTACK_PORT=80
1212
ATTACK_SSH_INTERVAL=0
1313
ATTACK_GOBUSTER_INTERVAL=0
14-
ATTACK_HYDRA_INTERVAL=0
14+
ATTACK_HYDRA_INTERVAL=0
15+
16+
17+
COMMERCE_PROVIDER=@vercel/commerce-spree
18+
# NEXT_PUBLIC_* are exposed to the web browser and the server #
19+
NEXT_PUBLIC_SPREE_API_HOST=http://web:4000
20+
NEXT_PUBLIC_SPREE_CLIENT_HOST=http://localhost:4000
21+
NEXT_PUBLIC_SPREE_DEFAULT_LOCALE=en-us
22+
NEXT_PUBLIC_SPREE_CART_COOKIE_NAME=spree_cart_token
23+
# cookie expire in days #
24+
NEXT_PUBLIC_SPREE_CART_COOKIE_EXPIRE=7
25+
NEXT_PUBLIC_SPREE_USER_COOKIE_NAME=spree_user_token
26+
NEXT_PUBLIC_SPREE_USER_COOKIE_EXPIRE=7
27+
NEXT_PUBLIC_SPREE_IMAGE_HOST=http://localhost:4000
28+
NEXT_PUBLIC_SPREE_ALLOWED_IMAGE_DOMAIN=localhost
29+
NEXT_PUBLIC_SPREE_CATEGORIES_TAXONOMY_PERMALINK=/t/categories
30+
NEXT_PUBLIC_SPREE_BRANDS_TAXONOMY_PERMALINK=/t/brands
31+
NEXT_PUBLIC_SPREE_ALL_PRODUCTS_TAXONOMY_ID=false
32+
NEXT_PUBLIC_SPREE_SHOW_SINGLE_VARIANT_OPTIONS=false
33+
NEXT_PUBLIC_SPREE_LAST_UPDATED_PRODUCTS_PRERENDER_COUNT=10
34+
NEXT_PUBLIC_SPREE_PRODUCT_PLACEHOLDER_IMAGE_URL=/product-img-placeholder.svg
35+
NEXT_PUBLIC_SPREE_LINE_ITEM_PLACEHOLDER_IMAGE_URL=/product-img-placeholder.svg
36+
NEXT_PUBLIC_SPREE_IMAGES_OPTION_FILTER=false
37+
NEXT_PUBLIC_SPREE_IMAGES_SIZE=1000x1000
38+
NEXT_PUBLIC_SPREE_IMAGES_QUALITY=100
39+
NEXT_PUBLIC_SPREE_LOGIN_AFTER_SIGNUP=true
40+
NEXT_PUBLIC_ADS_PORT=7676
41+
NEXT_PUBLIC_DISCOUNTS_PORT=2814
42+
NEXT_PUBLIC_ADS_ROUTE="http://localhost"
43+
NEXT_PUBLIC_DISCOUNTS_ROUTE="http://localhost"
44+
NEXT_PUBLIC_DD_APPLICATION_ID=""
45+
NEXT_PUBLIC_DD_CLIENT_TOKEN=""
46+
NEXT_PUBLIC_DD_SITE="datadoghq.com"
47+
NEXT_PUBLIC_DD_SERVICE="frontend"
48+
NEXT_PUBLIC_DD_VERSION="1.0.0"
49+
NEXT_PUBLIC_DD_ENV="development"
50+
NEXT_PUBLIC_AUTH_ROUTE="http://localhost"
51+
NEXT_PUBLIC_AUTH_PORT="7578"

.github/workflows/frontend.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Frontend
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- services/frontend/**
8+
workflow_dispatch:
9+
branches: [ main ]
10+
11+
defaults:
12+
run:
13+
working-directory: frontend
14+
15+
jobs:
16+
17+
build:
18+
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v1
27+
28+
- name: Configure AWS credentials
29+
uses: aws-actions/configure-aws-credentials@v1
30+
with:
31+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
32+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
33+
aws-region: us-east-1
34+
35+
- name: Login to ECR
36+
id: login-ecr
37+
uses: docker/login-action@v1
38+
with:
39+
registry: public.ecr.aws
40+
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
41+
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
42+
43+
- name: Build and push
44+
uses: docker/build-push-action@v2
45+
with:
46+
context: ./services/frontend
47+
platforms: linux/amd64
48+
push: true
49+
tags: ${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/frontend:latest
50+

.github/workflows/nginx.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Nginx
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- services/nginx/**
8+
workflow_dispatch:
9+
branches: [ main ]
10+
11+
defaults:
12+
run:
13+
working-directory: nginx
14+
15+
jobs:
16+
17+
build:
18+
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v1
27+
28+
- name: Configure AWS credentials
29+
uses: aws-actions/configure-aws-credentials@v1
30+
with:
31+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
32+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
33+
aws-region: us-east-1
34+
35+
- name: Login to ECR
36+
id: login-ecr
37+
uses: docker/login-action@v1
38+
with:
39+
registry: public.ecr.aws
40+
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
41+
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
42+
43+
- name: Build and push
44+
uses: docker/build-push-action@v2
45+
with:
46+
context: ./services/nginx
47+
platforms: linux/amd64
48+
push: true
49+
tags: ${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/nginx:latest
50+

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/ads-java
4343
${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/attackbox
4444
${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/auth
45+
${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/nginx
46+
${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/frontend
4547
)
4648
4749
for i in "${IMAGES[@]}"

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ yarn-debug.log*
4545
/yarn-error.log
4646
/app/assets/builds/*
4747
!/app/assets/builds/.keep
48+
49+
# local env files
50+
.env
51+
.env.development.local
52+
.env.test.local
53+
.env.production.local
54+
.env.local

README.md

Lines changed: 113 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
# Storedog Backend
1+
# Storedog
2+
3+
This a dockerized [Spree Commerce](https://spreecommerce.org) application consumed by a NextJS frontend.
24

3-
This a dockerized [Spree Commerce](https://spreecommerce.org) application consumed by [Storedog - Frontend](https://github.com/DataDog/storedog-frontend).
45
## Local development
56

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.
713

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.
916

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`
1118

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`.
1421

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.
1723

18-
To build the frontend, please see the README in the [Storedog - Frontend](https://github.com/DataDog/storedog-frontend) repo.
24+
# Backend
1925
## Database rebuild
2026

2127
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,7 +64,101 @@ Username: [email protected]
5864
Password: spree123
5965
```
6066

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`.
6367

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>

deploy/docker-compose/docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
version: '3.7'
22
services:
3+
frontend:
4+
image: public.ecr.aws/x2b9z2t7/storedog/frontend:1.0.2
5+
command: yarn dev
6+
volumes:
7+
- "../../services/frontend/site:/storedog-app/site"
8+
depends_on:
9+
- worker
10+
ports:
11+
- 3000:3000
12+
networks:
13+
- storedog-net
14+
nginx:
15+
image: public.ecr.aws/x2b9z2t7/storedog/nginx:1.0.2
16+
restart: always
17+
ports:
18+
- "80:80"
19+
depends_on:
20+
- frontend
21+
labels:
22+
com.datadoghq.ad.logs: '[{"source": "nginx", "service": "nginx"}]'
23+
networks:
24+
- storedog-net
325
postgres:
426
image: postgres:13-alpine
527
restart: always

0 commit comments

Comments
 (0)