NAS deployment fixed
This commit is contained in:
@@ -10,19 +10,29 @@ You need to build the application on your local machine before transferring it t
|
||||
Run the following in the project root:
|
||||
```bash
|
||||
npm install
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
> [!IMPORTANT]
|
||||
> If you encounter a `TypeError: Missing parameter name` in your logs, ensure you have rebuilt the app with the latest changes (`app.get('*all', ...)`).
|
||||
This creates a `dist` folder with the compiled frontend.
|
||||
|
||||
### Build Backend
|
||||
Run the following in the project root:
|
||||
1. Update your `server/package.json` to have these scripts for production:
|
||||
```json
|
||||
"scripts": {
|
||||
"start": "node dist/index.js",
|
||||
"start:prod": "node dist/index.js",
|
||||
...
|
||||
}
|
||||
```
|
||||
2. Run the following locally:
|
||||
```bash
|
||||
cd server
|
||||
npm install
|
||||
npm run build
|
||||
cd ..
|
||||
```
|
||||
This creates a `server/dist` folder with the compiled backend.
|
||||
|
||||
## 2. Transfer Files
|
||||
|
||||
@@ -38,22 +48,43 @@ Ensure the following files/folders are present on the NAS:
|
||||
|
||||
*Note: You do not need to copy `node_modules`. We will install production dependencies on the NAS to ensure compatibility.*
|
||||
|
||||
## 3. Integration
|
||||
Update your `docker-compose.yml` to use a custom Dockerfile (to support building native modules like `better-sqlite3`) and map the new port.
|
||||
|
||||
Update your `docker-compose.yml` to include GymFlow in the startup command and map the new port.
|
||||
### 2a. Use Custom Dockerfile
|
||||
The standard `node:lts-slim` image lacks Python and build tools. Use the provided [Dockerfile.node-apps](file:///d:/Coding/gymflow/Dockerfile.node-apps):
|
||||
|
||||
1. Copy `Dockerfile.node-apps` to your NAS alongside `docker-compose.yml`.
|
||||
2. Modify `docker-compose.yml`:
|
||||
```yaml
|
||||
services:
|
||||
nodejs-apps:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.node-apps
|
||||
container_name: node-apps
|
||||
# image: node:lts-slim <-- Comment this out
|
||||
...
|
||||
```
|
||||
|
||||
### 3. Integration
|
||||
|
||||
### Update `command`
|
||||
Add the following to your existing command string (append before the final `pm2 logs`):
|
||||
Add the following to your existing command string. We added `npx prisma generate` explicitly to ensure the Linux client is built correctly, and we ensure `DATABASE_URL` is consistent:
|
||||
|
||||
```bash
|
||||
... && cd ../gymflow/server && npm install --omit=dev && DATABASE_URL=file:./prod.db npx prisma db push && cd .. && pm2 start ecosystem.config.cjs && ...
|
||||
... && cd ../gymflow/server && npm install --omit=dev && APP_MODE=prod DATABASE_URL=file:./prod.db npx prisma generate && APP_MODE=prod DATABASE_URL=file:./prod.db npx prisma db push && cd .. && pm2 start ecosystem.config.cjs && ...
|
||||
```
|
||||
*Note: We assume `gymflow` is a sibling of `ag-beats` etc.*
|
||||
|
||||
**Full Command Example:**
|
||||
```yaml
|
||||
command: /bin/sh -c "npm install -g pm2 && cd ag-beats && npm install && cd ../ball-shooting && npm install && cd ../gymflow/server && npm install --omit=dev && DATABASE_URL=file:./prod.db npx prisma db push && cd .. && pm2 start ecosystem.config.cjs && cd ../ag-beats && pm2 start ecosystem.config.js && cd ../ball-shooting && pm2 start npm --name ag-ball -- start && pm2 logs --raw"
|
||||
command: /bin/sh -c "npm install -g pm2 && cd ag-beats && npm install && cd ../ball-shooting && npm install && cd ../gymflow/server && npm install --omit=dev && APP_MODE=prod DATABASE_URL=file:./prod.db npx prisma generate && APP_MODE=prod DATABASE_URL=file:./prod.db npx prisma db push && cd .. && pm2 start ecosystem.config.cjs && cd ../ag-beats && pm2 start ecosystem.config.js && cd ../ball-shooting && pm2 start npm --name ag-ball -- start && pm2 logs --raw"
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Since we updated the `Dockerfile.node-apps` to include `openssl` (required by Prisma), you **must** rebuild the image:
|
||||
> `docker-compose up -d --build nodejs-apps`
|
||||
|
||||
### Update `ports`
|
||||
Add the GymFlow port (3003 inside container, mapped to your choice, e.g., 3033):
|
||||
```yaml
|
||||
@@ -64,12 +95,45 @@ ports:
|
||||
- "3033:3003" # GymFlow
|
||||
```
|
||||
|
||||
## 4. Environment Variables
|
||||
## 4. Unified Ecosystem Config
|
||||
Your common `ecosystem.config.js` should look like this to ensure GymFlow has the correct production environment:
|
||||
|
||||
GymFlow uses `dotenv` but in this setup PM2 handles the variables via `ecosystem.config.cjs`.
|
||||
- Port: `3003` (Internal)
|
||||
- Database: `server/prod.db` (SQLite)
|
||||
- Node Env: `production`
|
||||
```javascript
|
||||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
name: "ag-home",
|
||||
script: "server.js",
|
||||
cwd: "/usr/src/app",
|
||||
exec_mode: "fork",
|
||||
},
|
||||
{
|
||||
name: "ag-beats",
|
||||
script: "npm",
|
||||
args: "start",
|
||||
cwd: "/usr/src/app/ag-beats",
|
||||
},
|
||||
{
|
||||
name: "ag-ball",
|
||||
script: "npm",
|
||||
args: "start",
|
||||
cwd: "/usr/src/app/ball-shooting",
|
||||
},
|
||||
{
|
||||
name: "gymflow",
|
||||
script: "dist/index.js",
|
||||
cwd: "/usr/src/app/gymflow/server",
|
||||
env: {
|
||||
NODE_ENV: "production",
|
||||
APP_MODE: "prod",
|
||||
PORT: 3003,
|
||||
DATABASE_URL: "file:./prod.db",
|
||||
DATABASE_URL_PROD: "file:./prod.db"
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
```
|
||||
|
||||
## 5. Nginx Proxy Manager
|
||||
|
||||
|
||||
Reference in New Issue
Block a user