A tutorial on continuous integration and deployment on Raspberry Pi machine. This tutorial targets to connect the dots to have successful CI/CD pipeline for an application. In this tutorial, we're building a minimal flask application which can be deployed to our Raspberry Pi machine with just a push to GitHub repo.
- A GitHub repository where you can host your source code and then use GitHub actions to push the code to Raspberry Pi.
- Raspberry Pi setup so that we can connect to it using
SSH
from a dev machine. - A stable internet connection, which I'm sure you have as you're reading this page.
Let's start!
- Create a folder into a local machine
mkdir rpi-cd-tutorial && cd rpi-cd-tutorial
- Clone this GitHub repository into a local machine
git clone https://github.com/peeush-agarwal/rpi-cd-tutorial.git
- Create a virtual environment and then activate it
python3 -m venv rpi-dev source rpi-dev/bin/activate
- Change directory to
src/
by runningcd src
- Install the dependencies by running
python3 -m pip install -r requirements.txt
- Test the flask application using the following steps:
export FLASK_APP=app.py flask run --host=0.0.0.0
- Browse the url http://127.0.0.1:5000/ in the browser. If you see
Welcome to the Raspberry Pi web application!
in the browser, then your Flask application is running successfully. Otherwise, check for errors in the terminal where you ran commands in Step 6. - Now, we have our Flask application tested locally, we would like to build a docker container.
docker build -t rpi-cd-tutorial .
- Run the docker container
docker run -p4000:4000 rpi-cd-tutorial
- Browse the url http://127.0.0.1:4000/ in the browser. If you see
Welcome to the Raspberry Pi web application!
in the browser, then the docker container is running successfully. Otherwise, check for errors in the terminal where you ran commands in Step 9. - Now, we have our Docker container tested locally, we would like to host it on the Raspberry Pi.
- Push the source code to your GitHub repository, a new GitHub Action deployment will start on the Raspberry Pi machine.
- Once the request has been processed in the Raspberry Pi, open another terminal in Raspberry Pi via SSH and run command:
If you see the docker container with image name 'rpi-cd-tutorial:xxx', then the setup is successful.
docker ps
- You can try browse http://{Raspberry-Pi's IP address}:4000/ in the browser and check if you see
Welcome to the Raspberry Pi web application!
.