Setting up CHIP environment easily and repeatedly

Added by J. Simmons about 7 years ago

Introduction

Holoseat needs an easy and repeatable process for setting up the dev/runtime environments on CHIPs and CHIP Pros. We need this process to support several initiatives.

  • Ensure consistent development environments across physically distributed team
  • Simplify setup steps for volunteers (and staff)
  • Simplify setup steps for production units

One view of these needs is to say we are looking for a Holoseat platform for the CHIP systems we are using. Now that Docker has been run on CHIPs we can look at using Docker to create a Platform as a Service (Paas) methodology to address these needs. As an added bonus, we can publish our Docker images to the larger CHIP and Docker communities to build credibility as NodeBots on CHIP authorities since these are core technologies for Holoseat.

Implementation Plans

Based on Building Your Own Paas with Docker, we will need at least two containers: a data volume container and a NodeBots container. Additionally, we may need a database container assuming we can find something lightweight enough to run on the CHIP (e.g. LevelUp/LevelDB). Note, I am leaning to storing this info in files on disk, but I don't want to rule things out.

There is also the question of if the containers can connect to the CHIP IO pins. Based on a blog post about Docker and Raspberry Pi and this stack overflow thread it looks like pin access in a container is just a matter of passing the correct devices to the container on startup.

We will also want to consider how we can separate general community needs (e.g. Node.js, Node.js + Johnny-Five) from Holoseat needs (developers need svn and a checkout of the firmware code from Holoseat repo, production units need the firmware without the overhead of svn). All of this also begs the question how much of this has already been done in the Docker community and how much can we reuse.

The following is a draft outline of steps to take towards implementation:

  1. Get Docker installed on a CHIP <find link(s)>
  2. Test out some base images to determine what we can reuse from the CHIP and Docker communities (e.g look for supported Node.js, and investigate running BusyBox)
  3. Test IO pin access from containers, test HID interaction from containers, and test lightweight databases
  4. As needed, build up required base Docker images we can share (based on CHIP research, which still needs some documentation work)
    1. Node.js
    2. Johnny-Five plus chip-io (on top of Node.js, installed globally so the build steps are done?)
  5. SSHD
    1. ...?
  6. Create Holoseat dev image by adding (in layers?)
    1. Data volume
    2. SVN
    3. Dev directory structure
    4. Samba
    5. SVN checkout of firmware from trunk
    6. ... any missing steps from CHIP research?
  7. Later create a production image as needed

If all goes according to plan, setting up a new CHIP should be as easy as

  1. Flash with updated OS
  2. Configure wifi - desktop app will automate this step later
    1. Login over serial
    2. Set up wifi
    3. Logout of serial
  3. Login over ssh
  4. Install Docker
  5. Grab dev images
  6. Set Docker images to auto-start
  7. Reboot
  8. Login to dev container over wifi and connect to samba
  9. Start coding

Replies (14)

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons about 7 years ago

Just a couple of new developments on this thread. First, Docker is officially supported on CHIP/CHIP Pro. Second, Bryan has some concerns about using Docker with the available storage on CHIP Pro, which bears research and testing.

Third, not only is Docker supported, there are Next Thing demos of using Docker on Chip Pro. They call this approach CHIP-tainer. Here are three examples from their github repo.

I think the next step is to get a CHIP Pro set up with Docker, run one or two of these demos, and then look at metrics (e.g. available disk space, processor load, memory). After that, it will be time to start trying to make our own Docker images.

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons almost 7 years ago

This work is now part of 2017 Sprint 2 (DEV-23: Test Nodejs then Johnny-Five in chiptainer enviroment to determine if we want to use chiptainer approach). Based on notes above, I am planning to test out VU Meter demo provided by Next Thing. A couple of quick notes before I start my work. This demo requires the CHIP Pro Dev Kit. The current OS install on my CHIP Pro Dev Kit is the Blinkenlights image (this is an example build-root image that blinks all of the LEDs). I have checked, and it does not have Docker pre-installed and the standard Docker install commands do not work in this environment. Contrast this with this message from Bryan that Docker is included when we make our own copy of build-root. A little more digging by Bryan shows us that his CHIP Pro is running Docker 1.12.2.

My plan is to install the Debian image on my CHIP Pro and then try to follow these instructions to install Docker on CHIP. I am hoping this test will provide an answer to the forum post Is Chip Pro Docker ready?.

One final note. I noticed problems flashing my CHIP Pro from Windows 7, but on the other hand serial access from OS X is painful. So, my plan is to flash the OS from my Mac and then switch to my Win 7 box to login over serial to set up wifi.

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons almost 7 years ago

CHIPtainer Example: VU Meter Test

  1. Initial setup
    1. Flash Chip Pro Dev Kit with "Pro" image (Debian install) from Mac per dev kit instructions
    2. Install wifi antenna that came with dev kit per wifi antenna instructions
    3. Connect to the CHIP Pro from Win 7 per serial connection (Windows) instructions
      You may see boot messages stream by
    4. Login with default user/password: chip/chip
    5. Enable the attached wifi antenna
      Neither the set_antenna script nor obvious access to a text editor are included with this image. So, the following steps show how to manually configure the CHIP Pro to use the connected wifi antenna. The following text should be run exactly as shown. For the sudo command, remember the default password is chip
      1. sudo bash
      2. echo 49 > /sys/class/gpio/export
      3. echo out > /sys/class/gpio/gpio49/direction
      4. echo 1 > /sys/class/gpio/gpio49/value
      5. echo 49 > /sys/class/gpio/unexport
      6. exit
    6. Enable wifi per the Debian wifi instructions
  2. Install Docker
    Based on Docker is supported on the $9 C.H.I.P. computer
    1. The first three steps are covered by the work above
    2. For this test we will skip Step 4 (Configure SSH to access the C.H.I.P.)
    3. Step 5 is to check the kernel version (we need a build more recent than 4.4.13 dated Dec 6, 2016). Below is the output I get from Step 5.
      chip@chip:~$ uname -a
      Linux chip 4.4.30-pro #1 SMP Wed Dec 21 01:50:18 UTC 2016 armv7l GNU/Linux
      It looks like we can safely move onto Step 6
    4. Remember to run the install command under sudo: sudo curl -sSL https://get.docker.com | sh
      Running under sudo might not have been necessary, there are calls to sudo in the install script. This is interesting, the docker install script reported missing features and then started updating apt-get and installing those missing features.
    5. Per comment at the end of the Docker install script, add chip to the docker group
      sudo usermod -aG docker chip
    6. Log out and then login back into the CHIP Pro to get the group membership to take effect
    7. Check the Docker version by running docker --version
    8. Clean up space by running sudo apt-get clean
      My results show Docker version 17.04.0-ce, build 4845c56 which differs from the version Bryan is running (1.12.2).
  3. Testing the VU Meter CHIPtainer
    1. In theory, this is just a matter of following the instructions
      Except, apparently you will need a login for https://ntc-registry.githost.io (just head to that page and sign up for an account). Well that did not work. It looks like registration is restricted (I got the following error: "Email domain is not authorized for sign-up")

New plan for basic testing. I am going to run the test from the Docker is supported on the $9 C.H.I.P. computer instructions (Step 8).

  1. docker run -d -p 80:80 hypriot/rpi-busybox-httpd
  2. Get the CHIP Pro's ip address: ip addr
  3. Open the CHIP Pro's ip address in a web browser

Success!!!

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons almost 7 years ago

After reviewing the Docker files and re-reading Packt's Docker Cookbook, I think I can get the CHIPtainer example working. I say example (and not examples) because the three links above together build up to a single example, the VU Meter. You see, the VU Meter image is built upon the Python IO image. And the Python IO image is built upon the Alpine image.

If I am starting to get the hang of the things I have been reading, I think the basic set of steps to get things running are:

  1. Build Alpine image from its Docker file
  2. Publish the Alpine image in a public registry
  3. Update the Python IO Docker file to reference the publicly hosted Alpine image
  4. Build the Python IO image from the updated Docker file
  5. Publish the Python IO image to a public registry
  6. Update the VU Meter Docker file to reference the publicly hosted Python IO image
  7. Build the VU Meter image from the updated Docker file
  8. Publish the VU Meter image to a public registry (this is not strictly required, but it is nice)
  9. Test out the VU Meter CHIPtainer

Tonight I will be setting a few things up and just testing out the general theory. See next post for engineering log.

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons almost 7 years ago

Prep Work

So, first things first, I am going to need a local text editor and git, so time to install a couple of packages (followed by cleaning up disk space).

  1. sudo apt-get install nano - I am not too proud to use nano for quick and dirty work
  2. sudo apt-get install git
  3. sudo apt-get clean

Testing

Now to run our test. I am going to try to build the Alpine image in a temporary testing directory.

  1. mkdir ~/docker-test
  2. cd ~/docker-test
  3. git clone https://github.com/NextThingCo/chiptainer_alpine.git
  4. cd ./chiptainer_alpine
  5. ./build.sh
  6. rm ./qemu-arm-static.tar.gz - cleaning up files we downloaded for the image
  7. rm ./rootfs.tar.gz

So far, so good. Docker reported that it successfully built the image. And running docker images shows the nextthingco/chiptainer_alpine image is there. Well that worked so well, let's try the next level (without publishing things to a registry).

First, after a little bit of digging I found someone posted a pull request for the Python IO Docker file. So, I forked this version of Python IO and then forked the NGC versions of Alpine and VU Meter. I then cloned my Python IO into my docker-test directory and edited the Docker file for Python IO to change the FROM line from FROM ntc-registry.githost.io/nextthingco/chiptainer_alpine to FROM nextthingco/chiptainer_alpine. And I ran the build.sh for Python IO. The build.sh reported the build was successful.

I think that is enough for tonight. Tomorrow I will run some tests on the Python IO image by starting a container. And if that works, I will use a similar process to build the VU Meter image. And if all that works I will start publishing the images and updating the Docker files and READMEs to make things just work out of the box.

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons almost 7 years ago

Next step is to test the Python IO image. The following are updated instructions from the the NTC instructions.

  1. docker run -v /sys:/sys --cap-add SYS_RAWIO --device /dev/mem -it nextthingco/chiptainer_python_io
    The following commands are from within the Python IO container
    1. python
      The following commands are from within Python environment
      1. import CHIP_IO.GPIO as GPIO
      2. GPIO.setup("CSID3", GPIO.OUT)
      3. GPIO.output("CSID3", GPIO.HIGH) # LED D3 should light up
      4. GPIO.output("CSID3", GPIO.LOW) # LED D3 should go out
      5. exit()
        Exits Python
    2. exit
      Exits container

This test was a complete success (thought it did involve some additional changes to the demo instructions from NTC).

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons almost 7 years ago

So, now it is time to get VU Meter running. So, back to the docker-test directory and now time to build the VU Meter code from my fork.

  1. cd ~/docker-test
  2. git clone https://github.com/modelb-jrs/chiptainer_vu_meter.git
  3. cd chiptainer_vu_meter
  4. Edit Dockerfile and update FROM line to FROM nextthingco/chiptainer_python_io
  5. ./build.sh
  6. docker run --name vu-meter --privileged --cap-add SYS_RAWIO --device /dev/mem -v /sys:/sys -ti nextthingco/chiptainer_vu_meter

Success, for a moment or two, then I received a "Program Closed" message and returned to the host OS prompt. The same thing happened when I restarted the VU Meter container. A little digging in the source code for the VU Meter shows it only runs 10 iterations and then displays "Program Closed". So, there you have it, total success!!!

Next steps are to clean up the files in my forks on github and publish the images to a public repo so people outside of NTC can just run the VU Meter example.

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons almost 7 years ago

This afternoon I set out to take all that I had learned from my previous experiments and wrap it all up in a published version of the NTC CHIPtainer examples. I am very happy to report I was completely successful. You can try things out for yourself by following the instructions over at the public repo for the VU Meter example. Just scroll down and follow the instructions in the README section.

I plan to post a few notes about tricky places and some helpful commands I found tomorrow.

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons almost 7 years ago

Some useful Docker commands (and sources)

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons almost 7 years ago

While trying to build a Node.js CHIPtainer I quickly ran out of room on my CHIP Pro. This is not really surprising, but I was hoping the issue would come up later. So, for short term development, I have added a USB drive to my Dev Board, set it to automount, and switched Docker's root dir to be the USB drive. Below are my config changes.

format flash drive
sudo mkfs.ext4 /dev/sda

file system
sudo mkdir /mnt/usb

/etc/fstab
/dev/sda /mnt/usb ext4 defaults 0 0

more file system work

sudo mount -a
chmod 777 /mnt/usb

/etc/docker/daemon.json # new file
per https://docs.docker.com/engine/admin/systemd/#runtime-directory-and-storage-driver

{
    "graph": "/mnt/usb",
    "storage-driver": "overlay" 
}

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons almost 7 years ago

And one more problem needed to be overcome... I received the following error when trying to build the Node.js CHIPtainer:

virtual memory exhausted: Cannot allocate memory

After some googling, I realized that the CHIP has 0 swap (just check out the results of running free -m). So, then I found the following instructions which fit very nicely with the work I had already done to set up a larger build environment on my CHIP Pro.

sudo dd if=/dev/zero of=/mnt/usb/swap.file bs=1M count=512
sudo chmod 600 /mnt/usb/swap.file
sudo mkswap /mnt/usb/swap.file
sudo swapon /mnt/usb/swap.file

The results of the build this time (after running for several hours - I really need to get a cross compile environment set up) were successful. Next up, some testing.

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons almost 7 years ago

So, lots of news. I only have time for the TL;DR tonight.

  • Using the swap file allowed the build to complete
  • The new image did not include npm
  • During missing npm troubleshooting, discovered the build of alpine we are using has nodejs
  • Started testing the alpine node-js packages -> nodejs 7.2 can be installed with apk add nodejs-current
  • Then started working on getting johnny-five to install
    • Eventual success (more details later)
    • Discovered that chip-io for node is not current for CHIP Pro (yay! another CHIP vs CHIP Pro issue)
    • Fixing chip-io for CHIP Pro is more work than I have time for right now (mostly because I don't know enough about the low level stuff)

The good news is the CHIPtainer stuff really does work, and if we mostly stay with apk packages and small builds, I think I can revert my changes to use the USB drive even on CHIP Pro. The bad news is we are not at a place where for v0.4 we have to decide between using nodejs and the CHIP Pro. If we go with nodejs we need to revert to CHIP. If we use CHIP Pro, we are probably looking at Python 2.7 as that is the only supported version on Alpine apparently.

RE: Setting up CHIP environment easily and repeatedly - Added by J. Simmons almost 7 years ago

I have just completed the CHIP Pro/Python testing and it was a huge success. Not only that, but it was all conducted inside a CHIPtainer, meaning we have successfully demonstrated that CHIPtainers will work for us. And with that, we can call "DEV-23: Test Nodejs then Johnny-Five in chiptainer enviroment to determine if we want to use chiptainer approach" done (with the caveat that we will be using Python instead of nodejs).

(1-14/14)