Git Product home page Git Product logo

rpi-cd-tutorial's Introduction

Continuous integration and deployment on Raspberry Pi

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.

Detailed blog

Pre-requisites

  1. A GitHub repository where you can host your source code and then use GitHub actions to push the code to Raspberry Pi.
  2. Raspberry Pi setup so that we can connect to it using SSH from a dev machine.
  3. A stable internet connection, which I'm sure you have as you're reading this page.

Let's start!

Getting started

  1. Create a folder into a local machine
    mkdir rpi-cd-tutorial && cd rpi-cd-tutorial
  2. Clone this GitHub repository into a local machine
    git clone https://github.com/peeush-agarwal/rpi-cd-tutorial.git
  3. Create a virtual environment and then activate it
    python3 -m venv rpi-dev
    source rpi-dev/bin/activate
  4. Change directory to src/ by running
    cd src
  5. Install the dependencies by running
    python3 -m pip install -r requirements.txt
  6. Test the flask application using the following steps:
    export FLASK_APP=app.py
    flask run --host=0.0.0.0
  7. 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.
  8. Now, we have our Flask application tested locally, we would like to build a docker container.
    docker build -t rpi-cd-tutorial .
  9. Run the docker container
    docker run -p4000:4000 rpi-cd-tutorial
  10. 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.
  11. Now, we have our Docker container tested locally, we would like to host it on the Raspberry Pi.
  12. Push the source code to your GitHub repository, a new GitHub Action deployment will start on the Raspberry Pi machine.
  13. Once the request has been processed in the Raspberry Pi, open another terminal in Raspberry Pi via SSH and run command:
    docker ps
    If you see the docker container with image name 'rpi-cd-tutorial:xxx', then the setup is successful.
  14. 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!.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.