fix[docker]: fixed devcontainer to match new file structure

This commit is contained in:
Waleed Latif
2025-03-18 13:34:30 -07:00
parent 4d07eaf541
commit 652e0b205c
9 changed files with 50 additions and 45 deletions

View File

@@ -14,7 +14,7 @@ alias ..="cd .."
alias ...="cd ../.." alias ...="cd ../.."
# Database aliases # 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'" alias check-db="PGPASSWORD=postgres psql -h db -U postgres -c '\l'"
# Sim Studio specific aliases # Sim Studio specific aliases

View File

@@ -3,15 +3,10 @@ FROM node:20-bullseye
# Avoid warnings by switching to noninteractive # Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
# Configure apt and install packages # Install necessary packages for development
RUN apt-get update \ RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ && apt-get -y install --no-install-recommends \
# Install git, process tools, lsb-release git curl wget jq sudo postgresql-client \
&& 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 \ && apt-get clean -y \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
@@ -20,10 +15,8 @@ ARG USERNAME=node
ARG USER_UID=1000 ARG USER_UID=1000
ARG USER_GID=$USER_UID ARG USER_GID=$USER_UID
# [Optional] Add sudo support # Add sudo support
RUN apt-get update \ RUN echo "$USERNAME ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USERNAME \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME && chmod 0440 /etc/sudoers.d/$USERNAME
# Make sure we have the latest npm # Make sure we have the latest npm
@@ -32,15 +25,10 @@ RUN npm install -g npm@latest
# Install global packages # Install global packages
RUN npm install -g drizzle-kit 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 # Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog ENV DEBIAN_FRONTEND=dialog
WORKDIR /workspace WORKDIR /workspace
# Expose the ports we're interested in # Expose the ports we're interested in
EXPOSE 3000 EXPOSE 3000

View File

@@ -52,9 +52,6 @@
"remoteUser": "node", "remoteUser": "node",
"features": { "features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "20"
},
"ghcr.io/devcontainers/features/git:1": {}, "ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers-contrib/features/npm-package:1": { "ghcr.io/devcontainers-contrib/features/npm-package:1": {
"package": "typescript", "package": "typescript",

View File

@@ -9,26 +9,34 @@ services:
- ..:/workspace:cached - ..:/workspace:cached
command: sleep infinity command: sleep infinity
environment: environment:
- DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres - NODE_ENV=development
- NEXT_PUBLIC_SUPABASE_URL=${NEXT_PUBLIC_SUPABASE_URL:-http://db:5432} - DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio
- NEXT_PUBLIC_SUPABASE_ANON_KEY=${NEXT_PUBLIC_SUPABASE_ANON_KEY:-your-anon-key} - POSTGRES_URL=postgresql://postgres:postgres@db:5432/simstudio
- BETTER_AUTH_URL=http://localhost:3000
- NEXT_PUBLIC_APP_URL=http://localhost:3000
depends_on: depends_on:
- db db:
network_mode: service:db condition: service_healthy
ports:
- "3000:3000"
working_dir: /workspace/sim working_dir: /workspace/sim
db: db:
image: postgres:14 image: postgres:16
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- postgres-data:/var/lib/postgresql/data - postgres-data:/var/lib/postgresql/data
environment: environment:
POSTGRES_PASSWORD: postgres - POSTGRES_USER=postgres
POSTGRES_USER: postgres - POSTGRES_PASSWORD=postgres
POSTGRES_DB: postgres - POSTGRES_DB=simstudio
ports: ports:
- "5432:5432" - "5432:5432"
- "3000:3000" healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
volumes: volumes:
postgres-data: postgres-data:

View File

@@ -29,11 +29,14 @@ npm install || {
# Set up environment variables if .env doesn't exist # Set up environment variables if .env doesn't exist
if [ ! -f ".env" ]; then if [ ! -f ".env" ]; then
echo "📄 Creating .env file from template..." 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 fi
# Run database migrations # Generate schema and run database migrations
echo "🗃️ Running database migrations..." echo "🗃️ Running database schema generation and migrations..."
echo "Generating schema..."
npx drizzle-kit generate
echo "Waiting for database to be ready..." echo "Waiting for database to be ready..."
# Try to connect to the database, but don't fail the script if it doesn't work # 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 while [ $timeout -gt 0 ]; do
if PGPASSWORD=postgres psql -h db -U postgres -c '\q' 2>/dev/null; then if PGPASSWORD=postgres psql -h db -U postgres -c '\q' 2>/dev/null; then
echo "Database is ready!" echo "Database is ready!"
npx drizzle-kit push DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio npx drizzle-kit push
break break
fi fi
echo "Database is unavailable - sleeping (${timeout}s remaining)" echo "Database is unavailable - sleeping (${timeout}s remaining)"
@@ -58,7 +61,7 @@ echo "Waiting for database to be ready..."
cat << EOF >> ~/.bashrc cat << EOF >> ~/.bashrc
# Additional Sim Studio Development Aliases # 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 generate="cd /workspace/sim && npx drizzle-kit generate"
alias dev="cd /workspace/sim && npm run dev" alias dev="cd /workspace/sim && npm run dev"
alias build="cd /workspace/sim && npm run build" alias build="cd /workspace/sim && npm run build"

View File

@@ -9,7 +9,16 @@ COPY sim/ ./
# Install dependencies # Install dependencies
RUN npm install RUN npm install
# Generate database schema
RUN npx drizzle-kit generate
EXPOSE 3000 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 # Default to development mode
CMD ["npm", "run", "dev"] CMD ["npm", "run", "dev"]

View File

@@ -36,7 +36,7 @@ There are several ways to self-host Sim Studio:
git clone https://github.com/YOUR_USERNAME/sim.git git clone https://github.com/YOUR_USERNAME/sim.git
cd sim cd sim
# Create environment file # Create environment file and update with required environment variables (BETTER_AUTH_SECRET)
cp sim/.env.example sim/.env cp sim/.env.example sim/.env
# Start the Docker environment # Start the Docker environment
@@ -140,4 +140,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
## ##
<p align="center">Made with ❤️ by the Sim Studio Team</p> <p align="center">Made with ❤️ by the Sim Studio Team</p>

View File

@@ -18,11 +18,11 @@ services:
- BETTER_AUTH_URL=http://localhost:3000 - BETTER_AUTH_URL=http://localhost:3000
- NEXT_PUBLIC_APP_URL=http://localhost:3000 - NEXT_PUBLIC_APP_URL=http://localhost:3000
depends_on: depends_on:
- db db:
command: npm run dev condition: service_healthy
db: db:
image: postgres:16-alpine image: postgres:16
restart: always restart: always
ports: ports:
- "5432:5432" - "5432:5432"

View File

@@ -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_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 BETTER_AUTH_URL=http://localhost:3000
## Security (Required)
ENCRYPTION_KEY=your_encryption_key # Use `openssl rand -hex 64` to generate
# Email Provider (Optional) # Email Provider (Optional)
# RESEND_API_KEY= # Uncomment and add your key from https://resend.com to send actual emails # 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 # 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) # 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 # WEBCONTAINER_CLIENT_ID= # Uncomment and add your key from https://stackblitz.com/docs/webcontainer-api#webcontainer-client-id