Skip to content

Conversation

@dionhut
Copy link

@dionhut dionhut commented Nov 13, 2023

What does this PR do?

Added VSCode DevContainer to automate setup of Bun development environment.

TLDR;

  • Added a bun-devcontainer image Dockerfile + dependency build setup scripts
  • Added .devcontainer VSCode config
  • Image based on known good VSCode base devcontainer image designed for devcontainers
  • build and node_modules folders are mounted volumes which survive container rebuilds and build performance.
  • Pre-built published image can save developers building their own development environment.
  • Bun project can provide a default set of VSCode extensions which are automatically installed in the devcontainer.

First off, I'm a huge fan of the project! I initially wanted to help contribute by looking into fixing the devcontainer lockfile issue - #4923
I started out seeing I could build the bun repo in a devcontainer cause I didn't want to contaminate my existing macbook development environment. I use isolated devcontainers where I can.

It's my view that the value of being able to contribute to the bun project itself or developing with bun javascript projects in isolation with other dev environments on a dev's work or personal machine and not have to worry about setup of extensive deps that can interfere with other projects is a must.

Also devcontainers are great at allowing a project to capture infra as code for the development environment in source control and each contributor could rely on working with the same environment every time an issue is reported or giving confidence PRs are at least testing with a consistent dev env. Hopefully I don't have to sell it much more :)

How did you verify your code works?

Tested building docker image

Built and tested using Macbook M1

From bun repo folder
cd ~/code/bun

Build the image - Ideally this image would be built via CI or something and published most likely the same way the oven/bun image is. This probably goes with out saying, but contributor developers wouldn't need to build the bun-devcontainer image.
cd .devcontainer && ./build-devcontainer.sh

Tested opening devcontainer + bun project in VSCode

code .

Open project in the devcontainer
Command-Shift-P - >dev Containers: Reopen in Container

You should see this message after devcontainer is ready for work.
Screenshot 2023-11-12 at 8 06 27 PM

Now build bun as normal. I found I had to run scripts/clean-dependencies to clean out all the other failed attempts to get the build environment right first.
bun setup

And Bob's your uncle!
Screenshot 2023-11-12 at 2 54 25 PM

Testing running bun-debug binary and debugging in VSCode with LLVM extension

Screenshot 2023-11-12 at 2 57 38 PM

TODO: Building the multiple images for each supported target architectures. I might need help with this I'm not familiar with this project and build pipeline.

Looking forward to any feedback or if this is something the project wants to incorporate. This change is definitely not a triumph or anything but a nice to have even if it only lives on in my fork. Thanks.

@staabm
Copy link
Contributor

staabm commented Nov 13, 2023

Can this image be used for github codespaces?

@Jarred-Sumner
Copy link
Collaborator

Thank you for this.

We previously had a dev container (#743 #1680 #1439 #472 #933), but since the core team doesn't use dev containers, they frequently stopped working. The iteration cycle time is better building outside Docker, and we put a lot of effort into trying to make Bun easy to build via CMake.

We don't have the bandwidth to maintain a devcontainer ourselves right now, but you're obviously welcome to do that in a separate repository if you'd like

@dionhut
Copy link
Author

dionhut commented Nov 13, 2023

Can this image be used for github codespaces?

Great question. I don't see why not but I haven't tried it. I guess I would say developing in a bun consumer javascript project environment in the cloud seems more compelling to me rather than working on the bun platform code itself. And BTW currently bun install is broken (fails to save lockfile) devcontainers. Cheers.

Sign up for free to 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.

3 participants