/deven

Primary LanguageShellMIT LicenseMIT

Deven, development environment management tool

Once upon a time in a galaxy far, far away...

I was doing different projects in school and other places where each needed its own environment packages. Thoses that I needed solely for a school project were polluting my distro and I didn't like that very much. Why not uninstalling them you ask ? Well I doubt that, when setting up the required development environment, anyone among us will do more than just copy paste the instructions. Beside, keeping track of all those packages is A LOT of work.

My computer is my house, and I couldn't let dust stacking up any longer, I needed a sandbox where I can just install those packages once in a while and delete them all in one click. Ahah...sounds like I needed a VM, or more contemporary, a container. Indeed, this repo is a little script that helps easing the process of doing just that. Behind the curtain, it uses LXD as the container platform.

Why LXD, not Docker ?

Docker is great for anything that need to be repoducible (the whole point of it), hence persistent changes need to be commited explicitely. I have no need of repoducible at all. In fact, I want a draft where whatever I write should be persistent, but leaving me the options to toss it away without tearing down the house. Moreover, some courses required GUI apps, and ofc it is possible to run GUI apps in Docker, but it just feels clunky and not the right tool for the job. What I want looks more like a VM than a container in Docker sense.

And LXD is just that. It is marketed a container, but I think the exact term should be thin VM, since each container run with a full fledge OS. I treat them as remote pc, accessible only from my system.

What does this script do exactly ?

LXD looks a lot like a VM, but it is still a CLI. In order to run GUI apps (with GPU accelerated ?!?), it needs a bit of setup (e.g. X forward). Then to use it as a development environment, I need to mount at least the source code folder in there with write permission. Moreover, what if I want to vscode ssh into the container conveniently ?

I wrote this script to do all of those configurations once and for all. It exposes several simple commands that allow spinning up easily new containers while doing different configurations behind the scene so you don't have to do it.

On the first run, it creates a base container if there isn't already one. This base container has X forward (for GPU accelerated, only nvidia is currently supported) and a chosen (by user) mounted directory from host with read/write permission. Every subsequent containers are duplicated from this one, so it should be kept bare metal. For conveniency, the password of the user in the container is also removed, and accessible through ssh, passwordless (only me can access the container anyway), this behavior can be disabled.

For now, the base image is ubuntu 22.04. Changing the base image might require changing the configurations.

How to use ?

Just run deven help, it's pretty self-descriptive. If you really don't care about the details, here some examples

  • run deven spawn container-name will shell into the container if it already exists, otherwise it will be created, the script might ask you some questions while doing so.
  • run deven showip container-name to see the IP address of the container (for ssh with vscode for example)

Installation

curl -L https://raw.githubusercontent.com/haoadoreorange/deven/main/install.sh | sh

This script has bash-oo-framework as dependency. If it can't find the framework directory on your system through the BASH_OO environment variable, it will download a bundled version on first run.

Also, this assume that you already have a fully functional LXD on your system.

Security implications

I might not use security best practices in here, mostly for conveniency. If that is what you care about, please read the script yourself. If you have an idea how to improve it, please send PR <3.

Limitations

All the lxc commands are run with sudo, because on my system I don't add my user to the lxd group, since it implies a security vulnerability (it elevates the user to root equivalent, see more here https://wiki.archlinux.org/title/LXD#Configure_LXD)

TODOs

Add tests ? But I'm not sure how.