update: generalize docker deployment

This commit is contained in:
2025-12-21 16:14:46 +01:00
parent 7453c356bb
commit 0b1e2b8dd3
5 changed files with 24 additions and 135 deletions

3
.gitignore vendored
View File

@@ -24,3 +24,6 @@ vite.config.ts.timestamp-*
# Claude
.claude
# Infisical
.infisical*

View File

@@ -1,84 +0,0 @@
# Coolify Deployment
## Prerequisites
- Coolify instance
- Git repository
## Database Setup
Choose one:
**Option A: Docker Compose (Recommended)**
- Database included in `docker-compose.coolify.yml`
- Skip to step 2
**Option B: Separate PostgreSQL Resource**
1. Create PostgreSQL database in Coolify
2. Note connection details
## Deploy
### Using Docker Compose (Recommended)
1. Create application in Coolify
2. Select Git repository
3. Configure:
- Build Pack: Docker Compose
- File: `./docker-compose.coolify.yml`
4. Assign domain to `app` service only (format: `http://yourdomain.com:3000`)
5. Set environment variables:
- `AUTH_SECRET` (generate with `openssl rand -base64 32`)
- `AUTH_URL` (your domain with https)
- `POSTGRES_DATA_PATH` (optional, for custom database storage location)
- `GOOGLE_CLIENT_ID` (optional)
- `GOOGLE_CLIENT_SECRET` (optional)
6. Deploy
### Using Dockerfile
1. Create application in Coolify
2. Select Git repository
3. Configure:
- Build Pack: Docker
- Port: `3000`
4. Add domain
5. Set environment variables:
- `DATABASE_URL`
- `AUTH_SECRET` (generate with `openssl rand -base64 32`)
- `AUTH_URL` (your domain with https)
- `GOOGLE_CLIENT_ID` (optional)
- `GOOGLE_CLIENT_SECRET` (optional)
6. Deploy
## After Deployment
Run migrations:
```bash
# In Coolify terminal or SSH
docker exec -it <container-name> bun run db:push
```
## Environment Variables
Required:
- `DATABASE_URL` - Connection string
- `AUTH_SECRET` - Random secret
- `AUTH_URL` - Your app URL
- `AUTH_TRUST_HOST` - `true`
Optional:
- `GOOGLE_CLIENT_ID`
- `GOOGLE_CLIENT_SECRET`
- `POSTGRES_DATA_PATH` - Custom path for PostgreSQL data (Docker Compose only)
- Example: `/mnt/storage/wishlist/postgres`
- If not set, uses a Docker named volume
- Path must exist with proper permissions before deployment
## Troubleshooting
**Container crashes:** Check logs in Coolify dashboard
**Database connection:** Verify `DATABASE_URL` format
**Auth issues:** Check `AUTH_URL` matches your domain

View File

@@ -1,51 +0,0 @@
# Coolify-optimized Docker Compose
# Includes both app and database - database is only exposed internally
services:
db:
image: postgres:16-alpine
environment:
POSTGRES_USER: ${POSTGRES_USER:-wishlistuser}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-wishlistpassword}
POSTGRES_DB: ${POSTGRES_DB:-wishlist}
volumes:
- type: bind
source: ${POSTGRES_DATA_PATH}
target: /var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-wishlistuser} -d ${POSTGRES_DB:-wishlist}"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
# NOTE: No ports exposed - only accessible internally by app service
app:
build:
context: .
dockerfile: Dockerfile
environment:
# Coolify will inject these from Environment Variables
DATABASE_URL: postgresql://${POSTGRES_USER:-wishlistuser}:${POSTGRES_PASSWORD:-wishlistpassword}@db:5432/${POSTGRES_DB:-wishlist}
NODE_ENV: production
PORT: 3000
AUTH_SECRET: ${AUTH_SECRET}
AUTH_URL: ${AUTH_URL:-https://wish.rasmusq.com}
AUTH_TRUST_HOST: ${AUTH_TRUST_HOST:-true}
GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID:-}
GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET:-}
depends_on:
db:
condition: service_healthy
restart: unless-stopped
labels:
- traefik.enable=true
- traefik.http.routers.wishlist.rule=Host(`wish.rasmusq.com`)
- traefik.http.routers.wishlist.entryPoints=https
- traefik.http.routers.wishlist.tls=true
- traefik.http.routers.wishlist.tls.certresolver=letsencrypt
- traefik.http.services.wishlist.loadbalancer.server.port=3000
# Forward headers for Auth.js behind reverse proxy
- traefik.http.middlewares.wishlist-headers.headers.customrequestheaders.X-Forwarded-Proto=https
- traefik.http.middlewares.wishlist-headers.headers.customrequestheaders.X-Forwarded-Host=wish.rasmusq.com
- traefik.http.routers.wishlist.middlewares=wishlist-headers

21
docker-compose.dev.yml Normal file
View File

@@ -0,0 +1,21 @@
services:
database:
image: postgres:16-alpine
container_name: wishlist-postgres-test
restart: unless-stopped
ports:
- 5432:5432
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- db-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
volumes:
db-data: