Courses / Build Your First Software Factory Execution HarnessFreeLesson 2 of 43:18

Isolate Ports, Databases and Environments

A worktree isolates code, not the machine: two dev servers still fight over port 3000 and share one database. A hook gives each branch its own port and empty database, and a sandbox or micro VM covers what lives in the cloud.

Play Isolate Ports, Databases and Environments

Chapters

  1. Where a worktree stops isolating
  2. A hook per worktree
  3. When the cloud is shared
  4. Sandboxes and micro VMs

Transcript

Where a worktree stops isolating

Now I said work tree alone won't help in certain cases when you have automated verification layers. For example, you need to spin up the development environment, development server, and you need to screenshot. For example, it is a UI change, and you wanted to visually check what is before, what is after, and you need to attach that screenshot in your PR. Then what will happen? two different processes try to open port 3000 and then it will fail. So now since work tree is not exactly VM or anything like that, it is still using the shared resources. How you can handle it.

A hook per worktree

It is not exactly resource splitting, but it is more like you can create processes around while creating the work tree. It goes into a hook. you can do it even without work tree. it it you know it creates using the configuration, you can create the hooks that will that will run okay. Create this empty DB and you run the migration along with this work tree. So automatically that work tree will connect to that port, and that work tree will connect to that database locally. So automatically you can isolate that process.

When the cloud is shared

Does that alone will solve it? Yes, for web application, most probably this is enough. And if you are mostly doing your local environment, this is enough. But what if your development system itself is connecting to a cloud environment like Google Pub/Sub or MongoDB in cloud or you know Cloud SQL in GCP, then this becomes a problem. At that point, these are like how you can you know switch and you can remove a work tree.

Sandboxes and micro VMs

Okay, if work tree alone won't solve it, since my environment is already in cloud, then the better approach is going for coding sandboxes like code spaces or Gitpod, those ones solve it, or even you can go for a more custom cheaper options like cloud environment. serverless might be a bit a bit more costlier, but you can go for more like VMs where you can span up micro VM and so on. That way you can manage a standalone isolated environment which has you know footprint of exactly what you want and it will deploy spin up and that environment you will push and then destroy that environment once you are satisfied and you will merge it. Of course, the process wise it does has its own challenges. But when you are actually working on something which is already in cloud, most probably you already have that process in place, even without AI. So automatically you can pin up spin down what you need.

This lesson is cut from the free Lightning session Build Your First Software Factory Execution Harness. The Live Labs build the same system with you, free, on Thursdays: see the Live Labs.