antonengelhardt / kicktipp-bot

A bot which can submit tips for a Kicktipp competition based on quotes.
MIT License
15 stars 5 forks source link

Docker version seems not to work on arm64 (Raspberry Pi) #3

Closed nordcomputer closed 1 year ago

nordcomputer commented 1 year ago

I tried to set up the docker container via docker-compose.yml but it seems not to work on a Raspberry Pi. It is working fine on my main machine (Debian).

My docker-compose.yml:

version: '3'

services:
  bot:
    image: antonengelhardt/kicktipp-bot:latest
    container_name: kicktipp-bot
    restart: always
    environment:
      - KICKTIPP_EMAIL=${KICKTIPP_EMAIL}
      - KICKTIPP_PASSWORD=${KICKTIPP_PASSWORD}
      - KICKTIPP_NAME_OF_COMPETITION=${KICKTIPP_NAME_OF_COMPETITION}

The docker logs:

docker-compose up
Creating network "kicktippbot_default" with the default driver
Pulling bot (antonengelhardt/kicktipp-bot:latest)...
latest: Pulling from antonengelhardt/kicktipp-bot
bbeef03cda1f: Pull complete
f049f75f014e: Pull complete
56261d0e6b05: Pull complete
9bd150679dbd: Pull complete
5b282ee9da04: Pull complete
03f027d5e312: Pull complete
41b6012c8972: Pull complete
e84941e8ff4e: Pull complete
8848ba81439a: Pull complete
5f78639e6ef0: Pull complete
da1870f2e0a0: Pull complete
43afa570d098: Pull complete
879b4ec8dcd2: Pull complete
4f4fb700ef54: Pull complete
de128f633af7: Pull complete
527535a1882f: Pull complete
2d6e99a4b627: Pull complete
901cbeda9d62: Pull complete
81b24fb0f729: Pull complete
Digest: sha256:5b515cd51940284917ae3213a5923aad47cd98213f4b2b7feb2a03419371807f
Status: Downloaded newer image for antonengelhardt/kicktipp-bot:latest
Creating kicktipp-bot ... done
Attaching to kicktipp-bot
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot exited with code 1
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot exited with code 1
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot exited with code 1
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot exited with code 1
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot | exec /usr/local/bin/python: exec format error
kicktipp-bot exited with code 1
antonengelhardt commented 1 year ago

Hi @nordcomputer

Thank you for your issue.

I think the problem is that you didn't set the Zapier_URL env variable but pythons expects it. The docker image is running "python3 main.py" with the options "headless withZapier" (see Dockerfile). So the url is required.

If you want to manually resolve it now there are two possibilities:

  1. build the image on your own and change the entrypoint / cmd in the dockerfile
  2. Provide a valid Zapier url

I will look into multiple image versions in the future.

If you have any more questions please let me know.

nordcomputer commented 1 year ago

Moin @antonengelhardt, Are you sure about that? Because the same .env file (without a Zapier Url) is running fine on my main machine (Debian on an AMD64 cpu). I am going to try your solution tomorrow.

antonengelhardt commented 1 year ago

Moin, @nordcomputer,

i was able to reproduce this.

in the Dockerfile at line 7 the architecture is specified. I created this project on an Intel Machine. I am on M1 now and have the container running on an ubuntu server. I haven't tested this container on my new M1 machine since i got it and therefore your issue is totally legitimate.

I will look into deploying different images for different architecture soon. If you'd like to and found this repo helpful, you can try it yourself and open a MR. Another Dockerfile might be the best approach.

nordcomputer commented 1 year ago

Not this week, but I may look into it next week.

nordcomputer commented 1 year ago

I just forked the repo and tried to get it to run on my pi, but I was out of luck so far.

Instead I tinkered a bit with the main.py file so you can set the hours until tipping via environment variable. I also added an if-clause, to check if ZAPIER_URL is empty.

If you wanna have a look: https://github.com/antonengelhardt/Kicktipp-Bot/compare/main...nordcomputer:Kicktipp-Bot:main

antonengelhardt commented 1 year ago

Hey @nordcomputer

I also haven't looked into the architecture matter.

If you have any suggestions please open a PR šŸ˜ƒ

My list for future features is very long and "checking for env" variables is one of them.

antonengelhardt commented 1 year ago

Hello again @nordcomputer,

Yesterday, I was able to reproduce it on my Pi aswell.

I think creating a second dockerfile and building another step for this image building & pushing is the best approach.

nordcomputer commented 1 year ago

Sounds good - do you really want a Pull Request, as I just edited the docker-compose file and the main.py - I did not look into the other files....

antonengelhardt commented 1 year ago

@nordcomputer

Up to you. But no need

antonengelhardt commented 1 year ago

Hello @nordcomputer,

i was able to build the new image and create a container from the image on M1 Mac and Raspberry Pi 4. I still get an Python error, which i will look into later, but the building and running works.

I used this Dockerfile:

Dockerfile.arm:

FROM python:3.8-alpine

# update apk repo
RUN echo "http://dl-4.alpinelinux.org/alpine/v3.14/main" >> /etc/apk/repositories && \
    echo "http://dl-4.alpinelinux.org/alpine/v3.14/community" >> /etc/apk/repositories

# install chromedriver
RUN apk update
RUN apk add chromium chromium-chromedriver

# upgrade pip
RUN pip install --upgrade pip
COPY . /app
WORKDIR /app

# Install the Python requirements
RUN pip install -r requirements.txt

# Set the entrypoint to run the Python script
CMD ["python", "./main.py", "headless", "withZapier"]

Build it with docker build -t antonengelhardt/kicktipp-bot:arm -f Dockerfile.arm .

antonengelhardt commented 1 year ago

@nordcomputer Also, i found that there is an opportunity to specify the desired platform: https://forums.docker.com/t/run-x86-intel-and-arm-based-images-on-apple-silicon-m1-macs/117123

Simply use

nordcomputer commented 1 year ago

nice, I will give it a try the next days

antonengelhardt commented 1 year ago

Hey again @nordcomputer,

the ARM Image is available now: https://hub.docker.com/layers/antonengelhardt/kicktipp-bot/arm/images/sha256-00c82c0e4b91091c8f6bbdf78a935cabb3eaf086fa23dae1d67a814d9d288c44?context=repo

I built it on my M1 with the Dockerfile from above and pushed it. Works on my M1 and on my Raspberry Pi 4.

Reminder: However i am also able to run the "Latest" Image using the --platform linux/amd64 flag. Maybe this is not possible on Pi, havent tested.

I will check out your PR in the next few days. Good changes šŸ‘šŸ¼ . But i'd like to have two separate Dockerfiles, so that two images are built automatically using GH Actions.

See ya

nordcomputer commented 1 year ago

I was able to build the image on my pi4 and my normal machine with the dockerfile you mentioned above (https://github.com/antonengelhardt/Kicktipp-Bot/issues/3#issuecomment-1484896426) So, I am not sure, but it seems, there is no need for different versions

antonengelhardt commented 1 year ago

@nordcomputer Well, i cannot run the arm image on my ubuntu (amd64) machine, so i guess 2 images are needed. Or am i missing something?

nordcomputer commented 1 year ago

As there is no architecture mentioned in the Dockerfile itself, I just tried to use it on my Debian 12 machine - it runs without any issues... image

antonengelhardt commented 1 year ago

Moin @nordcomputer

What is the Architecture of your Debian machine?

nordcomputer commented 1 year ago

AMD64 - its a Ryzen 5950X image

antonengelhardt commented 1 year ago

@nordcomputer I get this error when i try to run the arm image on my ubuntu amd64 machine:

WARNING: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested

PS: If you mention me, i also get notified about your replies šŸ˜ƒ

nordcomputer commented 1 year ago

@antonengelhardt did you rebuild the image?

antonengelhardt commented 1 year ago

@nordcomputer

No, i built it an hour ago and pushed it to the docker hub. Now there are two tags: latest and arm

nordcomputer commented 1 year ago

@antonengelhardt Also, I use this docker-compose.yml:


version: '3'

services:
  bot:
    build:
      dockerfile: Dockerfile
      context: ./
    container_name: kicktipp-bot
    restart: always
    environment:
      - KICKTIPP_EMAIL=${KICKTIPP_EMAIL}
      - KICKTIPP_PASSWORD=${KICKTIPP_PASSWORD}
      - KICKTIPP_NAME_OF_COMPETITION=${KICKTIPP_NAME_OF_COMPETITION}
      - ZAPIER_URL=${ZAPIER_URL}
      - HOURS_UNTIL_GAME=${HOURS_UNTIL_GAME}
antonengelhardt commented 1 year ago

@nordcomputer I assume that the Dockerfile mentioned in your Build context is the Arm version?

nordcomputer commented 1 year ago

@antonengelhardt As you can see in the Dockerfile I (and you) posted, there is no mention of an architecture anywhere. It should be a plain python:3-8-alpine image - or am I misunderstanding something here?

antonengelhardt commented 1 year ago

@nordcomputer No, all good.

I am just wondering why its working for you and not for me. My ubuntu machine is just a Server from Hetzner which i use to test amd64 images and deploy containers. I suppose this machine cannot emulate to arm whilst yours can. Do you know if your machine is capable of emulating arm architecture and there is able to execute arm images?

nordcomputer commented 1 year ago

@antonengelhardt I wasnt aware, that there is such thing as an arm emulator for running arm docker images. There seems to be an extra software (qemu), but as far as I am able to google, I would have to explicitly start it, to use it with docker images. And I definitely dont do that...

antonengelhardt commented 1 year ago

@nordcomputer

That's what i meant. I have Qemu on my M1 mac to use amd64 VMs.

I think some machines support it out of the box and some don't. I will investigate this a little more in the future. Also thanks again for your PR. Will check it out soon!

nordcomputer commented 1 year ago

No problem and Good night :)

antonengelhardt commented 1 year ago

Hey @nordcomputer I have done some changes and commited them on several branches in my repo:

  1. Arm support
  2. Env Vars setup.

I tried to look into buildx (experimental docker feature) but i didn't get it to work.

Your proposal for the 5th env vars HOURS_UNTIL_GAME is coming soon. I can't merge your PR as it is but i will use it as a starting point for this feature! Thanks