feat: update Docker setup and documentation for PostgreSQL integration
This commit is contained in:
1 parent
f56eac28f7
commit
14a7348632
7 files changed
+46
-130
No files matched your search
@@ -7,7 +7,6 @@ dist
|
|||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
README.md
|
README.md
|
||||||
docker-compose.yml
|
|
||||||
Dockerfile
|
Dockerfile
|
||||||
data/
|
data/
|
||||||
collabtable.db
|
collabtable.db
|
||||||
@@ -9,18 +9,11 @@ COOKIE_SECURE=false
|
|||||||
|
|
||||||
#################################################################
|
#################################################################
|
||||||
# PostgreSQL configuration
|
# PostgreSQL configuration
|
||||||
# You can either provide a single DATABASE_URL or the PG* variables below
|
|
||||||
#################################################################
|
#################################################################
|
||||||
# Example URL: postgres://user:password@localhost:5432/collabtable
|
# Postgres connection string (bring your own - this app does not run Postgres for you).
|
||||||
|
# Example: postgres://user:password@localhost:5432/collabtable
|
||||||
DATABASE_URL=
|
DATABASE_URL=
|
||||||
|
|
||||||
# If DATABASE_URL is not set, these individual settings are used:
|
|
||||||
PGHOST=localhost
|
|
||||||
PGPORT=5432
|
|
||||||
PGUSER=postgres
|
|
||||||
PGPASSWORD=
|
|
||||||
PGDATABASE=collabtable
|
|
||||||
|
|
||||||
#################################################################
|
#################################################################
|
||||||
# Startup resilience and sync tuning
|
# Startup resilience and sync tuning
|
||||||
#################################################################
|
#################################################################
|
||||||
|
|||||||
+17
-26
@@ -9,12 +9,12 @@ A collaborative table management server built with Node.js, Express, TypeScript,
|
|||||||
- PostgreSQL (pg) database backend
|
- PostgreSQL (pg) database backend
|
||||||
- Single-admin-account web dashboard login (session cookie, bcrypt-hashed password) plus a
|
- Single-admin-account web dashboard login (session cookie, bcrypt-hashed password) plus a
|
||||||
long-lived API token for sync clients/devices, generated from the dashboard
|
long-lived API token for sync clients/devices, generated from the dashboard
|
||||||
- Dockerized deployment with persistent storage
|
- Dockerized deployment (bring your own PostgreSQL instance)
|
||||||
- TypeScript for type safety
|
- TypeScript for type safety
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
- Docker and Docker Compose
|
- Docker and a PostgreSQL instance (bring your own - this app does not run Postgres for you)
|
||||||
- Or Node.js 20+ and a PostgreSQL instance (for local development)
|
- Or Node.js 20+ and a PostgreSQL instance (for local development)
|
||||||
|
|
||||||
## Quick Start with Docker
|
## Quick Start with Docker
|
||||||
@@ -25,14 +25,18 @@ A collaborative table management server built with Node.js, Express, TypeScript,
|
|||||||
cd CollabTableServer
|
cd CollabTableServer
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Copy the example environment file:
|
3. Build the image:
|
||||||
```bash
|
```bash
|
||||||
cp .env.example .env
|
docker build -t collabtable-server .
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Start the services (this also starts a bundled PostgreSQL container):
|
4. Run it, pointing at your own Postgres instance:
|
||||||
```bash
|
```bash
|
||||||
docker-compose up -d
|
docker run -d --name collabtable-server --restart unless-stopped \
|
||||||
|
-p 3000:3000 \
|
||||||
|
-e DATABASE_URL=postgres://user:password@host:5432/collabtable \
|
||||||
|
-e COOKIE_SECURE=false \
|
||||||
|
collabtable-server
|
||||||
```
|
```
|
||||||
|
|
||||||
The server will be available at `http://localhost:3000`. Open it in a browser to create the
|
The server will be available at `http://localhost:3000`. Open it in a browser to create the
|
||||||
@@ -53,12 +57,6 @@ admin account, then generate an API token from the dashboard for your sync clien
|
|||||||
3. Point it at a PostgreSQL instance in `.env`:
|
3. Point it at a PostgreSQL instance in `.env`:
|
||||||
```
|
```
|
||||||
DATABASE_URL=postgres://user:password@localhost:5432/collabtable
|
DATABASE_URL=postgres://user:password@localhost:5432/collabtable
|
||||||
# OR, as discrete variables:
|
|
||||||
# PGHOST=localhost
|
|
||||||
# PGPORT=5432
|
|
||||||
# PGUSER=postgres
|
|
||||||
# PGPASSWORD=yourpassword
|
|
||||||
# PGDATABASE=collabtable
|
|
||||||
|
|
||||||
# Set to "true" once served over HTTPS
|
# Set to "true" once served over HTTPS
|
||||||
COOKIE_SECURE=false
|
COOKIE_SECURE=false
|
||||||
@@ -199,24 +197,19 @@ npm start
|
|||||||
|
|
||||||
## Docker Commands
|
## Docker Commands
|
||||||
|
|
||||||
Start services:
|
Stop the container:
|
||||||
```bash
|
```bash
|
||||||
docker-compose up -d
|
docker stop collabtable-server
|
||||||
```
|
|
||||||
|
|
||||||
Stop services:
|
|
||||||
```bash
|
|
||||||
docker-compose down
|
|
||||||
```
|
```
|
||||||
|
|
||||||
View logs:
|
View logs:
|
||||||
```bash
|
```bash
|
||||||
docker-compose logs -f
|
docker logs -f collabtable-server
|
||||||
```
|
```
|
||||||
|
|
||||||
Rebuild and restart:
|
Rebuild and restart:
|
||||||
```bash
|
```bash
|
||||||
docker-compose up -d --build
|
docker build -t collabtable-server . && docker restart collabtable-server
|
||||||
```
|
```
|
||||||
|
|
||||||
## Environment Variables
|
## Environment Variables
|
||||||
@@ -224,8 +217,7 @@ docker-compose up -d --build
|
|||||||
- `PORT` - Server port (default: 3000)
|
- `PORT` - Server port (default: 3000)
|
||||||
- `NODE_ENV` - Environment (development/production)
|
- `NODE_ENV` - Environment (development/production)
|
||||||
- `COOKIE_SECURE` - Set to `true` to mark the admin session cookie `Secure` (requires HTTPS); default `false`
|
- `COOKIE_SECURE` - Set to `true` to mark the admin session cookie `Secure` (requires HTTPS); default `false`
|
||||||
- `DATABASE_URL` - PostgreSQL connection URL (optional alternative to PG* variables)
|
- `DATABASE_URL` - PostgreSQL connection URL (required; bring your own Postgres instance)
|
||||||
- `PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD`, `PGDATABASE` - PostgreSQL connection parameters
|
|
||||||
- `DB_INIT_RETRY_INTERVAL_MS` - Delay between DB init retries in ms (default: `5000`)
|
- `DB_INIT_RETRY_INTERVAL_MS` - Delay between DB init retries in ms (default: `5000`)
|
||||||
- `DB_INIT_RETRY_MAX_ATTEMPTS` - Max DB init retries; `0` retries forever (default: `0`)
|
- `DB_INIT_RETRY_MAX_ATTEMPTS` - Max DB init retries; `0` retries forever (default: `0`)
|
||||||
- `SYNC_MAX_FUTURE_SKEW_MS` - Allowed future timestamp skew from clients during sync (default: `0`)
|
- `SYNC_MAX_FUTURE_SKEW_MS` - Allowed future timestamp skew from clients during sync (default: `0`)
|
||||||
@@ -245,9 +237,8 @@ when left unset.
|
|||||||
|
|
||||||
## Data Persistence
|
## Data Persistence
|
||||||
|
|
||||||
Use your normal PostgreSQL backup/restore procedures (e.g., `pg_dump`, `pg_restore`). If
|
Use your normal PostgreSQL backup/restore procedures (e.g., `pg_dump`, `pg_restore`) against
|
||||||
using the bundled Dockerized Postgres service, the data is stored in a named volume (see
|
your own Postgres instance - this app does not manage Postgres storage itself.
|
||||||
`docker-compose.yml`).
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
version: '3.8'
|
|
||||||
|
|
||||||
services:
|
|
||||||
postgres:
|
|
||||||
image: postgres:17-alpine
|
|
||||||
container_name: collabtable-postgres
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
- POSTGRES_DB=collabtable
|
|
||||||
- POSTGRES_USER=collabtable
|
|
||||||
- POSTGRES_PASSWORD=collabtable
|
|
||||||
volumes:
|
|
||||||
- pg_data:/var/lib/postgresql/data
|
|
||||||
networks:
|
|
||||||
- collabtable-network
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD-SHELL", "pg_isready -U collabtable"]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
|
|
||||||
server:
|
|
||||||
build: .
|
|
||||||
container_name: collabtable-server
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
- PORT=3000
|
|
||||||
- NODE_ENV=production
|
|
||||||
# Session cookie for the admin web dashboard (see src/routes/authRoutes.ts)
|
|
||||||
- COOKIE_SECURE=false
|
|
||||||
# Retry DB initialization instead of crashing immediately on startup races
|
|
||||||
- DB_INIT_RETRY_INTERVAL_MS=5000
|
|
||||||
- DB_INIT_RETRY_MAX_ATTEMPTS=0
|
|
||||||
# Clamp future client timestamps during sync to avoid resend loops
|
|
||||||
- SYNC_MAX_FUTURE_SKEW_MS=0
|
|
||||||
- DATABASE_URL=postgres://collabtable:collabtable@postgres:5432/collabtable
|
|
||||||
ports:
|
|
||||||
- "3000:3000"
|
|
||||||
depends_on:
|
|
||||||
postgres:
|
|
||||||
condition: service_healthy
|
|
||||||
networks:
|
|
||||||
- collabtable-network
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
pg_data:
|
|
||||||
|
|
||||||
networks:
|
|
||||||
collabtable-network:
|
|
||||||
driver: bridge
|
|
||||||
@@ -36,17 +36,10 @@ class PostgresAdapter implements DBAdapter {
|
|||||||
// OID 20 = INT8, OID 1700 = NUMERIC (keep default for now)
|
// OID 20 = INT8, OID 1700 = NUMERIC (keep default for now)
|
||||||
pgTypes.setTypeParser(20, (val: string) => parseInt(val, 10));
|
pgTypes.setTypeParser(20, (val: string) => parseInt(val, 10));
|
||||||
const connectionString = process.env.DATABASE_URL;
|
const connectionString = process.env.DATABASE_URL;
|
||||||
if (connectionString) {
|
if (!connectionString) {
|
||||||
this.pool = new Pool({ connectionString });
|
throw new Error('DATABASE_URL environment variable is required');
|
||||||
} else {
|
|
||||||
this.pool = new Pool({
|
|
||||||
host: process.env.PGHOST || 'localhost',
|
|
||||||
port: parseInt(process.env.PGPORT || '5432', 10),
|
|
||||||
user: process.env.PGUSER || 'postgres',
|
|
||||||
password: process.env.PGPASSWORD || '',
|
|
||||||
database: process.env.PGDATABASE || 'collabtable'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
this.pool = new Pool({ connectionString });
|
||||||
}
|
}
|
||||||
|
|
||||||
async initialize(): Promise<void> {
|
async initialize(): Promise<void> {
|
||||||
|
|||||||
@@ -102,8 +102,7 @@ app.use('/', webRoutes);
|
|||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`Server is running on port ${PORT}`);
|
console.log(`Server is running on port ${PORT}`);
|
||||||
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`);
|
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`);
|
||||||
const source = process.env.DATABASE_URL ? 'DATABASE_URL' : 'PGHOST/PGDATABASE';
|
console.log('Database: PostgreSQL (DATABASE_URL)');
|
||||||
console.log(`Database: PostgreSQL (${source})`);
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Database initialization error:', error);
|
console.error('Database initialization error:', error);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ CollabTable allows multiple users to collaboratively create and manage lists wit
|
|||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
### Server
|
### Server
|
||||||
- **Docker** and **Docker Compose** (recommended)
|
- **Docker** and a PostgreSQL instance (bring your own - this app does not run Postgres for you)
|
||||||
- Or **Node.js 20+** for local development
|
- Or **Node.js 20+** for local development
|
||||||
|
|
||||||
### Android App
|
### Android App
|
||||||
@@ -65,17 +65,20 @@ CollabTable allows multiple users to collaboratively create and manage lists wit
|
|||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **Start the server (this also starts a bundled PostgreSQL container):**
|
3. **Build and run the server, pointing at your own PostgreSQL instance:**
|
||||||
```bash
|
```bash
|
||||||
docker-compose up -d
|
docker build -t collabtable-server .
|
||||||
|
docker run -d --name collabtable-server --restart unless-stopped \
|
||||||
|
-p 3000:3000 \
|
||||||
|
-e DATABASE_URL=postgres://user:password@host:5432/collabtable \
|
||||||
|
collabtable-server
|
||||||
```
|
```
|
||||||
|
|
||||||
Server runs on `http://localhost:3000`. Open it in a browser to create the admin account,
|
Server runs on `http://localhost:3000`. Open it in a browser to create the admin account,
|
||||||
then generate an API token from the dashboard's Settings page for your sync clients/devices
|
then generate an API token from the dashboard's Settings page for your sync clients/devices
|
||||||
— see `CollabTableServer/README.md`'s "Authentication" section for details.
|
— see `CollabTableServer/README.md`'s "Authentication" section for details.
|
||||||
|
|
||||||
**Database:** PostgreSQL, provisioned automatically via the bundled `postgres` service in
|
**Database:** PostgreSQL, bring your own instance via `DATABASE_URL`.
|
||||||
`docker-compose.yml`.
|
|
||||||
|
|
||||||
### Android App
|
### Android App
|
||||||
|
|
||||||
@@ -124,7 +127,6 @@ CollabTable/
|
|||||||
├── webui/ # SvelteKit web dashboard (read-only database viewer)
|
├── webui/ # SvelteKit web dashboard (read-only database viewer)
|
||||||
├── data/ # SQLite database storage
|
├── data/ # SQLite database storage
|
||||||
├── Dockerfile
|
├── Dockerfile
|
||||||
├── docker-compose.yml
|
|
||||||
└── README.md
|
└── README.md
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -340,34 +342,29 @@ The actual value for a specific field of an item:
|
|||||||
```bash
|
```bash
|
||||||
# Find and kill process using port 3000
|
# Find and kill process using port 3000
|
||||||
lsof -ti:3000 | xargs kill -9
|
lsof -ti:3000 | xargs kill -9
|
||||||
# Or change port in docker-compose.yml or .env
|
# Or change the port mapping in your `docker run` command or .env
|
||||||
```
|
```
|
||||||
|
|
||||||
**Docker container won't start**
|
**Docker container won't start**
|
||||||
```bash
|
```bash
|
||||||
# View logs
|
# View logs
|
||||||
docker-compose logs -f
|
docker logs -f collabtable-server
|
||||||
|
|
||||||
# Rebuild container
|
# Rebuild container
|
||||||
docker-compose down
|
docker stop collabtable-server && docker rm collabtable-server
|
||||||
docker-compose up -d --build
|
docker build -t collabtable-server . && docker run -d --name collabtable-server ...
|
||||||
```
|
```
|
||||||
|
|
||||||
**Database connection error (PostgreSQL)**
|
**Database connection error (PostgreSQL)**
|
||||||
- Verify PostgreSQL is running
|
- Verify your PostgreSQL instance is running and reachable from the container
|
||||||
- Check connection details in `.env`
|
- Check `DATABASE_URL` in `.env`
|
||||||
- Ensure database exists
|
- Ensure the database exists
|
||||||
|
|
||||||
**Data not persisting after container restart**
|
|
||||||
- Verify Docker volume exists: `docker volume ls`
|
|
||||||
- Check volume mount in `docker-compose.yml`
|
|
||||||
- For SQLite, data is in `sqlite_data` volume
|
|
||||||
|
|
||||||
### Getting Help
|
### Getting Help
|
||||||
|
|
||||||
- Check the [Android README](CollabTableAndroid/README.md) for app-specific details
|
- Check the [Android README](CollabTableAndroid/README.md) for app-specific details
|
||||||
- Check the [Server README](CollabTableServer/README.md) for server-specific details
|
- Check the [Server README](CollabTableServer/README.md) for server-specific details
|
||||||
- Review Docker logs: `docker-compose logs -f`
|
- Review Docker logs: `docker logs -f collabtable-server`
|
||||||
- Open an issue on GitHub with detailed error messages
|
- Open an issue on GitHub with detailed error messages
|
||||||
|
|
||||||
## Synchronization
|
## Synchronization
|
||||||
@@ -440,30 +437,24 @@ Response:
|
|||||||
### Data Persistence
|
### Data Persistence
|
||||||
|
|
||||||
**PostgreSQL**
|
**PostgreSQL**
|
||||||
- Use standard PostgreSQL backup tools (`pg_dump`, `pg_restore`)
|
- Use standard PostgreSQL backup tools (`pg_dump`, `pg_restore`) against your own instance -
|
||||||
- The bundled `postgres` service's data is stored in a named Docker volume (`pg_data`), which
|
this app does not manage Postgres storage itself
|
||||||
persists across container restarts
|
|
||||||
|
|
||||||
### Docker Commands
|
### Docker Commands
|
||||||
|
|
||||||
**Start services:**
|
**Stop the container:**
|
||||||
```bash
|
```bash
|
||||||
docker-compose up -d
|
docker stop collabtable-server
|
||||||
```
|
|
||||||
|
|
||||||
**Stop services:**
|
|
||||||
```bash
|
|
||||||
docker-compose down
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**View logs:**
|
**View logs:**
|
||||||
```bash
|
```bash
|
||||||
docker-compose logs -f
|
docker logs -f collabtable-server
|
||||||
```
|
```
|
||||||
|
|
||||||
**Rebuild and restart:**
|
**Rebuild and restart:**
|
||||||
```bash
|
```bash
|
||||||
docker-compose up -d --build
|
docker build -t collabtable-server . && docker restart collabtable-server
|
||||||
```
|
```
|
||||||
|
|
||||||
**Check running containers:**
|
**Check running containers:**
|
||||||
@@ -474,7 +465,7 @@ docker ps
|
|||||||
### Production Deployment
|
### Production Deployment
|
||||||
|
|
||||||
**Environment Variables**
|
**Environment Variables**
|
||||||
Configure these in `.env` or docker-compose.yml:
|
Configure these in `.env` or your `docker run` command:
|
||||||
```env
|
```env
|
||||||
PORT=3000 # Server port
|
PORT=3000 # Server port
|
||||||
NODE_ENV=production # Environment
|
NODE_ENV=production # Environment
|
||||||
|
|||||||
Reference in new issue
Block a user