feat: update Docker setup and documentation for PostgreSQL integration
Build & Push Docker Image / Docker Build & Push (push) Successful in 1m32s
Lint / Lint (push) Successful in 11s
Tests / Test (push) Successful in 9s

This commit is contained in:
Gabriel20xx committed 2026-08-01 19:53:32 +02:00
1 parent f56eac28f7
commit 14a7348632
7 files changed
+46 -130

No files matched your search

-1
View File
@@ -7,7 +7,6 @@ dist
.vscode
.idea
README.md
docker-compose.yml
Dockerfile
data/
collabtable.db
+2 -9
View File
@@ -9,18 +9,11 @@ COOKIE_SECURE=false
#################################################################
# 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=
# 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
#################################################################
+17 -26
View File
@@ -9,12 +9,12 @@ A collaborative table management server built with Node.js, Express, TypeScript,
- PostgreSQL (pg) database backend
- 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
- Dockerized deployment with persistent storage
- Dockerized deployment (bring your own PostgreSQL instance)
- TypeScript for type safety
## 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)
## Quick Start with Docker
@@ -25,14 +25,18 @@ A collaborative table management server built with Node.js, Express, TypeScript,
cd CollabTableServer
```
3. Copy the example environment file:
3. Build the image:
```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
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
@@ -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`:
```
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
COOKIE_SECURE=false
@@ -199,24 +197,19 @@ npm start
## Docker Commands
Start services:
Stop the container:
```bash
docker-compose up -d
```
Stop services:
```bash
docker-compose down
docker stop collabtable-server
```
View logs:
```bash
docker-compose logs -f
docker logs -f collabtable-server
```
Rebuild and restart:
```bash
docker-compose up -d --build
docker build -t collabtable-server . && docker restart collabtable-server
```
## Environment Variables
@@ -224,8 +217,7 @@ docker-compose up -d --build
- `PORT` - Server port (default: 3000)
- `NODE_ENV` - Environment (development/production)
- `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)
- `PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD`, `PGDATABASE` - PostgreSQL connection parameters
- `DATABASE_URL` - PostgreSQL connection URL (required; bring your own Postgres instance)
- `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`)
- `SYNC_MAX_FUTURE_SKEW_MS` - Allowed future timestamp skew from clients during sync (default: `0`)
@@ -245,9 +237,8 @@ when left unset.
## Data Persistence
Use your normal PostgreSQL backup/restore procedures (e.g., `pg_dump`, `pg_restore`). If
using the bundled Dockerized Postgres service, the data is stored in a named volume (see
`docker-compose.yml`).
Use your normal PostgreSQL backup/restore procedures (e.g., `pg_dump`, `pg_restore`) against
your own Postgres instance - this app does not manage Postgres storage itself.
## License
-50
View File
@@ -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
+3 -10
View File
@@ -36,17 +36,10 @@ class PostgresAdapter implements DBAdapter {
// OID 20 = INT8, OID 1700 = NUMERIC (keep default for now)
pgTypes.setTypeParser(20, (val: string) => parseInt(val, 10));
const connectionString = process.env.DATABASE_URL;
if (connectionString) {
this.pool = new Pool({ connectionString });
} 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'
});
if (!connectionString) {
throw new Error('DATABASE_URL environment variable is required');
}
this.pool = new Pool({ connectionString });
}
async initialize(): Promise<void> {
+1 -2
View File
@@ -102,8 +102,7 @@ app.use('/', webRoutes);
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`);
const source = process.env.DATABASE_URL ? 'DATABASE_URL' : 'PGHOST/PGDATABASE';
console.log(`Database: PostgreSQL (${source})`);
console.log('Database: PostgreSQL (DATABASE_URL)');
});
} catch (error) {
console.error('Database initialization error:', error);
+23 -32
View File
@@ -42,7 +42,7 @@ CollabTable allows multiple users to collaboratively create and manage lists wit
## Prerequisites
### 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
### Android App
@@ -65,17 +65,20 @@ CollabTable allows multiple users to collaboratively create and manage lists wit
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
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,
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.
**Database:** PostgreSQL, provisioned automatically via the bundled `postgres` service in
`docker-compose.yml`.
**Database:** PostgreSQL, bring your own instance via `DATABASE_URL`.
### Android App
@@ -124,7 +127,6 @@ CollabTable/
├── webui/ # SvelteKit web dashboard (read-only database viewer)
├── data/ # SQLite database storage
├── Dockerfile
├── docker-compose.yml
└── README.md
```
@@ -340,34 +342,29 @@ The actual value for a specific field of an item:
```bash
# Find and kill process using port 3000
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**
```bash
# View logs
docker-compose logs -f
docker logs -f collabtable-server
# Rebuild container
docker-compose down
docker-compose up -d --build
docker stop collabtable-server && docker rm collabtable-server
docker build -t collabtable-server . && docker run -d --name collabtable-server ...
```
**Database connection error (PostgreSQL)**
- Verify PostgreSQL is running
- Check connection details in `.env`
- Ensure 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
- Verify your PostgreSQL instance is running and reachable from the container
- Check `DATABASE_URL` in `.env`
- Ensure the database exists
### Getting Help
- Check the [Android README](CollabTableAndroid/README.md) for app-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
## Synchronization
@@ -440,30 +437,24 @@ Response:
### Data Persistence
**PostgreSQL**
- Use standard PostgreSQL backup tools (`pg_dump`, `pg_restore`)
- The bundled `postgres` service's data is stored in a named Docker volume (`pg_data`), which
persists across container restarts
- Use standard PostgreSQL backup tools (`pg_dump`, `pg_restore`) against your own instance -
this app does not manage Postgres storage itself
### Docker Commands
**Start services:**
**Stop the container:**
```bash
docker-compose up -d
```
**Stop services:**
```bash
docker-compose down
docker stop collabtable-server
```
**View logs:**
```bash
docker-compose logs -f
docker logs -f collabtable-server
```
**Rebuild and restart:**
```bash
docker-compose up -d --build
docker build -t collabtable-server . && docker restart collabtable-server
```
**Check running containers:**
@@ -474,7 +465,7 @@ docker ps
### Production Deployment
**Environment Variables**
Configure these in `.env` or docker-compose.yml:
Configure these in `.env` or your `docker run` command:
```env
PORT=3000 # Server port
NODE_ENV=production # Environment