Skip to content

Commit 0bd0d75

Browse files
authored
feat(wallet/backend,boutique/backend): DEV env - add hot reload for wallet and boutique backends (#1740)
* setup wallet backend hot reload * setup wallet backend hot reload dockerfile.dev * setup boutique backend hot reload * wallet hot reload watch also for shared folder changes * fix watch share path and remove chokidar env var * enable multiple types of local environment run configurations * pretty fix * fix pnpm lock
1 parent 36a6c42 commit 0bd0d75

10 files changed

Lines changed: 159 additions & 35 deletions

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,19 @@ If you would like to set up e-commerce application, you will need to create a US
100100
Navigate to the project's root directory and execute:
101101

102102
```sh
103-
pnpm dev
103+
pnpm dev #this will start the project in hot reload mode for backend containers. Frontend containers have hot reload functionality enabled on all dev commads
104+
```
105+
106+
other options to start the local env are:
107+
108+
```sh
109+
pnpm dev:debug #backend containers will not have hot reload feture enabled but will expose and have node `--inspect` option set with wallet container debug port set to 9229 and boutique port set to 9230. Once the containers are running, you can connect your debugger (e.g., Chrome DevTools, VS Code)
110+
```
111+
112+
and:
113+
114+
```sh
115+
pnpm dev:lite #backend containers will build and run the builds, no debug and no hot reload for these containers
104116
```
105117

106118
Upon executing the above command, the following will be available

boutique-entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
if [ "$DEV_MODE" = "lite" ]; then
4+
echo "DEV_MODE is lite, running default command..."
5+
exec node ./packages/boutique/backend/dist/index.js
6+
elif [ "$DEV_MODE" = "debug" ]; then
7+
echo "DEV_MODE is debug, running build with debug port $DEBUG_PORT open..."
8+
exec node --inspect=0.0.0.0:${DEBUG_PORT} ./packages/boutique/backend/dist/index.js
9+
else
10+
echo "DEV_MODE is hot-reload, running dev command with nodemon watcher and rebuild..."
11+
exec pnpm boutique:backend dev
12+
fi

docker/dev/docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ services:
2727
container_name: wallet-backend
2828
build:
2929
context: ../..
30+
args:
31+
DEV_MODE: ${DEV_MODE}
3032
dockerfile: ./packages/wallet/backend/Dockerfile.dev
3133
depends_on:
3234
- postgres
3335
- rafiki-backend
3436
- redis
37+
volumes:
38+
- ../../packages/wallet/backend:/home/testnet/packages/wallet/backend
39+
- ../../packages/wallet/shared:/home/testnet/packages/wallet/shared
3540
environment:
3641
NODE_ENV: development
3742
PORT: 3003
43+
DEBUG_PORT: 9229
3844
DATABASE_URL: postgres://wallet_backend:wallet_backend@postgres/wallet_backend
3945
COOKIE_NAME: testnet.cookie
4046
COOKIE_PASSWORD: testnet.cookie.password.super.secret.ilp
@@ -76,12 +82,18 @@ services:
7682
container_name: boutique-backend
7783
build:
7884
context: ../..
85+
args:
86+
DEV_MODE: ${DEV_MODE}
7987
dockerfile: ./packages/boutique/backend/Dockerfile.dev
88+
volumes:
89+
- ../../packages/boutique/backend:/home/testnet/packages/boutique/backend
90+
- ../../packages/boutique/shared:/home/testnet/packages/boutique/shared
8091
depends_on:
8192
- postgres
8293
environment:
8394
NODE_ENV: development
8495
PORT: 3004
96+
DEBUG_PORT: 9230
8597
DATABASE_URL: postgres://boutique_backend:boutique_backend@postgres/boutique_backend
8698
PRIVATE_KEY: ${PRIVATE_KEY}
8799
KEY_ID: ${KEY_ID}
@@ -91,6 +103,7 @@ services:
91103
- testnet
92104
ports:
93105
- '3004:3004'
106+
- '9230:9230' # Map debugger port to local machine's port 9230
94107
<<: *logging
95108

96109
# Rafiki

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
"clean:builds": "find . \\( -name \"dist\" -o -name \".next\" \\) -type d -prune -exec rm -rf '{}' +",
1818
"clean:modules": "find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +",
1919
"dev": "pnpm localenv:start && concurrently -n 'WALLET,BOUTIQUE' -c blue.bold,red.bold 'pnpm wallet:frontend dev' 'pnpm boutique:frontend dev'",
20+
"dev:debug": "pnpm localenv:start:debug && concurrently -n 'WALLET,BOUTIQUE' -c blue.bold,red.bold 'pnpm wallet:frontend dev' 'pnpm boutique:frontend dev'",
21+
"dev:lite": "pnpm localenv:start:lite && concurrently -n 'WALLET,BOUTIQUE' -c blue.bold,red.bold 'pnpm wallet:frontend dev' 'pnpm boutique:frontend dev'",
2022
"format": "pnpm prettier:write && pnpm lint:fix",
2123
"lint:check": "eslint --max-warnings=0 .",
2224
"lint:fix": "eslint --max-warnings=0 --fix .",
2325
"compose": "docker compose -f ./docker/dev/docker-compose.yml",
2426
"compose:prod": "docker compose -f ./docker/prod/docker-compose.yml",
25-
"localenv:start": "pnpm compose up -d --build",
27+
"localenv:start": "DEV_MODE=hot-reload pnpm compose up -d --build",
28+
"localenv:start:debug": "DEV_MODE=debug pnpm compose up -d --build",
29+
"localenv:start:lite": "DEV_MODE=lite pnpm compose up -d --build",
2630
"localenv:stop": "pnpm compose down",
2731
"preinstall": "npx only-allow pnpm",
2832
"prettier:write": "prettier --config '.prettierrc.js' --write .",
@@ -44,6 +48,7 @@
4448
"eslint-plugin-react": "^7.37.1",
4549
"eslint-plugin-react-hooks": "^4.6.2",
4650
"globals": "^15.10.0",
51+
"nodemon": "^3.1.7",
4752
"only-allow": "^1.2.1",
4853
"prettier": "^3.3.3",
4954
"prettier-plugin-tailwindcss": "^0.6.8",

packages/boutique/backend/Dockerfile.dev

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN corepack enable
1212
RUN corepack prepare pnpm@9.1.4 --activate
1313

1414
# Copy lockfile, NVM and NPM configuration to the working directory
15-
COPY pnpm-lock.yaml .nvmrc .npmrc ./
15+
COPY pnpm-lock.yaml .nvmrc .npmrc boutique-entrypoint.sh ./
1616

1717
# Fetch packages from lockfile (https://pnpm.io/cli/fetch#usage-scenario)
1818
RUN pnpm fetch
@@ -23,7 +23,16 @@ ADD . ./
2323
# Install packages from virtual store
2424
RUN pnpm install -r --offline
2525

26-
# Build backend
2726
RUN pnpm boutique:backend build
2827

29-
CMD ["node", "./packages/boutique/backend/dist/index.js"]
28+
# Expose debugger port regardlless of DEV_MODE
29+
EXPOSE ${DEBUG_PORT}
30+
31+
ARG DEV_MODE
32+
33+
# Set it as an environment variable
34+
ENV DEV_MODE=${DEV_MODE}
35+
36+
RUN chmod +x /home/testnet/boutique-entrypoint.sh
37+
38+
ENTRYPOINT ["/home/testnet/boutique-entrypoint.sh"]

packages/boutique/backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"start": "node dist/index.js",
55
"build:deps": "pnpm --filter @shared/backend build && pnpm --filter @boutique/shared build",
66
"build": "pnpm build:deps && tsc --build tsconfig.build.json && tsc-alias -p tsconfig.build.json",
7+
"dev": "nodemon --watch ./src --watch ../shared/src --ext ts,json --delay 0.5 --exec \"pnpm run build && node ./dist/index.js\"",
78
"test": "pnpm build:deps && NODE_OPTIONS='--experimental-vm-modules' jest --passWithNoTests --maxWorkers=2"
89
},
910
"dependencies": {

packages/wallet/backend/Dockerfile.dev

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN corepack enable
1212
RUN corepack prepare pnpm@9.1.4 --activate
1313

1414
# Copy lockfile, NVM and NPM configuration to the working directory
15-
COPY pnpm-lock.yaml .nvmrc .npmrc ./
15+
COPY pnpm-lock.yaml .nvmrc .npmrc wallet-entrypoint.sh ./
1616

1717
# Fetch packages from lockfile (https://pnpm.io/cli/fetch#usage-scenario)
1818
RUN pnpm fetch
@@ -27,6 +27,13 @@ RUN pnpm install -r --offline
2727
RUN pnpm wallet:backend build
2828

2929
# Expose debugger port
30-
EXPOSE 9229
30+
EXPOSE ${DEBUG_PORT}
3131

32-
CMD ["node", "--inspect=0.0.0.0:9229", "./packages/wallet/backend/dist/index.js"]
32+
ARG DEV_MODE
33+
34+
# Set it as an environment variable
35+
ENV DEV_MODE=${DEV_MODE}
36+
37+
RUN chmod +x /home/testnet/wallet-entrypoint.sh
38+
39+
ENTRYPOINT ["/home/testnet/wallet-entrypoint.sh"]

packages/wallet/backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"start": "node -r tsconfig-paths/register dist/index.js",
55
"build:deps": "pnpm --filter @shared/backend build && pnpm --filter @wallet/shared build",
66
"build": "pnpm build:deps && tsc --build tsconfig.build.json && tsc-alias -p tsconfig.build.json",
7+
"dev": "nodemon --watch ./src --watch ../shared/src --ext ts,json --delay 1 --exec \"pnpm run build && node ./dist/index.js\"",
78
"test": "jest --passWithNoTests --maxWorkers=75%",
89
"generate": "graphql-codegen --config codegen.yml"
910
},

0 commit comments

Comments
 (0)