|
1 | | -The error "exec /bin/sh: exec format error" usually indicates an architecture mismatch. You're trying to run an ARM-compiled binary (the shell within the Docker container) on a system with a different architecture (likely x86_64). While you're specifying --platform linux/arm/v7, the issue lies in the nested docker run command. |
| 1 | +name: Build Python-miio for ARMv7 using QEMU |
2 | 2 |
|
3 | | -Here's the breakdown of the problem and the solution: |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main # 自动触发条件:当 main 分支有新的提交时 |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main # 自动触发条件:当有 PR 合并到 main 分支时 |
| 10 | + workflow_dispatch: # 手动触发条件 |
4 | 11 |
|
5 | | -Nested docker run: You're attempting to run a Docker container inside another Docker container, and the inner container inherits the architecture of the outer Docker daemon, not the --platform flag you specified. This flag only affects the initial image pull. Since your host machine likely isn't ARM, the inner docker run tries to execute an ARM binary on a non-ARM system, resulting in the exec format error. |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v2 |
6 | 18 |
|
7 | | -Incorrect Shell Command: You're mixing the commands for running the container and the commands to be executed inside the container. The \ continues the Docker command, not the shell command within it. This leads to the outer docker run trying to execute /bin/sh -c " docker run ..., which isn't what you intend. |
| 19 | + - name: Set up QEMU for ARM |
| 20 | + uses: docker/setup-qemu-action@v2 |
| 21 | + with: |
| 22 | + platforms: arm |
8 | 23 |
|
9 | | -Here's how to fix it: Combine everything into a single docker run command: |
| 24 | + - name: Set up Python for ARMv7 |
| 25 | + run: | |
| 26 | + sudo apt-get update |
| 27 | + sudo apt-get install -y qemu-user-static |
| 28 | + sudo update-binfmts --install arm /usr/bin/qemu-arm-static --magic '\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x28\x00\x01\x00\x00\x00' --mask '\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' |
10 | 29 |
|
11 | | -bash |
12 | | -docker run --rm --platform linux/arm/v7 -v $(pwd):/workspace -w /workspace arm32v7/python:3-slim /bin/sh -c " |
13 | | - python -m venv venv && \ |
14 | | - . venv/bin/activate && \ |
15 | | - pip install --upgrade pip && \ |
16 | | - pip install git+https://github.com/rytilahti/python-miio.git && \ |
17 | | - python -c 'import miio; print(miio.__version__)' > version.txt |
18 | | -" |
19 | | -This single command does the following: |
| 30 | + - name: Create virtual environment and install python-miio |
| 31 | + run: | |
| 32 | + python3 -m venv venv |
| 33 | + . venv/bin/activate |
| 34 | + pip install --upgrade pip |
| 35 | + pip install git+https://github.com/rytilahti/python-miio.git |
| 36 | + python -c 'import miio; print(miio.__version__)' > version.txt |
20 | 37 |
|
21 | | -Pulls the correct image: docker run --rm --platform linux/arm/v7 ... arm32v7/python:3-slim pulls the ARM-based Python image. |
22 | | -Executes the commands within the ARM container: /bin/sh -c "..." executes the provided commands within the ARM container, ensuring the correct architecture. |
23 | | -By removing the nested docker run and correctly structuring the command, you should be able to run your Python script within the ARM container successfully. This avoids the architecture mismatch and ensures the entire process occurs within the emulated ARM environment. |
| 38 | + - name: Archive virtual environment |
| 39 | + run: | |
| 40 | + tar -czvf python-miio-armv7.tar.gz venv/ |
| 41 | +
|
| 42 | + - name: Upload artifact |
| 43 | + uses: actions/upload-artifact@v4 |
| 44 | + with: |
| 45 | + name: python-miio-armv7 |
| 46 | + path: | |
| 47 | + python-miio-armv7.tar.gz |
| 48 | + version.txt |
0 commit comments