diff --git a/.env.example b/.env.example index fe49ffad..11024c46 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,12 @@ +POSTGRES_USER=postgres +POSTGRES_PASSWORD=your_password_here +POSTGRES_DB=playmoney + NEXT_PUBLIC_WEB_URL="http://localhost:3000" NEXT_PUBLIC_API_URL="http://localhost:3001" -POSTGRES_PRISMA_URL="postgresql://postgres:password@localhost:5432/playmoney?schema=public" -POSTGRES_URL_NON_POOLING="postgresql://postgres:password@localhost:5432/playmoney?schema=public" +POSTGRES_PRISMA_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?schema=public" +POSTGRES_URL_NON_POOLING="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?schema=public" NEXTAUTH_URL="http://localhost:3000" # See: https://next-auth.js.org/configuration/options#nextauth_secret diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e3c88b59 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:20 + +WORKDIR /app + +RUN apt-get update && apt-get install -y postgresql-client + +COPY . . + +RUN npm install +RUN npm install -g prisma cross-env storybook + +RUN npx prisma generate +RUN npx storybook init + +EXPOSE 3000 3001 5555 6006 +ENTRYPOINT ["./docker-entrypoint.sh"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..deb99768 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,35 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + ports: + - "3000:3000" # Web app + - "3001:3001" # Backend server + - "5555:5555" # Database viewer + - "6006:6006" # Storybook + depends_on: + - db + environment: + - NODE_ENV=development # TODO: allow this to be set in .env & changed? + - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB} + - POSTGRES_HOST=db + volumes: + - .:/app + - /app/node_modules + + db: + image: postgres:16 + ports: + - "5432:5432" + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + volumes: + - postgres_data:/var/lib/postgresql/data + +volumes: + postgres_data: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 00000000..56afeab5 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -xe + +function wait_for_db() { + until pg_isready -h $POSTGRES_HOST -p 5432; do + echo "Waiting for the database to be accessible..." + sleep 2 + done +} + +wait_for_db + +npx prisma migrate dev + +# ignore failures below, probably best to remove this once +# it's clear why HOUSE user isn't being populated by default +npx prisma db seed || true + +npm run dev \ No newline at end of file