From 890e380c2cf2874f77cf085de838d5a4b768a879 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Mon, 3 Mar 2025 12:23:29 -0800 Subject: [PATCH] feat(docker): added docker + scripts to get started --- .dockerignore | 11 ++++++++++ Dockerfile | 15 ++++++++++++++ docker-compose.yml | 42 +++++++++++++++++++++++++++++++++++++++ generate_migrations.sh | 7 +++++++ next.config.ts | 1 + start_simstudio_docker.sh | 25 +++++++++++++++++++++++ 6 files changed, 101 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 generate_migrations.sh create mode 100644 start_simstudio_docker.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..bb88d29906 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +# Exclude files from Docker build +.git +.github +node_modules +.next +.vercel +.husky +.env +.env.* +npm-debug.log +README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..5842a68b99 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM node:20-alpine + +WORKDIR /app + +# Copy package files +COPY package.json package-lock.json ./ +RUN npm ci + +# Copy everything else (for build) +COPY . . + +EXPOSE 3000 + +# Default to development mode +CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000..8c5e7c75b1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +version: '3.8' + +services: + simstudio: + build: + context: . + dockerfile: Dockerfile + ports: + - "3000:3000" + volumes: + - .:/app + - /app/node_modules + - /app/.next + environment: + - NODE_ENV=development + - DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio + - POSTGRES_URL=postgresql://postgres:postgres@db:5432/simstudio + - BETTER_AUTH_URL=http://localhost:3000 + - NEXT_PUBLIC_APP_URL=http://localhost:3000 + depends_on: + - db + command: npm run dev + + db: + image: postgres:16-alpine + restart: always + ports: + - "5432:5432" + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=simstudio + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + +volumes: + postgres_data: \ No newline at end of file diff --git a/generate_migrations.sh b/generate_migrations.sh new file mode 100644 index 0000000000..ddf6666bee --- /dev/null +++ b/generate_migrations.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Generate migrations using Drizzle +echo "Generating database migrations..." +docker compose exec simstudio npm run db:push + +echo "Migrations generated successfully." \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index 550afe2efc..08d980ad96 100644 --- a/next.config.ts +++ b/next.config.ts @@ -36,6 +36,7 @@ const nextConfig: NextConfig = { }, ] }, + output: 'standalone', } export default nextConfig diff --git a/start_simstudio_docker.sh b/start_simstudio_docker.sh new file mode 100644 index 0000000000..b361313c7c --- /dev/null +++ b/start_simstudio_docker.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Check if .env file exists, if not, create from example +if [ ! -f .env ]; then + echo "Creating .env file from .env.example..." + cp .env.example .env + echo "Please update .env file with your configuration." +fi + +# Stop any running containers +docker compose down + +# Build and start containers in detached mode +docker compose up --build -d + +# Wait for database to be ready +echo "Waiting for database to be ready..." +sleep 5 + +# Apply migrations automatically +echo "Applying database migrations..." +docker compose exec simstudio npm run db:push + +echo "Sim Studio is now running at http://localhost:3000" +echo "To view logs, run: docker compose logs -f simstudio" \ No newline at end of file