This One File Fixed My Dev Environment (Devbox)
BBetter Stack
Computing/SoftwareSmall Business/StartupsInternet Technology
Transcript
00:00:00your readme is lying to you it says setup takes five minutes then node is wrong python is wrong
00:00:07postgres is missing docker is taking forever and now we're debugging before we even get started
00:00:13your dev environment should not live in a readme it should live in git that's what devbox does
00:00:20one devbox json file one command devox shell same environment for every dev with no global installs
00:00:28and no nix knowledge required let me show you
00:00:30at first devbox looks almost too simple you make a devbox json you list the tools your project needs
00:00:42node go python postgres whatever your stack actually needs you commit that file then anyone else can just
00:00:50run devbox shell and they get the same environment you do same versions tools scripts no global
00:00:58installs no please install these eight things first no homebrew state from years ago your setup
00:01:03stops living in someone's memory it starts living in your repo now that sounds small but if you've
00:01:09ever lost half a day to a broken local setup you already know that this is not small if you enjoy
00:01:16coding tools to speed up your workflow be sure to subscribe we have videos coming out all the time
00:01:20now we're starting off here so i'm going to start with an empty project i'm going to make a new folder
00:01:25we'll call it devbox demo we cd into the folder and all we need to do once we have devbox is run
00:01:31devbox in it devbox creates a file called devbox json right now it's basically empty it's just the
00:01:39boilerplate that devbox gives us now let's add the tools this project actually needs to add tools we can
00:01:45create a devbox add and i'm going to install things like go node.js and some python now here's the
00:01:52important part i'm not installing these globally i'm not changing my system node i'm not touching my system
00:02:00with python these tools belong to this project now when i run devbox shell and i'm inside a clean project
00:02:09environment now that you're in this environment you could just check the versions right go version no
00:02:14version python version right i can check everything to make sure it's running now that's the big payoff
00:02:19the project asked for specific tools devbox gave me those tools now let's add a script and inside devbox
00:02:27json we can actually define a test and i'm just going to echo back these running tests and i'll get the node
00:02:34in the go version when you run devbox run test and now that same command works for anyone using this repo
00:02:42same script same tools same environment now watch what happens when i leave you can just run exit
00:02:48you are going to leave that environment and i'm back to my normal machine environment so that was a dead
00:02:53simple right like what is devbox actually doing well devbox uses nyx under it all nyx is great because
00:03:00it's built for reproducibility instead of saying install whatever happens to be the latest today
00:03:06it can pin the exact tools your project actually needs now that is the good part the hard part is
00:03:12that nyx can feel like a whole new world there are a lot of concepts that are great but not exactly
00:03:18friendly when all you wanted was the right node version devbox takes shows us something different
00:03:23here it says what if we kept the reproducibility but made the workflow feel normal so instead of
00:03:29writing nyx expressions you can use commands like devbox add devbox search shell run services all of
00:03:37these commands are much more simpler and your project gets two important files you get a json file and a
00:03:44lock file think of the devbox json as what our environment needs think of the devbox lock file as the pin to pin
00:03:52exactly what you got you commit both now your environment is not just a paragraph in a readme file
00:03:58it's part of the actual project devbox works on mac os linux and wsl it can integrate with vs code it can
00:04:06define scripts it can manage services like databases and when you need to it can export to things like
00:04:12docker dev containers and ci workflows the value of this isn't just cool tool right it's a dead simple tool the
00:04:19value is i think just time the first problem is the readme right the readme could say really anything it
00:04:26could say hey install node 18 but the app has changed it really needs node 20. the second problem
00:04:32this actually helps with is onboarding it's your first day on the job it should be easy to get going
00:04:37we know that's not the case right so you shouldn't need to ask which node version do i need you shouldn't
00:04:43need to ping someone hey which python version are we on do i really need postgres locally and why does
00:04:48this only work for little timmy over there they should just have to clone the repo enter the shell
00:04:52and run the project if something breaks at least everyone is starting from the same environment the problem
00:04:58is global pollution trying tools should not wreck your laptop you want go 1.22 for this repo you add it you
00:05:06want node 20 here but something else elsewhere fine okay that's fine the tools live with the project your
00:05:13system stays cleaner with devbox your environment definition can be shared between local development
00:05:18and automation does that fix every ci problem no it's not going to but it removes a huge class of dumb
00:05:26problems and dumb problems are the ones that hurt us the most they're simple we still have them all the
00:05:32time finally here is docker heavy local docker workflow more specifically docker is still great by far if
00:05:40you need containers use containers but a lot of teams use docker locally because they don't have a better
00:05:46way to manage tools now what's good here is the workflow is dead simple dev box add shell run you
00:05:52don't have to learn that much the environment becomes a real part of your project a real file
00:05:57in the repo when everyone uses the same versions and scripts debugging gets easier but that's great
00:06:03super simple what's going to annoy you is well the first next door download it took a while to download
00:06:09it's fine it's the first time okay json is simple but it can get ugly as we know if we add too much
00:06:15into it for basic scripts it's fine for complex setup logic don't cram a giant shell command into json
00:06:22just put the logic in a sh file then call that from dev box and finally dev box is not a full cloud ide
00:06:30if you need browser-based coding instant preview urls you may still want something like code spaces
00:06:36dev box is best at local and ci reproducibility dev box is not going to solve every development
00:06:42problem but it can solve the ones that annoy us the most which is really just getting the project to
00:06:46run so could be worth a shot especially if your project has more than one language or more than
00:06:51one cli tool if you enjoy coding tools like this be sure to subscribe to the better stack channel we'll
00:06:56We'll see you in another video.
Community Posts
No posts yet. Be the first to write about this video!
Write about this video