mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-08 14:43:54 -05:00
feat: added dev container as an option to run & develop sim studio
This commit is contained in:
29
.devcontainer/.bashrc
Normal file
29
.devcontainer/.bashrc
Normal file
@@ -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"
|
||||
46
.devcontainer/Dockerfile
Normal file
46
.devcontainer/Dockerfile
Normal file
@@ -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
|
||||
78
.devcontainer/README.md
Normal file
78
.devcontainer/README.md
Normal file
@@ -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).
|
||||
53
.devcontainer/devcontainer.json
Normal file
53
.devcontainer/devcontainer.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
33
.devcontainer/docker-compose.yml
Normal file
33
.devcontainer/docker-compose.yml
Normal file
@@ -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:
|
||||
48
.devcontainer/post-create.sh
Executable file
48
.devcontainer/post-create.sh
Executable file
@@ -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"
|
||||
@@ -8,4 +8,5 @@ node_modules
|
||||
.env
|
||||
.env.*
|
||||
npm-debug.log
|
||||
README.md
|
||||
README.md
|
||||
.devcontainer
|
||||
Reference in New Issue
Block a user