Automated Testing and Dev Containers
TheoForger
Posted on November 16, 2024
This week continuing with my project Mastermind, I updated my CI workflow and played around with dev containers.
CI Refinement
Since I updated my test code last week, it's only natural I work on CI this week. I already had a workflow going in GitHub Actions, which builds the package and runs unit tests.
Obviously there's room for improvement:
Firstly, I added a section to run the code formatter rustfmt
and the linter clippy
:
- name: Run rustfmt
run: cargo fmt --check
- name: Run clippy
run: cargo clippy --all-features --all-targets -- -D clippy::all
I then separated these runs into different jobs, so that whenever one job fails, it's easier to locate the exact cause:
jobs:
lint:
# ...
test:
# ...
build:
# ...
I also fixed a bug where the test code would fail without some environment variables, despite they are only for configuration purposes. So now I can safely remove them from the workflow file!
I once again worked with Amir to test each other's setup, which was as always a good time! We filed a PR on each other's repo to implement more testing, as well as double checking our CI setup.
Update
Just as I was writing the blog, I realized that instead of trying to build the project as the third job, I could simply run cargo check
. It checks the code for error without building the project, which is not only faster, but also saves resources.
Dev Containers
This was not the first time I heard of nor used Dev containers - In the past, I have experimented with immutable Linux distros like Fedora Silverblue and openSUSE MicroOS. Dev containers are constantly recommended among those communities. Powered by docker, they allow users to have an isolated, reproducible dev environment on top of their operating system.
But the advantage doesn't stop there. You can also have these containers in the cloud and have access to them no matter where you go or which device you use.
For my project, I honestly wish there was more work to do, but once again, Rust just made things insanely easy: Because everything I needed, including the package manager, the project manager, the code formatter, the linter are included in the Rust toolchain, all I had to do was using the Rust template image. I simply went with the default configuration, ran the containers, and everything just worked!
{
"name": "Rust",
"image": "mcr.microsoft.com/devcontainers/rust:1-1-bookworm",
"customizations" : {
"jetbrains" : {
"backend" : "RustRover"
}
},
}
As a self hosting hobbyist, I work with docker on a regular basis. I'm a huge fan of container technology - It's such a powerful tool that not only solves dependency issues but enables incredible power in software deployment, networking, easy configuration, etc. This is another fantastic example.
Conclusion
Not a super eventful week, but it's always nice to feel the project really coming together. I'm also interested in further exploring the power of dev containers and see how I can benefit from them in different projects.
Posted on November 16, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.