diff --git a/.devcontainer/.bashrc b/.devcontainer/.bashrc new file mode 100644 index 0000000000..e0637b15d3 --- /dev/null +++ b/.devcontainer/.bashrc @@ -0,0 +1,29 @@ +# Sim Studio Development Environment Bashrc +# This gets sourced by post-create.sh + +# Enhanced prompt with git branch info +parse_git_branch() { + git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' +} + +export PS1="\[\033[01;32m\]\u@simstudio\[\033[00m\]:\[\033[01;34m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\$ " + +# Helpful aliases +alias ll="ls -la" +alias ..="cd .." +alias ...="cd ../.." + +# Database aliases +alias pgc="PGPASSWORD=postgres psql -h db -U postgres -d postgres" +alias check-db="PGPASSWORD=postgres psql -h db -U postgres -c '\l'" + +# Sim Studio specific aliases +alias logs="tail -f logs/*.log 2>/dev/null || echo 'No log files found'" +alias sim-start="npm run dev" +alias sim-migrate="npx drizzle-kit push" +alias sim-generate="npx drizzle-kit generate" +alias sim-rebuild="npm run build && npm start" + +# Welcome message +echo "๐Ÿš€ Welcome to Sim Studio development environment!" +echo "Type 'sim-start' to start the development server" \ No newline at end of file diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..003e38aaeb --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,46 @@ +FROM node:18-bullseye + +# Avoid warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# Configure apt and install packages +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 clean -y \ + && rm -rf /var/lib/apt/lists/* + +# Create a non-root user +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 \ + && chmod 0440 /etc/sudoers.d/$USERNAME + +# Make sure we have the latest npm +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 diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 0000000000..0afc8fb90d --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,78 @@ +# Sim Studio Development Container + +This directory contains configuration files for Visual Studio Code Dev Containers / GitHub Codespaces. Dev containers provide a consistent, isolated development environment for this project. + +## Contents + +- `devcontainer.json` - The main configuration file that defines the development container settings +- `Dockerfile` - Defines the container image and development environment +- `docker-compose.yml` - Sets up the application and database containers +- `post-create.sh` - Script that runs when the container is created +- `.bashrc` - Custom shell configuration with helpful aliases + +## Usage + +### Prerequisites + +- Visual Studio Code +- Docker installation: + - Docker Desktop (Windows/macOS) + - Docker Engine (Linux) +- VS Code Remote - Containers extension + +### Getting Started + +1. Open this project in Visual Studio Code +2. When prompted, click "Reopen in Container" + - Alternatively, press `F1` and select "Remote-Containers: Reopen in Container" +3. Wait for the container to build and initialize +4. The post-creation script will automatically: + + - Install dependencies + - Set up environment variables + - Run database migrations + - Configure helpful aliases + +5. Start the application with `sim-start` (alias for `npm run dev`) + +### Development Commands + +The development environment includes these helpful aliases: + +- `sim-start` - Start the development server +- `sim-migrate` - Push schema changes to the database +- `sim-generate` - Generate new migrations +- `sim-rebuild` - Build and start the production version +- `pgc` - Connect to the PostgreSQL database +- `check-db` - List all databases + +### Using GitHub Codespaces + +This project is also configured for GitHub Codespaces. To use it: + +1. Go to the GitHub repository +2. Click the "Code" button +3. Select the "Codespaces" tab +4. Click "Create codespace on main" + +This will start a new Codespace with the development environment already set up. + +## Customization + +You can customize the development environment by: + +- Modifying `devcontainer.json` to add VS Code extensions or settings +- Updating the `Dockerfile` to install additional packages +- Editing `docker-compose.yml` to add services or change configuration +- Modifying `.bashrc` to add custom aliases or configurations + +## Troubleshooting + +If you encounter issues: + +1. Rebuild the container: `F1` โ†’ "Remote-Containers: Rebuild Container" +2. Check Docker logs for build errors +3. Verify Docker Desktop is running +4. Ensure all prerequisites are installed + +For more information, see the [VS Code Remote Development documentation](https://code.visualstudio.com/docs/remote/containers). diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..f5de4a5971 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,53 @@ +{ + "name": "Sim Studio Dev Environment", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspace", + + "customizations": { + "vscode": { + "settings": { + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + }, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "[typescript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[typescriptreact]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + } + }, + "extensions": [ + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode", + "bradlc.vscode-tailwindcss", + "ms-vscode.vscode-typescript-next", + "github.copilot", + "github.copilot-chat", + "rvest.vs-code-prettier-eslint", + "mikestead.dotenv", + "dsznajder.es7-react-js-snippets", + "steoates.autoimport" + ] + } + }, + + "forwardPorts": [3000, 5432], + + "postCreateCommand": "sh .devcontainer/post-create.sh", + + "remoteUser": "node", + + "features": { + "ghcr.io/devcontainers/features/node:1": { + "version": "lts" + }, + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers-contrib/features/npm-package:1": { + "package": "typescript", + "version": "latest" + } + } +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000000..6b04048271 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,33 @@ +version: '3.8' + +services: + app: + build: + context: .. + dockerfile: .devcontainer/Dockerfile + volumes: + - ..:/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} + depends_on: + - db + network_mode: service:db + + db: + image: postgres:14 + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres + POSTGRES_DB: postgres + ports: + - "5432:5432" + - "3000:3000" + +volumes: + postgres-data: \ No newline at end of file diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh new file mode 100755 index 0000000000..cbae5bb93f --- /dev/null +++ b/.devcontainer/post-create.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +set -e + +echo "๐Ÿ”ง Setting up Sim Studio development environment..." + +# Install dependencies +echo "๐Ÿ“ฆ Installing npm dependencies..." +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 +fi + +# Run database migrations +echo "๐Ÿ—ƒ๏ธ Running database migrations..." +echo "Waiting for database to be ready..." +until PGPASSWORD=postgres psql -h db -U postgres -c '\q'; do + echo "Database is unavailable - sleeping" + sleep 2 +done + +echo "Database is ready!" +npx drizzle-kit push + +# Add helpful aliases to .bashrc +cat << EOF >> ~/.bashrc + +# Sim Studio Development Aliases +alias migrate="npx drizzle-kit push" +alias generate="npx drizzle-kit generate" +alias dev="npm run dev" +alias build="npm run build" +alias start="npm run start" +alias lint="npm run lint" +alias test="npm run test" +EOF + +echo "โœ… Development environment is ready! Here are some helpful commands:" +echo "๐Ÿ“ฆ dev - Start the development server" +echo "๐Ÿ”จ build - Build the application for production" +echo "๐Ÿš€ start - Start the production server" +echo "๐Ÿงน lint - Run ESLint" +echo "๐Ÿงช test - Run tests" +echo "๐Ÿ—ƒ๏ธ migrate - Push schema changes to the database" +echo "๐Ÿ“ƒ generate - Generate new migrations" \ No newline at end of file diff --git a/.dockerignore b/.dockerignore index bb88d29906..b031393514 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,4 +8,5 @@ node_modules .env .env.* npm-debug.log -README.md \ No newline at end of file +README.md +.devcontainer \ No newline at end of file