Ver código fonte

chore: Add backend debug

Co-authored-by: Kristian Vos <k.vos@kvos.dev>
Owen Diffey 1 semana atrás
pai
commit
418327cc9c

+ 3 - 0
.env.example

@@ -4,6 +4,9 @@ CONTAINER_MODE=production
 
 APP_ENV=production
 
+BACKEND_DEBUG=false
+BACKEND_DEBUG_PORT=9229
+
 FRONTEND_CLIENT_PORT=80
 FRONTEND_DEV_PORT=81
 FRONTEND_PROD_DEVTOOLS=false

+ 0 - 1
.gitignore

@@ -2,7 +2,6 @@ Thumbs.db
 .DS_Store
 *.swp
 .idea/
-.vscode/
 .vagrant/
 
 .env

+ 21 - 0
.vscode/launch.json

@@ -0,0 +1,21 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "Docker: Attach to Node",
+            "type": "node",
+            "request": "attach",
+            "port": 9229,
+            "address": "localhost",
+            "localRoot": "${workspaceFolder}/backend",
+            "remoteRoot": "/opt/app/",
+            "autoAttachChildProcesses": true,
+            "restart": true,
+            "continueOnAttach": true,
+            "smartStep": true
+        }
+    ]
+}

+ 2 - 0
.wiki/Configuration.md

@@ -18,6 +18,8 @@ environment variables yourself.
 | `DOCKER_COMMAND` | Should be either `docker` or `podman`.  |
 | `CONTAINER_MODE` | Should be either `production` or `local`.  |
 | `APP_ENV` | Should be either `production` or `development`.  |
+| `BACKEND_DEBUG` | Should be either `true` or `false`. If enabled backend will await debugger connection and trigger to start. |
+| `BACKEND_DEBUG_PORT` | Backend container debug port, if enabled. |
 | `FRONTEND_CLIENT_PORT` | Should be the port on which the frontend will be accessible from, usually port `80`, or `443` if using SSL. Only used when running in development mode. |
 | `FRONTEND_DEV_PORT` | Should be the port where Vite's dev server will be accessible from, should always be port `81` for Docker since nginx listens on port 80, and is recommended to be port `80` for non-Docker. Only used when running in development mode. |
 | `FRONTEND_PROD_DEVTOOLS` | Whether to enable Vue dev tools in production builds. [^1] |

+ 6 - 0
backend/entrypoint.dev.sh

@@ -7,6 +7,12 @@ if [ ! -d node_modules ]; then
     npm install
 fi
 
+if [ "${BACKEND_DEBUG}" = "true" ]; then
+    export INSPECT_BRK="--inspect-brk=0.0.0.0:${BACKEND_DEBUG_PORT:-9229}"
+else
+    export INSPECT_BRK=""
+fi
+
 if [ "${APP_ENV}" = "development" ]; then
     npm run dev
 else

+ 7 - 0
backend/nodemon.json

@@ -0,0 +1,7 @@
+{
+    "ext": "js,json",
+	"stdin": true,
+	"stdout": true,
+	"signal": "SIGUSR2",
+	"exec": "node --import=extensionless/register -i ${INSPECT_BRK} /opt/app"
+}

+ 1 - 1
backend/package.json

@@ -9,7 +9,7 @@
   "license": "GPL-3.0",
   "repository": "https://github.com/Musare/Musare",
   "scripts": {
-    "dev": "nodemon --import=extensionless/register --legacy-watch --no-stdin /opt/app",
+    "dev": "nodemon",
     "prod": "node --import=extensionless/register /opt/app",
     "lint": "eslint . --ext .js",
     "typescript": "tsc --noEmit --skipLibCheck"

+ 2 - 0
compose.dev.yml

@@ -4,6 +4,8 @@ services:
       dockerfile: ./Dockerfile.dev
     environment:
       - APP_ENV=${APP_ENV:-development}
+      - BACKEND_DEBUG=${BACKEND_DEBUG:-false}
+      - BACKEND_DEBUG_PORT=${BACKEND_DEBUG_PORT:-9229}
 
   frontend:
     build: