This is a first post of series of posts on using Jenkins+Docker for developing embedded applications on a Raspberry Pi. This is a multi part tutorial:
Part 1: We set up Cross Compile Using Docker, build a simple C code and test it manually on Target
Part 2: We install Jenkins to automate the build/deploy/test.
Part 3: We set up a local server for Git instead of Github to automate pipeline on each commit.
Step 1 – Ubuntu Server
We are using a VMWare VirtualBox to setup the build server. Download ISO image of Ubuntu Server 20.04 LTS from here (Size 1.17GB).
we create new Virtual Machine using this image with 20GB of storage and 4GB RAM.
Don’t forget to set Network to “Bridged Adapter” so we can have access to a Raspberry Pi in our local network.
Step 2 – Installing Docker
For Docker installation, this guide from Digital Ocean is the best. follow both steps 1 and 2 to install docker and add your user to “docker” group so you can run docker without sudo privilege.
Step 3 – Cross Compile Using Docker
You can create your own docker image using a custom DockerFile but as always with anything related to Raspberry Pi, there is always already job done! So we are using dockcross [Github, Docker Hub].
For a Raspberry Pi 3 with kernel 5.10 Buster image we are using linux-armv7-lts image with following command:
docker run --rm dockcross/linux-armv7-lts > ./dockcross-armv7-rpi
Depending on your Internet connection speed this would take a while. The resulting image is 1.76GB in size.
We will use the resulting bash script saved in the file:
dockcross-armv7-rpi. So we need to make it executable:
chmod +x dockcross-armv7-rpi
Now we can easily use this script to Compile our C codes. For example save the following simple “Hello World” code in a hello.c file:
int main(int argc, char *argv)
printf("Hello cross-compilation world!\n");
With the following command we build it:
./dockcross-armv7-rpi bash -c '$CC hello.c -o hello_arm'
Then we transfer the binary result to a Raspberry Pi with the IP address of 192.168.1.120
scp hello_arm firstname.lastname@example.org:/home/pi
And on the Raspberry Pi we manually run it:
pi@raspberrypi:~ $ ./hello_arm
Hello cross-compilation world!
That’s it for the first part. If you have any questions please do not hesitate to ask.