From 652e0b205cd9856bb8920136927cdb55f48d9217 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Tue, 18 Mar 2025 13:34:30 -0700 Subject: [PATCH] fix[docker]: fixed devcontainer to match new file structure --- .devcontainer/.bashrc | 2 +- .devcontainer/Dockerfile | 24 ++++++------------------ .devcontainer/devcontainer.json | 3 --- .devcontainer/docker-compose.yml | 28 ++++++++++++++++++---------- .devcontainer/post-create.sh | 13 ++++++++----- Dockerfile | 9 +++++++++ README.md | 4 ++-- docker-compose.yml | 6 +++--- sim/.env.example | 6 +++--- 9 files changed, 50 insertions(+), 45 deletions(-) diff --git a/.devcontainer/.bashrc b/.devcontainer/.bashrc index 4dec58022..705d31fbb 100644 --- a/.devcontainer/.bashrc +++ b/.devcontainer/.bashrc @@ -14,7 +14,7 @@ alias ..="cd .." alias ...="cd ../.." # Database aliases -alias pgc="PGPASSWORD=postgres psql -h db -U postgres -d postgres" +alias pgc="PGPASSWORD=postgres psql -h db -U postgres -d simstudio" alias check-db="PGPASSWORD=postgres psql -h db -U postgres -c '\l'" # Sim Studio specific aliases diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 2697cc46b..dd485c55c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,15 +3,10 @@ FROM node:20-bullseye # Avoid warnings by switching to noninteractive ENV DEBIAN_FRONTEND=noninteractive -# Configure apt and install packages +# Install necessary packages for development RUN apt-get update \ - && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ - # Install git, process tools, lsb-release - && apt-get -y install git procps lsb-release \ - # Install other dependencies - && apt-get -y install curl wget jq sudo \ - # Clean up - && apt-get autoremove -y \ + && apt-get -y install --no-install-recommends \ + git curl wget jq sudo postgresql-client \ && apt-get clean -y \ && rm -rf /var/lib/apt/lists/* @@ -20,10 +15,8 @@ ARG USERNAME=node ARG USER_UID=1000 ARG USER_GID=$USER_UID -# [Optional] Add sudo support -RUN apt-get update \ - && apt-get install -y sudo \ - && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ +# Add sudo support +RUN echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USERNAME \ && chmod 0440 /etc/sudoers.d/$USERNAME # Make sure we have the latest npm @@ -32,15 +25,10 @@ RUN npm install -g npm@latest # Install global packages RUN npm install -g drizzle-kit -# Install dependencies for Postgres client -RUN apt-get update && apt-get -y install --no-install-recommends \ - postgresql-client \ - && rm -rf /var/lib/apt/lists/* - # Switch back to dialog for any ad-hoc use of apt-get ENV DEBIAN_FRONTEND=dialog WORKDIR /workspace # Expose the ports we're interested in -EXPOSE 3000 \ No newline at end of file +EXPOSE 3000 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4a8758e37..e50f506cf 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -52,9 +52,6 @@ "remoteUser": "node", "features": { - "ghcr.io/devcontainers/features/node:1": { - "version": "20" - }, "ghcr.io/devcontainers/features/git:1": {}, "ghcr.io/devcontainers-contrib/features/npm-package:1": { "package": "typescript", diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 2e540c375..feca73626 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -9,26 +9,34 @@ services: - ..:/workspace:cached command: sleep infinity environment: - - DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres - - NEXT_PUBLIC_SUPABASE_URL=${NEXT_PUBLIC_SUPABASE_URL:-http://db:5432} - - NEXT_PUBLIC_SUPABASE_ANON_KEY=${NEXT_PUBLIC_SUPABASE_ANON_KEY:-your-anon-key} + - 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 - network_mode: service:db + db: + condition: service_healthy + ports: + - "3000:3000" working_dir: /workspace/sim db: - image: postgres:14 + image: postgres:16 restart: unless-stopped volumes: - postgres-data:/var/lib/postgresql/data environment: - POSTGRES_PASSWORD: postgres - POSTGRES_USER: postgres - POSTGRES_DB: postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=simstudio ports: - "5432:5432" - - "3000:3000" + 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/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index 08090e58e..71c4d0a90 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -29,11 +29,14 @@ npm install || { # Set up environment variables if .env doesn't exist if [ ! -f ".env" ]; then echo "📄 Creating .env file from template..." - cp .env.example .env 2>/dev/null || echo "DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres" > .env + cp .env.example .env 2>/dev/null || echo "DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio" > .env fi -# Run database migrations -echo "🗃️ Running database migrations..." +# Generate schema and run database migrations +echo "🗃️ Running database schema generation and migrations..." +echo "Generating schema..." +npx drizzle-kit generate + echo "Waiting for database to be ready..." # Try to connect to the database, but don't fail the script if it doesn't work ( @@ -41,7 +44,7 @@ echo "Waiting for database to be ready..." while [ $timeout -gt 0 ]; do if PGPASSWORD=postgres psql -h db -U postgres -c '\q' 2>/dev/null; then echo "Database is ready!" - npx drizzle-kit push + DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio npx drizzle-kit push break fi echo "Database is unavailable - sleeping (${timeout}s remaining)" @@ -58,7 +61,7 @@ echo "Waiting for database to be ready..." cat << EOF >> ~/.bashrc # Additional Sim Studio Development Aliases -alias migrate="cd /workspace/sim && npx drizzle-kit push" +alias migrate="cd /workspace/sim && DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio npx drizzle-kit push" alias generate="cd /workspace/sim && npx drizzle-kit generate" alias dev="cd /workspace/sim && npm run dev" alias build="cd /workspace/sim && npm run build" diff --git a/Dockerfile b/Dockerfile index 8118cf3f8..47a8c5809 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,16 @@ COPY sim/ ./ # Install dependencies RUN npm install +# Generate database schema +RUN npx drizzle-kit generate + EXPOSE 3000 +# Create a startup script that will run migrations and then start the app +RUN echo '#!/bin/sh\nnpx drizzle-kit push\nexec "$@"' > /app/docker-entrypoint.sh && \ + chmod +x /app/docker-entrypoint.sh + +ENTRYPOINT ["/app/docker-entrypoint.sh"] + # Default to development mode CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/README.md b/README.md index a8c78846e..c65c49b04 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ There are several ways to self-host Sim Studio: git clone https://github.com/YOUR_USERNAME/sim.git cd sim -# Create environment file +# Create environment file and update with required environment variables (BETTER_AUTH_SECRET) cp sim/.env.example sim/.env # Start the Docker environment @@ -140,4 +140,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file ## -

Made with ❤️ by the Sim Studio Team

+

Made with ❤️ by the Sim Studio Team

\ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 98c2aa9c7..d803306a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,11 +18,11 @@ services: - BETTER_AUTH_URL=http://localhost:3000 - NEXT_PUBLIC_APP_URL=http://localhost:3000 depends_on: - - db - command: npm run dev + db: + condition: service_healthy db: - image: postgres:16-alpine + image: postgres:16 restart: always ports: - "5432:5432" diff --git a/sim/.env.example b/sim/.env.example index e04f9e65c..02b639ba5 100644 --- a/sim/.env.example +++ b/sim/.env.example @@ -5,12 +5,12 @@ DATABASE_URL="postgresql://postgres:password@localhost:5432/postgres" BETTER_AUTH_SECRET=your_secret_key # Use `openssl rand -hex 32` to generate, or visit https://www.better-auth.com/docs/installation BETTER_AUTH_URL=http://localhost:3000 +## Security (Required) +ENCRYPTION_KEY=your_encryption_key # Use `openssl rand -hex 64` to generate + # Email Provider (Optional) # RESEND_API_KEY= # Uncomment and add your key from https://resend.com to send actual emails # If left commented out, emails will be logged to console instead -# App URL (Required) -NEXT_PUBLIC_APP_URL=http://localhost:3000 - # StackBlitz (Webcontainer) API Key (Optional, for handling sandboxed code execution for functions/custom-tools) # WEBCONTAINER_CLIENT_ID= # Uncomment and add your key from https://stackblitz.com/docs/webcontainer-api#webcontainer-client-id \ No newline at end of file