swiebertje
Posts: 2
Joined: Sun Jul 25, 2021 7:19 pm

PI-CI: prepare a Raspberry Pi image using a VM

Sun Jul 25, 2021 8:30 pm

I'm very proud to share my first open source project: PI-CI, A raspberry Pi emulator in a Docker container that lets developers easily prepare and flash RPi configurations.

Explanation
- Run an RPi VM with internet access.
- Prepare an RPi configuration inside the VM.
- Flash the Raspberry VM image to a physical SD card.

Use cases
- Preconfigure Raspberry Pi servers that work from first boot.
- Create reproducible server configurations using Ansible.
- Automate the distribution of configurations through a CI pipeline.
- Test ARM applications in a virtualized environment.
- Safely test backups without a second SD card.

Specifications
- Pi 3 and 4 support
- 64 bit (ARMv8) Raspbian OS included
- Support for 32 bit ARMv7l distro's
- Internet access
- No root required
- Ansible preinstalled
- Safe, fully reproducible from source
- Configurable kernel
- Tested and stable

Example workflow

Code: Select all

# Download the container image
docker pull ptrsr/pi-ci

# Run the VM and put the virtual image in the dist folder in the home directory.
# NOTE: login using the default username: pi , password: raspberry
docker run --rm -it -v ~/dist:/dist ptrsr/pi-ci start

# Flash the VM to an SD card (mmcblk0)
docker run --rm -it -v $(realpath .):/dist --device=/dev/mmcblk0 ptrsr/pi-ci flash
Automation
It is actually possible to automate the complete configuration process, ensuring reproducible configurations. The automation can be done using Ansible, a simple example configuration can be found on the PI-CI repo. The example configuration is actually used in a CI pipeline to test the virtual machine before pushing it to Docker hub!

Future improvements
I'm planning to add image resizing soon, so that the virtual machine can have any side. For now, the virtual Pi is only 2gb and can be extended to 4gb using the resize command (or for advanced users, using qemu-img resize).

Creating sparse backups of SD cards is also on the TO-DO list.

Final note
I'd love to hear what you think, and happily answer any questions! Github stars and pull-requests are especially welcome.

User avatar
Botspot
Posts: 1771
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas
Contact: Website

Re: PI-CI: prepare a Raspberry Pi image using a VM

Sat Jul 31, 2021 7:00 pm

Wow, this looks very similar to my vdesktop and Pi Power Tools programs I made a while back.
Does your virtual Pi display the desktop environment like vdesktop can, or is it command-line only?
Pi-Apps - #1 most popular Raspberry Pi app store with >500,000 users.
Includes the Zoom desktop app, 3 ways to run Minecraft, 7 web browsers, appearance themes, and 72 more.
More info: https://github.com/Botspot/pi-apps

User avatar
thagrol
Posts: 5558
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: PI-CI: prepare a Raspberry Pi image using a VM

Sat Jul 31, 2021 8:09 pm

Couple of questions:
  1. What hardware and OS do I need to run this? I couldn't quite work it out from the README.
    [*"64 bit (ARMv8) Raspbian OS included": Is that Raspbian or Raspberry Pi OS (they're no longer the same thing)? Lite, desktop, or desktop with recommended software?
  2. Is it wise to use a 64 bit OS as AFAIK it's still in beta?
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

swiebertje
Posts: 2
Joined: Sun Jul 25, 2021 7:19 pm

Re: PI-CI: prepare a Raspberry Pi image using a VM

Sun Aug 01, 2021 1:38 pm

Great questions, let me answer them in order.

@Botspot, Your vdesktop and pi power tools projects look really interesting! Also goes to show that we were both running into the common problem of (SD) configuration management. The main difference between our approaches (if I understood correctly) is that vdesktop and pi power tools run on a physical pi, while PI-CI runs in an emulator on PC. To answer your question: at the moment it does not have a graphical output. This can be added fairly easily, although I'm not planning to as my main goal is automation.

@thagrol
1. PI-CI runs on ordinary PC hardware (AMD64 to be specific). As for OS, PI-CI runs in a Linux Docker container. I recommend either Linux or macOS with Docker installed. It should be possible to run PI-CI in Docker for Windows, but I haven't tested it. If anyone would like to try, I'd recommend using WSL2. The included RPi distro is RaspiOS Lite 64bit 2021-05-28 with a custom (downgraded) kernel for emulation compatibility (rpi-5.4.y to be specific).

2. From a stablity point of view 32 bit would've been better. I chose to develop PI-CI for 64 bit to ensure that the concept is future proof. Creating an additional 32 bit image should be easy now that the whole process already works. Will keep this in mind!

Return to “Other projects”