Thursday, December 1, 2022

Into the world of 3d printing

I have long been interested in 3d printing, but I have mostly had other people print for me.  I got myself a Prusa MK3s+, and have been doing the SD card shuffle to get my prints to the printer, which has been working flawlessly.  


I have a raspberry pi lying around, but for reasons I cannot figure out, my previous install had docker, docker-compose, and k3s installed on it.  Whenever I accessed the pi, I would always get a 404, and I didn't see any processes listening to 80/443 on my system.  There was probably something that the k3s install had done, but I wasn't able to track it down.  

To verify that I didn't have some other phantom issue on my network, I pulled down the latest copy of raspbian, cloned https://github.com/OctoPrint/octoprint-docker and went to install docker-compose, using the way I knew (which was apparently the 'old way'), through pip.

I tried to `sudo pip3 install docker-compose` and ran into an error that I hadn't seen before when installing python modules.... `error: can't find Rust compiler`...  One of the dependencies of docker-compose is the cryptography package, and the newest version that was being pulled in now requires rust to build it.  The error message itself and various resources online said they've fixed it by updating pip... `sudo pip3 install --upgrade pip`, but that didn't solve my problem.  

I installed the rust tools `sudo pip3 install setuptools_rust` but it still failed the same way.  I installed the packages for my raspberry pi using apt( `sudo apt-get install cargo`, but they had to old of a compiler... The dependency required 1.56, and the package installed for raspbian was 1.42.

I followed the instructions from the error installing the crypto module, and that wanted me to use `rustup` to manage my rust version.  I pulled down the rustup installer, and that went fine, but when I tried to install docker-compose with sudo (a mistake, but oh well, I'll be reinstalling the OS onto my harddrive instead of an SD card later), the install of docker-compose still failed, due to my user having rustc on their path, but the root user not having it.  So I switched to a root shell, installed rustup, and was able to run my pip install of docker-compose.


As a side path, while I was trying to figure out how to install docker-compose, I saw some mention that the python version was v1, and v2 was a statically linked go binary to run as a docker plugin.... which led me to having to do a little  bit of manual fighting with https://github.com/docker/compose ... The install script was detecting me as arm64, but I had installed the 32 bit OS, and my system reported as arm7.  So I had to manually download the correct build, and update the binary to use that instead of what it pulled down.


the Octoprint-docker guides are all using the old docker-compose syntax, so I needed to use  utility called compose-switch to convert my syntax for me..... one problem, they didn't build the arm7 binary, only amd64 and arm64 (I had installed the 32 bit os..) 

So no problem right?  Someone even had a snippet in a github issue to cross-compile it using the go toolchain in a docker run on my laptop then copy it over to my pi...   But when I was following the advice in the last comment in the issue thread, they mentioned that the initial poster had the path wrong, but I was getting an error during the `docker cp` step... After a bit of digging, it turned out the initial suggestion of copying from /go/bin/linux_arm/compose-switch was correct, and /go/bin/compose-switch was wrong.  Once I fixed that up, I could copy over the compose-swich binary and manually follow the setup steps to set compose-switch as the etc-alternatives for docker-compose, which would remap my commands to `docker compose`.  


Once I fixe all the above, I was able to run `docker-compose up -d` and see octoprint running on my pi!


I didn't have my printer plugged in yet, but I was seeing the interface and not getting a 404 when trying to contact my pi.  

I did want to verify that the webcam worked properly, and I had to remember to go into `raspi-config` and enable 3. Interface Options and I1 Legacy Camera Enable.  Once I did that (and rebooted), and updated my paths for my camera according to the octoprint docker image readme, and added the right env vars and devices to my docker compose file (uncommented from the octoprint-docker provided docker-compose.yml file, I was able to see my camera stills/stream from within the Octoprint UI.


Lots of jumping around for something that I thought was going to be about 3 commands from a fresh raspbian install!