Creating portable environments for the CM5 DevServer
Today I'll be going over portable dev environments on my CM5, why I use them and why they are beneficial to every developer, no matter if you're just starting out or fully seasoned.
Why, though?
Portable dev environments are incredibly useful and if you're just starting out, be thankful you never endured the pitfalls every developer did 20 years ago, such as machine downtime, version mismatch, operating system incompatability... Nowadays, these issues are rare. Now, we have tools that allow you to create and deploy from pretty much anywhere, on any machine. It doesn't matter if your OS is version 6.7, your colleagues machine is Grape, NodeJS is version 21 on the main project machine but verison 23 on all the other machines.. your project will still work and you can continue to develop and deploy even if these variables change further. The greastest strength is that with portable dev environments, you can run select versions of your project alongside other versions that are completely and totally isolated from each other. If you have a bug in one version, but the other version works perfectly, you can use each version to successfully identify the issue without suffering downtime on the version that has been released.

Connecting to CM5 Dev Server via SSH
VSCode
We're going to go off on a tangent here slightly and quickly touch on VSCode, which has been a game changer in the development scene. Next to Vim, it's the most powerful code editor in your toolkit, highly customizable, has a vast range of plugins developed by a dedicated community, easy to use and better yet, allows you to connect and develop remotely via SHH. Tne best thing for me about VSCode is that it supports vim keybidings, so I get the full Vim experience while using VS. Vim is just as powerful and also has a vast array of plugins but harder to get to grips with and set up as an IDE. It's more suited to powerusers than hobbyists or general developers, but developing over SSH is also possible with Vim using an SSH tunnel. I will be covering more on Vim and VSCode in seperate posts in the future, including how to set up Vim as an IDE, so stay tuned for those.
Setting up & scripting with Bash
Starting up the CM5, which is quite noisy at the minute due to the old fan (you'll be pleased to know I ordered 2 new fans, using the old fan is something I covered here), I will be going straight to the terminal on my main development machine and I won't have to wait long to connect as the CM5 is lightning fast to boot.
I'll be writing a bash script for this, I write bash scripts for pretty much everything where I can, it's good practice and saves you time in the long run especially for tasks like this, the script can be saved and ported to pretty much any linux machine. This way, you can set up and run a portable dev environment no matter where you are.

Starting Vim
So first we open up Vim using the filename we want to create. I place all my scripts in a /script folder in my /dev directory, where all my projects are located. We start our bash script with a Shebang (#!/bin/bash) that tells Bash (the terminal) that this file is a bash script. Now if you have experience with bash commands you will start to notice commands that you recognise and this is all bash scripts are, executable terminal commands with a bit of extra functionality. Feel free to follow along with the pictures, some of the code is missing from the photos but don't fret, I'll post the .sh file at the end of the post.

docker function
Here, we write a function to tell the script that this is the code we want to execute when the function is called. This function will execute code that installs docker.

kubernetes function
The next function executes code that installs Kubernetes Lite. (K3s)

docker_compose function
This function creates a compose file for Docker that holds all the container details, such as ports and the environment.

deploy function
The last function deploys the project to Kubernetes, which manages docker containers. After all the functions have been coded, we can write the section for accepting user input and store them as variables to be used elsewhere.

echoing success.
and finally, we tell the script to create the project in a specified directory and if it doesn't exist, create it. Then we echo to the user that it was successful.
On first run, it didnt work and that's ok! It seems docker-compose is throwing up an error. I get no response when I asked what version it is (--version) so I will re-install it:
sudo curl -L "https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Now, everything should work.

Success!
There we have it, portable dev environments on my CM5, which are created and deployed using a simple Bash script.
Catch you next time, where we will be going a bit further with this script.
- Dru