diff --git a/.devcontainer/.bashrc b/.devcontainer/.bashrc index e0637b15d3..e281532264 100644 --- a/.devcontainer/.bashrc +++ b/.devcontainer/.bashrc @@ -24,6 +24,19 @@ 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 +# Welcome message - only show once per session +if [ -z "$SIM_WELCOME_SHOWN" ]; then + export SIM_WELCOME_SHOWN=1 + + echo "" + echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" + echo "๐Ÿš€ Welcome to Sim Studio development environment!" + echo "" + echo "Available commands:" + echo " sim-start - Start the development server" + echo " sim-migrate - Push schema changes to the database" + echo " sim-generate - Generate new migrations" + echo " sim-rebuild - Build and start the production server" + echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" + echo "" +fi \ No newline at end of file diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 003e38aaeb..2697cc46bc 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18-bullseye +FROM node:20-bullseye # Avoid warnings by switching to noninteractive ENV DEBIAN_FRONTEND=noninteractive diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f5de4a5971..e80c8e27c3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -17,7 +17,15 @@ }, "[typescriptreact]": { "editor.defaultFormatter": "esbenp.prettier-vscode" - } + }, + "terminal.integrated.defaultProfile.linux": "bash", + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/bin/bash", + "args": ["--login"] + } + }, + "terminal.integrated.shellIntegration.enabled": true }, "extensions": [ "dbaeumer.vscode-eslint", @@ -36,13 +44,15 @@ "forwardPorts": [3000, 5432], - "postCreateCommand": "sh .devcontainer/post-create.sh", + "postCreateCommand": "bash -c 'bash .devcontainer/post-create.sh || true'", + + "postStartCommand": "bash -c 'if [ ! -f ~/.bashrc ] || ! grep -q \"sim-start\" ~/.bashrc; then cp .devcontainer/.bashrc ~/.bashrc; fi'", "remoteUser": "node", "features": { "ghcr.io/devcontainers/features/node:1": { - "version": "lts" + "version": "20" }, "ghcr.io/devcontainers/features/git:1": {}, "ghcr.io/devcontainers-contrib/features/npm-package:1": { diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index cbae5bb93f..d033433cc0 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -1,12 +1,27 @@ #!/bin/bash +# Exit on error, but with some error handling set -e echo "๐Ÿ”ง Setting up Sim Studio development environment..." -# Install dependencies -echo "๐Ÿ“ฆ Installing npm dependencies..." -npm install +# Setup .bashrc +echo "๐Ÿ“„ Setting up .bashrc with aliases..." +cp .devcontainer/.bashrc ~/.bashrc +# Add to .profile to ensure .bashrc is sourced in non-interactive shells +echo 'if [ -f ~/.bashrc ]; then . ~/.bashrc; fi' >> ~/.profile + +# Clean and reinstall dependencies to ensure platform compatibility +echo "๐Ÿ“ฆ Cleaning and reinstalling npm dependencies..." +if [ -d "node_modules" ]; then + echo "Removing existing node_modules to ensure platform compatibility..." + rm -rf node_modules +fi + +# Install dependencies with platform-specific binaries +npm install || { + echo "โš ๏ธ npm install had issues but continuing setup..." +} # Set up environment variables if .env doesn't exist if [ ! -f ".env" ]; then @@ -17,18 +32,29 @@ 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 +# Try to connect to the database, but don't fail the script if it doesn't work +( + timeout=60 + 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 + break + fi + echo "Database is unavailable - sleeping (${timeout}s remaining)" + sleep 5 + timeout=$((timeout - 5)) + done + + if [ $timeout -le 0 ]; then + echo "โš ๏ธ Database connection timed out, skipping migrations" + fi +) || echo "โš ๏ธ Database setup had issues but continuing..." -echo "Database is ready!" -npx drizzle-kit push - -# Add helpful aliases to .bashrc +# Add additional helpful aliases to .bashrc cat << EOF >> ~/.bashrc -# Sim Studio Development Aliases +# Additional Sim Studio Development Aliases alias migrate="npx drizzle-kit push" alias generate="npx drizzle-kit generate" alias dev="npm run dev" @@ -38,11 +64,22 @@ 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 +# Source the .bashrc to make aliases available immediately +. ~/.bashrc + +# Clear the welcome message flag to ensure it shows after setup +unset SIM_WELCOME_SHOWN + +echo "" +echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" +echo "โœ… Sim Studio development environment setup complete!" +echo "" +echo "Your environment is now ready. A new terminal session will show" +echo "available commands. You can start the development server with:" +echo "" +echo " sim-start" +echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" +echo "" + +# Exit successfully regardless of any previous errors +exit 0 \ No newline at end of file