Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 55 additions & 37 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,48 +1,66 @@
DD_API_KEY=
DD_APP_KEY=
# this is used specifically for datadog-ci
DATADOG_API_KEY=
DD_ENV=storedog-local
DD_HOSTNAME=storedog-local-host
# =============================================
# Datadog API Keys and Configuration
# =============================================
DD_API_KEY= # Required for Datadog Agent and APM
DD_APP_KEY= # Required for Datadog API access
DATADOG_API_KEY= # Used specifically for datadog-ci
NEXT_PUBLIC_DD_APPLICATION_ID= # Required for RUM in frontend service
NEXT_PUBLIC_DD_CLIENT_TOKEN= # Required for RUM in frontend service

# for puppeteer
STOREDOG_URL=http://nginx:80
# =============================================
# Environment and Host Configuration
# =============================================
DD_ENV=development
DD_HOSTNAME=development-host
NEXT_PUBLIC_DD_ENV=development # Required for RUM in frontend service
NEXT_PUBLIC_DD_SITE=datadoghq.com # Required for RUM in frontend service

# for spree, discounts, ads-python (if used), and dbm (if used)
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres

# set versions of specific services (these are used in the `docker-compose.yml` file)
# use NEXT_PUBLIC_* for frontend service to expose to the web browser
# =============================================
# Service Versions
# =============================================
NEXT_PUBLIC_DD_VERSION_FRONTEND=1.0.0
# use for worker service too, since they use the same image
DD_VERSION_BACKEND=1.0.0
DD_VERSION_DBM=1.0.0
DD_VERSION_ADS=1.0.0
DD_VERSION_DISCOUNTS=1.0.0
DD_VERSION_POSTGRES=15
DD_VERSION_REDIS=6.2
DD_VERSION_NGINX=1.0.0

# NEXT_PUBLIC_* are exposed to the web browser and the server #
# these are also used in `docker-compose.yml`

# used in server-side fetch calls in frontend service, note the use of full domains
NEXT_PUBLIC_FRONTEND_API_ROUTE=http://nginx:80
NEXT_PUBLIC_SPREE_API_HOST=http://nginx/services/backend
# =============================================
# Database Configuration (used in backend, worker, discounts, and dbm services)
# =============================================
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
DB_HOST=postgres
DB_PORT=5432
DB_POOL=25 # Database connection pool size set in backend service (default: 25)
MAX_THREADS=5 # Maximum number of concurrent threads set in backend service (default: 5)

# for all client-side spree fetch calls from frontend service
NEXT_PUBLIC_SPREE_CLIENT_HOST=/services/backend
NEXT_PUBLIC_SPREE_IMAGE_HOST=/services/backend
# configured in the next.config.js file to allow for image loading from the spree service
NEXT_PUBLIC_SPREE_ALLOWED_IMAGE_DOMAIN=nginx
# =============================================
# Frontend Service Configuration
# =============================================
FRONTEND_COMMAND='npm run dev' # Command to run the frontend service (default: 'npm run dev', use 'npm run build && npm run start' for production)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THIS IS SO GREAT

NEXT_PUBLIC_DD_SERVICE_FRONTEND=store-frontend # Service name for frontend service in Datadog
NEXT_PUBLIC_FRONTEND_API_ROUTE=http://nginx:80 # base url for next.js API routes (default: 'http://nginx:80')
NEXT_PUBLIC_SPREE_API_HOST=http://nginx/services/backend # base url for backend service (default: 'http://nginx/services/backend')
NEXT_PUBLIC_SPREE_CLIENT_HOST=/services/backend # base url for backend service (default: '/services/backend')
NEXT_PUBLIC_SPREE_IMAGE_HOST=/services/backend # base url for backend service (default: '/services/backend')
NEXT_PUBLIC_SPREE_ALLOWED_IMAGE_DOMAIN=nginx # allowed image domain for backend service (default: 'nginx')
NEXT_PUBLIC_ADS_ROUTE=/services/ads # base url for ads service (default: '/services/ads')
NEXT_PUBLIC_DISCOUNTS_ROUTE=/services/discounts # base url for discounts service (default: '/services/discounts')
NEXT_PUBLIC_DBM_ROUTE=/services/dbm # base url for dbm service (default: '/services/dbm')

# called in client-side fetch calls from frontend service (no need to include the domain)
NEXT_PUBLIC_ADS_ROUTE=/services/ads
NEXT_PUBLIC_DISCOUNTS_ROUTE=/services/discounts
NEXT_PUBLIC_DBM_ROUTE=/services/dbm
# =============================================
# Backend Service Configuration
# =============================================
RAILS_ENV=production
REDIS_URL=redis://redis:6379/0
DISABLE_SPRING=1

# used in frontend service app.tsx file for RUM config
NEXT_PUBLIC_DD_APPLICATION_ID=
NEXT_PUBLIC_DD_CLIENT_TOKEN=
NEXT_PUBLIC_DD_SITE=datadoghq.com
NEXT_PUBLIC_DD_SERVICE_FRONTEND=store-frontend
NEXT_PUBLIC_DD_ENV=storedog-local
# see version in NEXT_PUBLIC_DD_VERSION_FRONTEND above
# =============================================
# Puppeteer Configuration
# =============================================
STOREDOG_URL=http://nginx:80 # base url for storedog service (default: 'http://nginx:80')
PUPPETEER_TIMEOUT=30000 # timeout for puppeteer (default: 30000)
SKIP_SESSION_CLOSE= # skip session close for puppeteer (default: '')
44 changes: 44 additions & 0 deletions .github/workflows/puppeteer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Puppeteer

permissions: {}

on:
push:
branches: [main]
paths:
- services/puppeteer/**
workflow_dispatch:

defaults:
run:
working-directory: puppeteer

jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Vulnerability

Workflow depends on a GitHub actions pinned by tag instead of a hash. (...read more)

Pin GitHub Actions by commit hash to ensure supply chain security.

Using a branch (@main) or tag (@v1) allows for implicit updates, which can introduce unexpected or malicious changes. Instead, always pin actions to a full length commit SHA. You can find the commit SHA for the latest tag from the action’s repository and ensure frequent updates via auto-updaters such as dependabot. Include a comment with the corresponding full-length SemVer tag for clarity:

      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

View in Datadog  Leave us feedback  Documentation


- name: Login to GHCR
id: login-ghcr
uses: docker/login-action@v3

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Vulnerability

Workflow depends on a GitHub actions pinned by tag instead of a hash. (...read more)

Pin GitHub Actions by commit hash to ensure supply chain security.

Using a branch (@main) or tag (@v1) allows for implicit updates, which can introduce unexpected or malicious changes. Instead, always pin actions to a full length commit SHA. You can find the commit SHA for the latest tag from the action’s repository and ensure frequent updates via auto-updaters such as dependabot. Include a comment with the corresponding full-length SemVer tag for clarity:

      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

View in Datadog  Leave us feedback  Documentation

with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Vulnerability

Workflow depends on a GitHub actions pinned by tag instead of a hash. (...read more)

Pin GitHub Actions by commit hash to ensure supply chain security.

Using a branch (@main) or tag (@v1) allows for implicit updates, which can introduce unexpected or malicious changes. Instead, always pin actions to a full length commit SHA. You can find the commit SHA for the latest tag from the action’s repository and ensure frequent updates via auto-updaters such as dependabot. Include a comment with the corresponding full-length SemVer tag for clarity:

      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

View in Datadog  Leave us feedback  Documentation

with:
context: ./services/puppeteer
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/datadog/storedog/puppeteer:latest
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
ghcr.io/datadog/storedog/frontend
ghcr.io/datadog/storedog/dbm
ghcr.io/datadog/storedog/postgres
ghcr.io/datadog/storedog/puppeteer
)

for i in "${IMAGES[@]}"
Expand Down
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,40 @@ Many parts of this application were intentionally modified to introduce performa

## Local development

1. Before starting the containers, you will need to define the required env vars. Run the following command to copy the env var template:
The Storedog application comes pre-configured with default values for all services. These defaults are baked into:
- Service Dockerfiles
- docker-compose.yml
- .env.template

The only values you need to provide are your Datadog credentials to enable Datadog features:

1. Copy the environment template:
```sh
cp .env.template .env
```

1. 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_*` variables, which are required to enable different Datadog services and features.

You'll need to bring your own Datadog API key, application key, and RUM Client Token/Application ID values. You can find these in your Datadog org.
1. Open the `.env` file and provide your Datadog credentials:
- `DD_API_KEY`: Required for Datadog Agent and APM
- `DD_APP_KEY`: Required for Datadog API access
- `NEXT_PUBLIC_DD_APPLICATION_ID`: Required for RUM in frontend service

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add a comment saying that you need to create a RUM Application (local dev: create one in Datadog, lab dev: use the configrum script)

- `NEXT_PUBLIC_DD_CLIENT_TOKEN`: Required for RUM in frontend service

1. Start the app's services via `docker compose up`:
You can find these values in your Datadog organization. All other variables have sensible defaults and can be left as-is.

1. Start the application:
```sh
docker compose up
docker compose up -d
```

1. Visit http://localhost to use the app. The homepage will take a few seconds to load as the backend is still starting up.
1. Visit http://localhost to use the app. The homepage will take a few seconds to load as the backend services initialize.

If you see a 502 error for an extended period, check the service health with:
```sh
docker compose logs <service-name>
```

If you see a 502 error for a while, confirm services are healthy by running `docker compose logs <service-name>` and checking logs.
> [!NOTE]
> By default, the frontend service runs in development mode. If you want to run it in production, you can set the `FRONTEND_COMMAND` environment variable to `npm run build && npm run start`. This can be done either on the host or in the `.env` file.

## Feature flags
Some capabilities are hidden behind feature flags, which can be controlled via `services/frontend/site/featureFlags.config.json`.
Expand Down
Loading