Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docker build and runtime config #296

Merged
merged 6 commits into from
Jan 3, 2025

Conversation

phaseloop
Copy link
Contributor

@phaseloop phaseloop commented Dec 27, 2024

TL;DR

Fix various docker issues:

  • bump python version to something that understands types
  • python3-libgpiod package is not working in python docker images because of version discrepancy. pip3 package with gpiod needs to be installed inside container
  • mount local code and config inside container for easier development and testing
  • create separate .ini config for docker (mostly to print logs to console)
  • use simulation hardware by default to have something workable out of the box instead a bunch of exceptions

What

What is affected by this PR?

  • [ X] API
  • GUI
  • Hardware Integration
  • [X ] OS/Deployment
  • Documentation
  • Other (please describe in notes)

@fall-byrd
Copy link
Contributor

These changes look good to me however I've been developing sans docker. If I get some extra time in the near future I'll do some testing with these changes

Copy link
Contributor

@fall-byrd fall-byrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and seems to be working from what I can see

simple-pid==2.0.0
waitress==3.0.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch, I must have missed that in one of my commits

docker/api_dockerfile Outdated Show resolved Hide resolved
Comment on lines 14 to 17
# - /dev/gpiomem:/dev/gpiomem
# /dev/ttyUSB0:/dev/ttyUSB0
# /dev/ttyUSB1:/dev/ttyUSB1
# /dev/ttyACM0:/dev/ttyACM0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change these lines to this:

    #      - "/dev/ttyUSB0:/dev/ttyUSB0"
    #      - "/dev/ttyUSB1:/dev/ttyUSB1"
    #      - "/dev/ttyACM0:/dev/ttyACM0"
    # If using pi uncomment these lines:
    #      - "/dev/gpiomem:/dev/gpiomem"
    # If using potato uncomment these lines:
    #      - "/dev/gpiochip0:/dev/gpiochip0"
    #      - "/dev/gpiochip1:/dev/gpiochip1"

For whatever reason when I tested this docker compose didn't like some of these fields not being enclosed in quotes, even though it worked for others. I don't know why, version difference maybe, but having them all quoted worked fine. The gpio devices are also different depending on which sbc you're using so that needs to be added and documented

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird - can you check if the reason is having each line hyphenated or is it both hyphenation and quotes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah brain fart, it does only need the hyphenation, quotes are unnecessary. Without either you get a confusing error message and I had tried quotes first which gives a more helpful error message about needing hyphenation, so I had assumed it was both.

Strangely having only two device lines, with only the first hyphenated and neither quoted does build and startup without error, but the devices don't get properly mapped. It's only 3 or more device lines with only the first hyphenated when errors start occurring for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, maybe some yaml parser bug - anyway I updated to file to fix this list.

docker-compose.yml Outdated Show resolved Hide resolved
Comment on lines 4 to 11
RUN apt-get update && apt-get install -y build-essential python3-libgpiod
RUN apt-get update && apt-get install -y build-essential
COPY backend/requirements.txt .

RUN pip3 install -r requirements.txt

# python-libgpiod does not work on docker images
# as it targets python 3.7 (??)
RUN pip3 install gpiod
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why the python3-libgpiod package isn't working anymore in docker, it isn't a python versioning issue since I'm using that with python 3.11 on my pi just fine, but just installing gpiod through pip also doesn't work because they updated the api of the library in version 2 so it just errors on trying to load the device. The old version 1.5.4 also doesn't work, though I can't remember exactly why.

Ultimately we probably just need to update the gpiod code to use the new version 2 of the library and move away from using the system package entirely, but that's outside of the scope of this PR and since I don't think there's a different quick fix for this best thing is just to add a note somewhere saying gpio doesn't work with docker and make an issue for upgrading gpiod.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it seems it is a clusterfuck of bugs. First of all it's about python docker image - for whatever reason python3-libgpiod available in apt repository for this image is built against python 3.7 and python 3.11 just does not even try to load those share libraries on start.

Also it seems python3-libgpiod was abandoned at version 1.5.4 and all development moved to v2. I'll add GH issue to fix compatibility but sadly I don't use any SBC as I think Raspberry Pi is a shit abomination of modern computing and electronics design.

@0phelia36 0phelia36 merged commit 94bfa1a into FourThievesVinegar:master Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants