Skip to content

feat: optimized multi-stage docker images (93% smaller) [WIP] - #359

Closed
adiologydev wants to merge 12 commits into
simstudioai:new-bunfrom
adiologydev:new-bun
Closed

feat: optimized multi-stage docker images (93% smaller) [WIP]#359
adiologydev wants to merge 12 commits into
simstudioai:new-bunfrom
adiologydev:new-bun

Conversation

@adiologydev

Copy link
Copy Markdown
Contributor

Description

This PR optimizes sim's publishable image to just 93% of the original size. It now uses runtime environment variables to be truly agnostic and letting users skip the self-building step.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Security enhancement
  • Performance improvement
  • Code refactoring (no functional changes)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • All tests pass locally and in CI (npm test)
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • I have updated version numbers as needed (if needed)
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Security Considerations:

  • My changes do not introduce any new security vulnerabilities
  • I have considered the security implications of my changes

Additional Information:

Next Steps:

  • Let GitHub Workflow use new dockerfiles
  • Update docker-compose to include other variable placeholders if needed.
  • Add a .dev and .prod compose file, one using context, the other using published ghcr image.

@vercel

vercelBot commented May 15, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

NameStatusPreviewCommentsUpdated (UTC)
docs✅ Ready (Inspect)Visit Preview💬 Add feedbackMay 18, 2025 1:28am
sim✅ Ready (Inspect)Visit Preview💬 Add feedbackMay 18, 2025 1:28am

@vercel

vercelBot commented May 15, 2025

Copy link
Copy Markdown

@adiologydev is attempting to deploy a commit to the Sim Studio Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR significantly optimizes Docker images through multi-stage builds and runtime environment configuration, reducing image size by 93%. The changes span across multiple files to support containerized deployment. - New multi-stage app.Dockerfile and db.Dockerfile using Bun runtime and Alpine Linux base for minimal image size - Modified env.ts to use next-runtime-env for dynamic environment variable handling, making the app more deployment-agnostic - Added DOCKER_BUILD environment flag to bypass waitlist protection and modify build configurations in self-hosted environments - Removed migration #29 from _journal.json which could impact database consistency across environments - Changed S3 client initialization from eager to lazy loading using getS3Client() factory pattern

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

40 file(s) reviewed, 24 comment(s)
Edit PR Review Bot Settings | Greptile

Comment threadapps/sim/app/api/auth/oauth/connections/route.ts Outdated
Comment threadapps/sim/app/api/auth/oauth/disconnect/route.ts Outdated
Comment threadapps/sim/app/api/auth/oauth/discord/channels/route.ts Outdated
Comment threadapps/sim/app/api/auth/oauth/discord/channels/route.ts
Comment threadapps/sim/app/api/auth/oauth/token/route.ts Outdated
Comment threaddocker/db.Dockerfile

# Copy only package files needed for migrations
COPY package.json bun.lock turbo.json ./
COPY apps/sim/package.json ./apps/sim/db/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Incorrect destination path for package.json. Should be ./apps/sim/ instead of ./apps/sim/db/ since the package.json is needed at the app root

Suggested change
COPY apps/sim/package.json ./apps/sim/db/
COPY apps/sim/package.json ./apps/sim/

Comment threaddocker/db.Dockerfile
Comment on lines +12 to +13
RUN bun install --omit dev --ignore-scripts && \
bun install --omit dev --ignore-scripts drizzle-kit drizzle-orm postgres next-runtime-env

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Second bun install command will overwrite dependencies from first install. Combine into single command with all packages

Suggested change
RUN bun install --omit dev --ignore-scripts && \
bun install --omit dev --ignore-scripts drizzle-kit drizzle-orm postgres next-runtime-env
RUN bun install --omit dev --ignore-scripts drizzle-kit drizzle-orm postgres next-runtime-env

Comment threaddocker/db.Dockerfile
COPY apps/sim/package.json ./apps/sim/package.json
COPY apps/sim/lib/env.ts ./apps/sim/lib/env.ts

WORKDIR /app/apps/sim No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Missing CMD or ENTRYPOINT instruction to specify how to run database migrations

Comment threaddocker/db.Dockerfile
# ========================================
# Dependencies Stage: Install Dependencies
# ========================================
FROM oven/bun:alpine AS deps

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider pinning to specific Bun version instead of using latest alpine for reproducible builds

Comment threaddocker-compose.yml Outdated
… and implement GitHub Actions for Docker image build and publish
@waleedlatif1

Copy link
Copy Markdown
Collaborator

merged in #371

@adiologydev
adiologydev deleted the new-bun branch May 21, 2025 21:46
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@adiologydev@waleedlatif1