I’m going to try a new thing. I keep a million tabs open all the time, and I’m pretty tired of it. I also need a place to keep track of projects and my line of thinking while working on them. I’m so often interrupted in the middle of a project and can’t get back to it for weeks or months, and when I open a project file, it takes me forever to figure out my train of thought or what I was even working toward. Maybe with some notes and links I’ll be able to keep track of this stuff so I can get back up to speed faster. Maybe not. But it’s worth a shot.
I’ve been keeping paper notes of my latest project. It filled a bunch of space, so it’s hard to jump around and see important bits at a glance. I’m going to type these up here with the hope that I will be able to search for them in the future.
raspberry pi image / docker image of people counter app
2 july
Trying to think through this imaging thing…
What if I…
- fork noobs image on GH
- install Docker on image
- user Docker to pull down people-counter app locally
- push back up to cloud
But how would I pull down raspberry pi updates/upgrades? Obviously docker will run my app on whichever version of raspbian I want, but to keep the pis secure, I’ll need to be able to pull down upgrades of OSes via apt-get unattended-upgrades
Other things to do (see 5 best basic security tips):
- delete user pi
- set up SSH
- auto-update/auto-upgrade
I’m having a hard time wrapping my brain around this, but maybe pretend I want to run this at home… I don’t have raspbian installed on my home machine, but my people-counter image will have raspbian. I’m caught up on why I need raspbian on the SD card and in the Dockerfile, but I think the previous is why. Docker will run whichever version of raspbian I want, even if my Pi is auto-upgrading. See Simple way to build a custom Docker-ready raspberry pi image.
3 july
I think I figured out the docker container mess, so onto creating an image for people-counter.
Steps I took
- create new directory
docker-container
cp gate-counter.js
from old dir =>docker-counter
- create a
package.json
folder with dependencies - run
npm init
- run
npm install --save
(packages from README) - run
sudo node gate-counter.js
to make sure it initializes GPIOs - create Dockerfile, .dockerignore
- added script
start: sudo node gate-counter.js
topackage.json
- build testing!
$ sudo docker build -t carylwyatt/docker-counter
- build failing during step 4: npm install
- thought it might be related to sudo issues, so I added ‘pi’ as
$USER
to docker, but still failing - tried to install each package individually to figure out which one was causing issues; turns out it’s
raspi-io
raspi-io
README notes: “warning: this module must be installed as a normal user, but run as the root user” whaaaaaaaat.- now trying to figure out how to add user, give permissions, switch user, & npm install
- thought it might be related to sudo issues, so I added ‘pi’ as
- changed users and permissions and still got the error…
- when I get back on 5 july, start by trying to build docker container in
~/new-test
and go from there!
5 july
After getting back up to speed, several stack overflow helper are suggesting either/both clearing the cache npm cache clean
and/or deleting node_modules
. Buuuuuut my .dockerignore
file already includes node_modules
, so those shouldn’t be there anyway, yes?
more steps
Since pigpio
is the hold-up, I RTFM and it has to be installed locally before npm install
- my container only had node, so I tried
apt-get install pigpio
but that failed- error message:
E: unable to locate package pigpio
- error message:
- docs indicated
pigpio
comes installed on raspbian jessie 2016 and later, so I decided to build containerFROM resin/raspberry-pi-node
but got same error (unable to locatepigpio
) - cannot figure out resin’s base images
- there are generic “raspberry pi” but also
- some for RPi 3
- some for RPi 3-node
- but somehow none of them have the latest raspbian, stretch
- there are generic “raspberry pi” but also
- tried
raspberrypi3-node:onbuild
- github file claims it’s Jessie with node v8
- tried installing
pigpio
as dependency inpackage.json
before it was needed, no avail - BUT THIS FIXED IT, YO
- all hail this digital ocean post: How to debug and fix common docker issues
- used
resin/raspberrypi3-node:latest
base image - used
RUN apt-get clean && apt-get update
thenRUN apt-get install pigpio
- which resulted in FIRST SUCCESSFUL BUILD OF IMAGE
- used
- all hail this digital ocean post: How to debug and fix common docker issues
- the app isn’t running inside the container, so that will need to be fixed on monday
- error: looks like an i2c problem, no surprise there
- tried “reboot” of container since I got the message about not using i2c untill restart
9 july
The Docker saga continues to unfold…
i2c-dev
error when trying to run gate-counter app- found an old GH issue from raspi-io repo about getting this error when running johnny-five app from docker
- soltuion seems to involve kernel access
- have tried solution from the issue and the blog post he got the solution from, but have only gotten errors and “permission denied” in return
- error references
modprobe
… no idea what that is - I think the error relates to needing access to a system device (in this case, the GPIOs) but the container doesn’t have permission to access
- the solution probably revolves around these docker commands I don’t understand:
-v
bind/mount a volume--device
add a host device to a container--privileged
give privileges to container
17 july
RasPi people counter saga, continued
i2c-dev
still a problem- checked that it was included in the
/etc/module
config file and that it was not included in the blacklist file - tried enabling
i2c
in$ sudo raspi-config
then reboot - tried adding
modprobe i2c-dev &&
to existingpackage.json
start command - read some nonsense that there are specific raspi pins for i2c… how is my app running normally without being on an i2c pin if an i2c module is what’s holding up the docker container?
$ docker build -t carylwyatt/new-test .
$ docker run --privileged -ti carylwyatt/new-test
- resin suggests using the npm library
pi-pins
to interface with raspi since it has been shown to be reliable - time to abandon johnny-five/raspi-io??
- tried adding to Dockerfile:
RUN apt-get install rpi-update && sudo rpi-update
- is there a way to restart/reboot after install with Docker?
- stack overflows suggest it reboots the container with every start, so maybe the warning about i2c needing to reboot before running has already been taken care of?
Tomorrow: try building fresh app outside of Docker; see if you can eliminate all the node-gyp
, i2c-bus
, pigpio
, serialport
because they’re causing issues
- tried outside install of dependencies (
GCC
,make
,python
), but they already existed
24 july
Digging around on raspi i2c stuff
- my project doesn’t use an i2c pin
- but the build –and specifially the
npm install
step– keeps getting hung up on a module for i2c- it builds the container… successfully?? … but has a bunch of warnings about libraries not being installed correctly
- can I delete this module?
- how would I remove from package.json dependency list?
- recreate repo & branch test?
2 aug
Current day. Spent about an hour writing up this post, and it helped me remember where I am in this project. I’m still wondering what road to take. The way I see it, I have three options:
- remove dependencies my app doesn’t rely on, especially i2c stuff
- use a the resin-recommended GPIO library and rewrite gate-counter/people-counter app
- build docker container from a different base image and hope i2c is no longer an issue
…or burn it all down and start over. Maybe I should install raspbian jessie on a new SD card and try to npm install dependencies. I’m just so confused about how my app is running in my current raspi environment but the docker situation is completely melting down.
“Only time will tell, my friends!” - Michael Scott, Casino Night
3 aug
It’s been a month since I started this whole Docker/raspi imaging fun. Let’s see if I can wrap it up.
I’ve decided to try building a new image from a different base image: schachr/raspbian-stretch
$ mkdir pi-stretch
- copy files from current project into this directory: Dockerfile, package.json, gate-counter.js
- deleted
pigpio
from package.json dependency list (it’s not original to the app, I added it sometime during testing) - commented out “extras” in Dockerfile
- added a new FROM command:
FROM schachr/raspbian-stretch:latest
$ npm install
so I can double check my app dependencies are installing correctly- turns out, the same errors I was getting in my container are happening here, too.
- looks like this is not a jessie vs stretch issue, so I’ll be abadoning that route
Went back and looked at the errors from the npm install. The largest chunk of errors is from attempting to install serialport
. I found the github repo and started devling through the issues, and surprise surprise, I’m not alone in this. Most of the issues similar to mine mention Docker.
- tried creating new directory with
johnny-five 0.12.0
as dependency, but still tried to installserialport 6.2.2
- wandering around the serialport issues trying to find something that makes sense
- read something about using the CMD command to
npm install serialport
after the build just before starting the app, so I switched over to new-test again and tried taking out the extra stuff and adding the install- this did not work
- I did make it to the npm install part once I ran the container, but it just kept installing in a loop, over and over
- I switched back to another directory to try installing
serialport
on its own, but it gave me the same “no prebuilt binaries” error message
It’s 4pm, so it’s time to wind down and go sit with Bob, but here are the salient links open in my browser:
- Resin.io forum: Node-gyp fails on serialport
- Resin.io forum: Error on docker build
- Node-serialport issue: Missing prebuild binaries in 6.2.1
- Node-serialport issue: Rpi3 based Alpine can’t build serialport
- which reminds me: alpine node???
I’m still not sure any of this serialport
has anything to do with the main issue of running the app on the device. I reopened an old terminal tab today and remembered that the error I was working through before vacation was a modprobe error. This could be related to the serialport stuff or it could not. I’m still pretty lost in the sauce on all this.