Setting up Raspbian on Mac and image cloning for easier deployment(2021)

I had an old post here that details the setup of Raspbian Lite on Mac, now I am going to give an updated method to setup Raspberry Pis. The Pi will be used mainly as a development device and middleware component. As such work will be primarily done in Docker for easier deployment in the future. So after setting up the Pi, we will be focused on setting up the Docker as well.

Installing Raspbian

  1. Start by downloading the image from the official website. As of writing this is kernel version 5.10 based on Buster.
  2. Download Etcher app here, this will be used to flash images to the micro SD card.
  3. Flash the image to the card using Etcher.
  4. Enable the SSH on Raspberry Pi in headless mode via:

Eject the card first if it was fresh from being flashed and plug in again and access the boot folder in the sd card. This might be different depending on your system.

cd /Volumes/boot
touch ssh

Eject the card.

  1. Insert the card to the Raspberry Pi and plugin all the needed peripherals and cables (mice, keyboard, ethernet and HDMI)
  2. Power up the Raspberry Pi and login using the credentials
raspberrypi login: pi
Password: raspberry
  1. From here do the needed sudo raspi-config steps that were the same as detailed in the previous post.

Installing Docker

Pretty simple and straightforward to install Docker, just follow the steps here:

  1. Download the convenience script and run
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# not sure if this next line is still valid but i did it anyway.
sudo usermod -aG docker pi
  1. Test your docker installation by running:
sudo docker run hello-world
  1. A new image is needed since the previous images i created for some reason either won’t work or are outdated. Here is a preferred base image.

Installing necessary packages

sudo apt-get install python3-pip libffi-dev
sudo apt-get install git vim docker-compose

Getting docker images for the middleware

This step is only for me and people that will use my middleware. and mostly this is so i don’t forget steps.

  1. git clone https://github.com/linusmotu/IFoT_AnomalyDection_Worker.git
  2. cd IFoT_AnomalyDetection_Worker.git
  3. docker-compose -f docker-compose.yaml up

It will get the image from the repository and start the container. Now you need to verify on your broker that the device’s heartbeat is being received.

However, since ARM is different from x86 which was used in the Dockerfile in the middleware we have to adjust it.

We can create a new Docker image using arm debian build as shown in the Dockerfile below.

FROM arm32v7/debian:buster

RUN apt-get update -yqq \
				&& apt-get upgrade -yqq \
				&& apt-get install -yqq --no-install-recommends \
				apt-utils \
				build-essential \
				cmake \
				pkg-config \
				vim \
				git \
				gdal-bin \
				libgdal-dev \
				python3-pip \
				libffi-dev \
				libspatialindex-dev \
				libatlas-base-dev \
				sqlite3 \				
				&& apt-get purge -y --auto-remove \
				&& rm -rf /var/lib/apt/lists/*
					
ENV PYTHONPATH="${PYTHONPATH}:/usr/lib/python3/dist-packages"

ENV PIP_EXTRA_INDEX_URL=https://www.piwheels.org/simple

WORKDIR tmp
RUN wget https://download.osgeo.org/proj/proj-8.0.1.tar.gz
RUN tar xvf proj-8.0.1.tar.gz
WORKDIR proj-8.0.1
RUN ./configure
RUN make
RUN make install
RUN ldconfig

RUN pip3 install -U pip3 setuptools wheel \
				 && pip3 install fiona \
				 && pip3 install pyproj \
				 && pip3 install pandas \
				 && pip3 install osmnx \
				 && pip3 install rtree \
				 && pip3 install shapely --no-binary shapely \
				 && pip3 install geopandas \

This will ensure that your Docker will work with the middleware or better to say that the middleware will run on the Docker and use the latest packages possible.

References:

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.