Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hot server reload & debugging over docker #2718

Merged
merged 18 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/node-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ jobs:
with:
push: false
platforms: ${{ matrix.platform.arch }}
file: packages/${{ matrix.package }}/Dockerfile
file: packages/${{ matrix.package }}/Dockerfile.prod
tags: ghcr.io/${{ github.repository_owner }}/rafiki-${{ matrix.package }}:${{ needs.version-generator.outputs.version }}
outputs: type=docker,dest=/tmp/${{ github.sha }}-${{ matrix.package }}-${{ matrix.platform.name }}-${{ needs.version-generator.outputs.version }}.tar
- name: Save docker image to cache
Expand Down
41 changes: 41 additions & 0 deletions localenv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,47 @@ Note that you have to go through an additional "login" step by providing you IPv

After stopping the script it is necessary to clear the environment using the command described in [Shutting down](#Shutting-down). This is necessary as on a new run of the scripts (with autopeering or not) the wallet address url will differ.

### Debugging
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add a section with the launch.json configuration for VSCode as well?

Also, did you want to keep it just in this readme, or should we also add it to the documentation site?

Copy link
Contributor Author

@BlairCurrey BlairCurrey May 16, 2024

Choose a reason for hiding this comment

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

added the vscode section and added to the documentation site: 02a5e6b


Debuggers for the services are exposed on the following ports:

| IP and Port | Services |
| -------------- | ------------------------- |
| 127.0.0.1:9229 | Cloud Nine Wallet Backend |
| 127.0.0.1:9230 | Cloud Nine Auth |
| 127.0.0.1:9231 | Happy Life Bank Backend |
| 127.0.0.1:9232 | Happy Life Bank Auth |

#### With a chromium browser:

- go to `chrome://inspect`
- Click "Configure" and add the IP addresses and ports detailed above
- start docker containers
- click "inspect" on the service you want to debug to open the chromium debugger

You can either trigger the debugger by adding `debugger` statements in code and restarting, or by adding breakpoints directly in the chromium debugger after starting the docker containers.

#### With VS Code:

For debugging with VS Code, you can add this configuration to your `.vscode/launch.json`):

```json
{
"name": "Attach to docker (cloud-nine-backend)",
"type": "node",
"request": "attach",
"port": 9229,
"address": "localhost",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/home/rafiki/",
"restart": true
},
```

`localRoot` will vary depending on the location of `launch.json` relative to rafiki's root directory.

For more ways to connect debuggers, see the Node docs for debugging: https://nodejs.org/en/learn/getting-started/debugging

### Shutting down

```
Expand Down
18 changes: 15 additions & 3 deletions localenv/cloud-nine-wallet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ services:
image: rafiki-backend
build:
context: ../..
dockerfile: ./packages/backend/Dockerfile
dockerfile: ./packages/backend/Dockerfile.dev
volumes:
- type: bind
source: ../../packages/backend/src
target: /home/rafiki/packages/backend/src
read_only: true
restart: always
privileged: true
ports:
- '3000:80'
- '3001:3001'
- '3002:3002'
- "9229:9229"
networks:
- rafiki
environment:
Expand Down Expand Up @@ -73,13 +79,19 @@ services:
image: rafiki-auth
build:
context: ../..
dockerfile: ./packages/auth/Dockerfile
dockerfile: ./packages/auth/Dockerfile.dev
volumes:
- type: bind
source: ../../packages/auth/src
target: /home/rafiki/packages/auth/src
read_only: true
restart: always
networks:
- rafiki
ports:
- '3003:3003'
- '3006:3006'
- "9230:9229"
environment:
NODE_ENV: ${NODE_ENV:-development}
TRUST_PROXY: ${TRUST_PROXY}
Expand Down Expand Up @@ -112,7 +124,7 @@ services:
image: rafiki-frontend
build:
context: ../..
dockerfile: ./packages/frontend/devDockerfile
dockerfile: ./packages/frontend/Dockerfile.dev
Copy link
Contributor Author

@BlairCurrey BlairCurrey May 10, 2024

Choose a reason for hiding this comment

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

went ahead and renamed this for consistency. I went with Dockerfile.dev because that seemed to be a more standard convention from examples I saw a variety of places. VSCode also recognizes its a dockerfile from name alone, whereas it did not with devDockerfile.

volumes:
- type: bind
source: ../../packages/frontend/app
Expand Down
12 changes: 12 additions & 0 deletions localenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ services:
hostname: happy-life-bank-backend
image: rafiki-backend
pull_policy: never
volumes:
- type: bind
source: ../../packages/backend/src
target: /home/rafiki/packages/backend/src
read_only: true
restart: always
privileged: true
ports:
- "4000:80"
- "4001:3001"
- '9231:9229'
networks:
- rafiki
environment:
Expand Down Expand Up @@ -64,11 +70,17 @@ services:
image: rafiki-auth
pull_policy: never
restart: always
volumes:
- type: bind
source: ../../packages/auth/src
target: /home/rafiki/packages/auth/src
read_only: true
networks:
- rafiki
ports:
- '4003:3003'
- '4006:3006'
- '9232:9229'
environment:
NODE_ENV: development
AUTH_DATABASE_URL: postgresql://happy_life_bank_auth:happy_life_bank_auth@shared-database/happy_life_bank_auth
Expand Down
24 changes: 24 additions & 0 deletions packages/auth/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:20-alpine3.18

WORKDIR /home/rafiki

RUN corepack enable
RUN corepack prepare pnpm@8.7.4 --activate

COPY pnpm-lock.yaml package.json pnpm-workspace.yaml .npmrc tsconfig.json tsconfig.build.json ./

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm fetch \
| grep -v "cross-device link not permitted\|Falling back to copying packages from store"

COPY . ./

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--offline \
--frozen-lockfile

RUN pnpm --filter auth build:deps

CMD pnpm --filter auth dev
File renamed without changes.
4 changes: 3 additions & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"prepack": "pnpm build",
"postinstall": "pnpm copy-op-schemas",
"copy-op-schemas": "cp ./node_modules/@interledger/open-payments/dist/openapi/specs/auth-server.yaml ./node_modules/@interledger/open-payments/dist/openapi/specs/schemas.yaml ./src/openapi/specs/",
"copy-files": "cp src/graphql/schema.graphql dist/graphql/ && cp -r ./src/openapi ./dist/"
"copy-files": "cp src/graphql/schema.graphql dist/graphql/ && cp -r ./src/openapi ./dist/",
"dev": "ts-node-dev --inspect=0.0.0.0:9229 --respawn --transpile-only src/index.ts"
},
"dependencies": {
"@adonisjs/fold": "^8.2.0",
Expand Down Expand Up @@ -47,6 +48,7 @@
"pg": "^8.11.3",
"pino": "^8.19.0",
"token-introspection": "workspace:*",
"ts-node-dev": "^2.0.0",
"uuid": "^9.0.1"
},
"devDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion packages/auth/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"rootDir": "./src",
"declaration": true
},
"include": ["src/**/*"]
"include": ["src/**/*"],
"ts-node": {
"swc": true
}
}
24 changes: 24 additions & 0 deletions packages/backend/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:20-alpine3.18

WORKDIR /home/rafiki

RUN corepack enable
RUN corepack prepare pnpm@8.7.4 --activate

COPY pnpm-lock.yaml package.json pnpm-workspace.yaml .npmrc tsconfig.json tsconfig.build.json ./

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm fetch \
| grep -v "cross-device link not permitted\|Falling back to copying packages from store"

COPY . ./

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--offline \
--frozen-lockfile

RUN pnpm --filter backend build:deps

CMD pnpm --filter backend dev
File renamed without changes.
6 changes: 4 additions & 2 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"copy-files": "cp src/graphql/schema.graphql dist/graphql/ && cp -r ./src/openapi ./dist/",
"copy-op-schemas": "cp ./node_modules/@interledger/open-payments/dist/openapi/specs/schemas.yaml ./src/openapi/specs/",
"prepack": "pnpm build",
"postinstall": "pnpm copy-op-schemas"
"postinstall": "pnpm copy-op-schemas",
"dev": "ts-node-dev --inspect=0.0.0.0:9229 --respawn --transpile-only src/index.ts"
},
"devDependencies": {
"@apollo/client": "^3.9.9",
Expand Down Expand Up @@ -42,7 +43,8 @@
"react": "~18.2.0",
"rosie": "^2.1.1",
"testcontainers": "^10.7.2",
"tmp": "^0.2.3"
"tmp": "^0.2.3",
"ts-node-dev": "^2.0.0"
},
"dependencies": {
"@adonisjs/fold": "^8.2.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"]
"include": ["src/**/*"],
"ts-node": {
"swc": true
}
}
41 changes: 41 additions & 0 deletions packages/documentation/src/content/docs/playground/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,47 @@ The secondary Happy Life Bank docker compose file (`./happy-life-bank/docker-com
data stores created by the primary Rafiki instance so it can't be run by itself.
The `pnpm localenv:compose up` command starts both the primary instance and the secondary.

### Debugging

Debuggers for the services are exposed on the following ports:

| IP and Port | Services |
| -------------- | ----------------------- |
| 127.0.0.1:9229 | Cloud Nine Backend |
| 127.0.0.1:9230 | Cloud Nine Auth |
| 127.0.0.1:9231 | Happy Life Bank Backend |
| 127.0.0.1:9232 | Happy Life Bank Auth |

#### With a chromium browser:

- go to `chrome://inspect`
- Click "Configure" and add the IP addresses and ports detailed above
- start docker containers
- click "inspect" on the service you want to debug to open the chromium debugger

You can either trigger the debugger by adding `debugger` statements in code and restarting, or by adding breakpoints directly in the chromium debugger after starting the docker containers.

#### With Vscode:

For debugging with Vscode, you can add this configuration to your `.vscode/launch.json`):

```json
{
"name": "Attach to docker (cloud-nine-backend)",
"type": "node",
"request": "attach",
"port": 9229,
"address": "localhost",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/home/rafiki/",
"restart": true
},
```

`localRoot` will vary depending on the location of `launch.json` relative to rafiki's root directory.

For more ways to connect debuggers, see the Node docs for debugging: https://nodejs.org/en/learn/getting-started/debugging

### Shutting down

```
Expand Down
File renamed without changes.
File renamed without changes.
Loading
Loading