-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(bun): upgrade to bun, reduce docker image size by 95%, upgrade docs & ci #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b4a2d85
e780fd8
99e18b8
7837c1e
f74aadf
730bf83
b1ccc86
df3e9d0
db8e2f7
c51b5e1
f5bdd01
d2ea965
1ad8140
37fbb12
d9d82d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,29 +1,35 @@ | ||||||||||||||||||||
| FROM node:20-bullseye | ||||||||||||||||||||
| # Use the latest Bun canary image for development | ||||||||||||||||||||
| FROM oven/bun:canary | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Avoid warnings by switching to noninteractive | ||||||||||||||||||||
| ENV DEBIAN_FRONTEND=noninteractive | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Install necessary packages for development | ||||||||||||||||||||
| RUN apt-get update \ | ||||||||||||||||||||
| && apt-get -y install --no-install-recommends \ | ||||||||||||||||||||
| git curl wget jq sudo postgresql-client \ | ||||||||||||||||||||
| git curl wget jq sudo postgresql-client vim nano \ | ||||||||||||||||||||
| bash-completion ca-certificates lsb-release gnupg \ | ||||||||||||||||||||
| && apt-get clean -y \ | ||||||||||||||||||||
| && rm -rf /var/lib/apt/lists/* | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Create a non-root user | ||||||||||||||||||||
| ARG USERNAME=node | ||||||||||||||||||||
| ARG USERNAME=bun | ||||||||||||||||||||
| ARG USER_UID=1000 | ||||||||||||||||||||
| ARG USER_GID=$USER_UID | ||||||||||||||||||||
|
Comment on lines
+16
to
18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: User creation commands are missing - need to actually create the user before setting up sudo access
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| # 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 | ||||||||||||||||||||
| RUN npm install -g npm@latest | ||||||||||||||||||||
| # Install global packages for development | ||||||||||||||||||||
| RUN bun install -g turbo drizzle-kit typescript @types/node | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Install global packages | ||||||||||||||||||||
| RUN npm install -g drizzle-kit turbo | ||||||||||||||||||||
| # Install bun completions | ||||||||||||||||||||
| RUN bun completions > /etc/bash_completion.d/bun | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Set up shell environment | ||||||||||||||||||||
| RUN echo "export PATH=$PATH:/home/$USERNAME/.bun/bin" >> /etc/profile | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: PATH modification doesn't include $USER_HOME variable, could break for different user configurations
Suggested change
|
||||||||||||||||||||
| RUN echo "source /etc/profile" >> /etc/bash.bashrc | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Switch back to dialog for any ad-hoc use of apt-get | ||||||||||||||||||||
| ENV DEBIAN_FRONTEND=dialog | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,15 @@ services: | |
| dockerfile: .devcontainer/Dockerfile | ||
| volumes: | ||
| - ..:/workspace:cached | ||
| - bun-cache:/home/bun/.bun/cache:delegated | ||
| command: sleep infinity | ||
| environment: | ||
| - NODE_ENV=development | ||
| - DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio | ||
| - POSTGRES_URL=postgresql://postgres:postgres@db:5432/simstudio | ||
|
Comment on lines
14
to
15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Duplicate database connection strings (DATABASE_URL and POSTGRES_URL) may cause confusion. Consider using only DATABASE_URL. |
||
| - BETTER_AUTH_URL=http://localhost:3000 | ||
| - NEXT_PUBLIC_APP_URL=http://localhost:3000 | ||
| - BUN_INSTALL_CACHE_DIR=/home/bun/.bun/cache | ||
| depends_on: | ||
| db: | ||
| condition: service_healthy | ||
|
|
@@ -41,3 +43,4 @@ services: | |
|
|
||
| volumes: | ||
| postgres-data: | ||
| bun-cache: | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,19 +15,34 @@ cp /workspace/.devcontainer/.bashrc ~/.bashrc | |||||||||||||||
| echo 'if [ -f ~/.bashrc ]; then . ~/.bashrc; fi' >> ~/.profile | ||||||||||||||||
|
|
||||||||||||||||
| # Clean and reinstall dependencies to ensure platform compatibility | ||||||||||||||||
| echo "📦 Cleaning and reinstalling npm dependencies..." | ||||||||||||||||
| echo "📦 Cleaning and reinstalling dependencies..." | ||||||||||||||||
| if [ -d "node_modules" ]; then | ||||||||||||||||
| echo "Removing existing node_modules to ensure platform compatibility..." | ||||||||||||||||
| rm -rf node_modules | ||||||||||||||||
| rm -rf apps/sim/node_modules | ||||||||||||||||
| rm -rf apps/docs/node_modules | ||||||||||||||||
| fi | ||||||||||||||||
|
|
||||||||||||||||
| # Ensure Bun cache directory exists and has correct permissions | ||||||||||||||||
| mkdir -p ~/.bun/cache | ||||||||||||||||
| chmod 700 ~/.bun ~/.bun/cache | ||||||||||||||||
|
|
||||||||||||||||
| # Install dependencies with platform-specific binaries | ||||||||||||||||
| npm install || { | ||||||||||||||||
| echo "⚠️ npm install had issues but continuing setup..." | ||||||||||||||||
| echo "Installing dependencies with Bun..." | ||||||||||||||||
| bun install || { | ||||||||||||||||
| echo "⚠️ bun install had issues but continuing setup..." | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+32
to
34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Silently continuing after bun install failures could leave the environment in an inconsistent state. Consider failing fast here instead.
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| # Check for native dependencies | ||||||||||||||||
| echo "Checking for native dependencies compatibility..." | ||||||||||||||||
| NATIVE_DEPS=$(grep '"trustedDependencies"' apps/sim/package.json || echo "") | ||||||||||||||||
| if [ ! -z "$NATIVE_DEPS" ]; then | ||||||||||||||||
| echo "⚠️ Native dependencies detected. Ensuring compatibility with Bun..." | ||||||||||||||||
| for pkg in $(echo $NATIVE_DEPS | grep -oP '"[^"]*"' | tr -d '"' | grep -v "trustedDependencies"); do | ||||||||||||||||
| echo "Checking compatibility for $pkg..." | ||||||||||||||||
| done | ||||||||||||||||
|
Comment on lines
+41
to
+43
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Native dependency check only logs but takes no action. Should verify/rebuild native dependencies for Bun compatibility. |
||||||||||||||||
| fi | ||||||||||||||||
|
|
||||||||||||||||
| # Set up environment variables if .env doesn't exist for the sim app | ||||||||||||||||
| if [ ! -f "apps/sim/.env" ]; then | ||||||||||||||||
| echo "📄 Creating .env file from template..." | ||||||||||||||||
|
|
@@ -42,7 +57,7 @@ fi | |||||||||||||||
| echo "🗃️ Running database schema generation and migrations..." | ||||||||||||||||
| echo "Generating schema..." | ||||||||||||||||
| cd apps/sim | ||||||||||||||||
| npx drizzle-kit generate | ||||||||||||||||
| bunx drizzle-kit generate | ||||||||||||||||
| cd ../.. | ||||||||||||||||
|
|
||||||||||||||||
| echo "Waiting for database to be ready..." | ||||||||||||||||
|
|
@@ -53,7 +68,7 @@ echo "Waiting for database to be ready..." | |||||||||||||||
| if PGPASSWORD=postgres psql -h db -U postgres -c '\q' 2>/dev/null; then | ||||||||||||||||
| echo "Database is ready!" | ||||||||||||||||
| cd apps/sim | ||||||||||||||||
| DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio npx drizzle-kit push | ||||||||||||||||
| DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio bunx drizzle-kit push | ||||||||||||||||
| cd ../.. | ||||||||||||||||
| break | ||||||||||||||||
| fi | ||||||||||||||||
|
|
@@ -71,13 +86,14 @@ echo "Waiting for database to be ready..." | |||||||||||||||
| cat << EOF >> ~/.bashrc | ||||||||||||||||
|
|
||||||||||||||||
| # Additional Sim Studio Development Aliases | ||||||||||||||||
| alias migrate="cd /workspace/apps/sim && DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio npx drizzle-kit push" | ||||||||||||||||
| alias generate="cd /workspace/apps/sim && npx drizzle-kit generate" | ||||||||||||||||
| alias dev="cd /workspace && npm run dev" | ||||||||||||||||
| alias build="cd /workspace && npm run build" | ||||||||||||||||
| alias start="cd /workspace && npm run dev" | ||||||||||||||||
| alias lint="cd /workspace/apps/sim && npm run lint" | ||||||||||||||||
| alias test="cd /workspace && npm run test" | ||||||||||||||||
| alias migrate="cd /workspace/apps/sim && DATABASE_URL=postgresql://postgres:postgres@db:5432/simstudio bunx drizzle-kit push" | ||||||||||||||||
| alias generate="cd /workspace/apps/sim && bunx drizzle-kit generate" | ||||||||||||||||
| alias dev="cd /workspace && bun run dev" | ||||||||||||||||
| alias build="cd /workspace && bun run build" | ||||||||||||||||
| alias start="cd /workspace && bun run dev" | ||||||||||||||||
| alias lint="cd /workspace/apps/sim && bun run lint" | ||||||||||||||||
| alias test="cd /workspace && bun run test" | ||||||||||||||||
| alias bun-update="cd /workspace && bun update" | ||||||||||||||||
| EOF | ||||||||||||||||
|
|
||||||||||||||||
| # Source the .bashrc to make aliases available immediately | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| # Exclude files from Docker build | ||
| .git | ||
| .github | ||
| node_modules | ||
| .next | ||
| .vercel | ||
| .husky | ||
| .env | ||
| .env.* | ||
| npm-debug.log | ||
| LICENSE | ||
| NOTICE | ||
| .prettierrc | ||
| .prettierignore | ||
| README.md | ||
| .devcontainer | ||
| .gitignore | ||
| .husky | ||
| .github | ||
| .devcontainer | ||
| .env.example | ||
| node_modules |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||||||
| version: 2 | ||||||||||
| updates: | ||||||||||
| - package-ecosystem: 'npm' | ||||||||||
| directory: 'apps/sim' | ||||||||||
| - package-ecosystem: 'bun' | ||||||||||
| directory: '/apps/sim' | ||||||||||
|
Comment on lines
+3
to
+4
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Verify that GitHub's dependabot officially supports 'bun' as a package-ecosystem value. This may cause dependabot to fail if not supported.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Leading slash in directory path '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/apps/sim' may cause issues with dependabot's directory resolution. Consider removing the leading slash. |
||||||||||
| schedule: | ||||||||||
| interval: 'weekly' | ||||||||||
| day: 'monday' | ||||||||||
|
|
@@ -21,9 +21,9 @@ updates: | |||||||||
| patterns: | ||||||||||
| - '*' | ||||||||||
|
|
||||||||||
| # Documentation site dependencies (/docs) | ||||||||||
| - package-ecosystem: 'npm' | ||||||||||
| directory: 'apps/docs' | ||||||||||
| # Documentation site dependencies (/apps/docs) | ||||||||||
| - package-ecosystem: 'bun' | ||||||||||
| directory: '/apps/docs' | ||||||||||
| schedule: | ||||||||||
| interval: 'weekly' | ||||||||||
| day: 'wednesday' | ||||||||||
|
|
@@ -42,7 +42,7 @@ updates: | |||||||||
| - '*' | ||||||||||
|
|
||||||||||
| # Root-level dependencies (if any) | ||||||||||
| - package-ecosystem: 'npm' | ||||||||||
| - package-ecosystem: 'bun' | ||||||||||
| directory: '/' | ||||||||||
| schedule: | ||||||||||
| interval: 'weekly' | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,64 @@ | ||||||
| name: Build and Publish Docker Image | ||||||
|
|
||||||
| on: | ||||||
| push: | ||||||
| branches: [main] | ||||||
| tags: ['v*'] | ||||||
|
|
||||||
| jobs: | ||||||
| build-and-push: | ||||||
| runs-on: ubuntu-latest | ||||||
| strategy: | ||||||
| fail-fast: false | ||||||
| matrix: | ||||||
| include: | ||||||
| - dockerfile: ./docker/app.Dockerfile | ||||||
| image: ghcr.io/simstudioai/simstudio | ||||||
| - dockerfile: ./docker/db.Dockerfile | ||||||
| image: ghcr.io/simstudioai/migrations | ||||||
| permissions: | ||||||
| contents: read | ||||||
| packages: write | ||||||
|
|
||||||
| steps: | ||||||
| - name: Checkout repository | ||||||
| uses: actions/checkout@v4 | ||||||
|
|
||||||
| - name: Set up QEMU | ||||||
| uses: docker/setup-qemu-action@v3 | ||||||
|
|
||||||
| - name: Set up Docker Buildx | ||||||
| uses: docker/setup-buildx-action@v3 | ||||||
|
|
||||||
| - name: Log in to the Container registry | ||||||
| if: github.event_name != 'pull_request' | ||||||
| uses: docker/login-action@v3 | ||||||
| with: | ||||||
| registry: simstudioai | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: registry value should be 'ghcr.io' not 'simstudioai' to match the image names being used
Suggested change
|
||||||
| username: ${{ github.repository_owner }} | ||||||
| password: ${{ secrets.GITHUB_TOKEN }} | ||||||
|
|
||||||
| - name: Extract metadata (tags, labels) for Docker | ||||||
| id: meta | ||||||
| uses: docker/metadata-action@v5 | ||||||
| with: | ||||||
| images: ${{ matrix.image }} | ||||||
| tags: | | ||||||
| type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} | ||||||
| type=ref,event=pr | ||||||
| type=semver,pattern={{version}} | ||||||
| type=semver,pattern={{major}}.{{minor}} | ||||||
| type=semver,pattern={{major}}.{{minor}}.{{patch}} | ||||||
| type=sha,format=long | ||||||
|
|
||||||
| - name: Build and push Docker image | ||||||
| uses: docker/build-push-action@v5 | ||||||
| with: | ||||||
| context: . | ||||||
| file: ${{ matrix.dockerfile }} | ||||||
| platforms: linux/amd64,linux/arm64 | ||||||
| push: ${{ github.event_name != 'pull_request' }} | ||||||
| tags: ${{ steps.meta.outputs.tags }} | ||||||
| labels: ${{ steps.meta.outputs.labels }} | ||||||
| cache-from: type=gha | ||||||
| cache-to: type=gha,mode=max | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: sim-rebuild uses 'bun run start' but earlier aliases use 'bun run dev' - this inconsistency could cause confusion