diff --git a/.env.compose b/.env.compose new file mode 100644 index 0000000..5846b95 --- /dev/null +++ b/.env.compose @@ -0,0 +1,14 @@ +# Copy this file and fill in your values before deploying: +# cp .env.compose .env.compose.local +# +# Then run: +# docker compose --env-file .env.compose.local up -d --build + +# URL your browser (and the SSR server) uses to reach the API. +# LAN example: http://192.168.1.100:8000 +# Reverse proxy: https://pocketchords.yourdomain.com/api +VITE_API_URL=http://localhost:8000 + +# Host ports (change if something else is already using them) +API_PORT=8000 +APP_PORT=3000 diff --git a/app/Dockerfile b/app/Dockerfile index 207bf93..16edc48 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -12,6 +12,9 @@ FROM node:20-alpine AS build-env COPY . /app/ COPY --from=development-dependencies-env /app/node_modules /app/node_modules WORKDIR /app +# VITE_API_URL is baked into the bundle at build time (both SSR and client use it) +ARG VITE_API_URL=http://localhost:8000 +ENV VITE_API_URL=$VITE_API_URL RUN npm run build FROM node:20-alpine diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b4638dc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,41 @@ +# PocketChords – homeserver deployment template +# +# Usage: +# cp .env.compose .env.compose.local # fill in your values +# docker compose --env-file .env.compose.local up -d --build +# +# VITE_API_URL is baked into the JS bundle at build time. +# Set it to the URL your BROWSER (and SSR server) will use to reach the API. +# On a LAN homeserver: http://192.168.x.x:8000 +# Behind a reverse proxy: https://pocketchords.example.com/api + +services: + api: + build: + context: . + dockerfile: Dockerfile + restart: unless-stopped + ports: + - "${API_PORT:-8000}:8000" + environment: + DATABASE_URL: sqlite:///app/data/pocket-chords.db + volumes: + - api-data:/app/data + + app: + build: + context: ./app + dockerfile: Dockerfile + args: + VITE_API_URL: ${VITE_API_URL:-http://localhost:8000} + restart: unless-stopped + ports: + - "${APP_PORT:-3000}:3000" + environment: + PORT: 3000 + depends_on: + - api + +volumes: + api-data: + driver: local