Skip to content
box

GitHub Action

Setup QEMU Container

v1.1.1 Latest version

Setup QEMU Container

box

Setup QEMU Container

Set up a podman-powered, QEMU-enabled container for use in workflow steps

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Setup QEMU Container

uses: SanderVocke/[email protected]

Learn more about this action in SanderVocke/setup-qemu-container

Choose a version

GitHub Action: Setup QEMU-enabled Container

Set up a container that keeps running in the background and available to run following workflow steps in, integrated as closely to Github Actions as possible.

The main advantage over the built-in container: functionality is that QEMU-powered containers, that emulate other processor architectures, are available.

The container can be used by any following workflow step which sets the shell to run-in-container.sh {0}. $GITHUB_OUTPUT and $GITHUB_ENV are supported inside the container and propagate outside the container. The workspace folder is also mapped into the container so files can be accessed seamlessly.

Minimal example (Alpine on ARM)

runs-on: ubuntu-latest
steps:
    - uses: sandervocke/setup-qemu-container@v1
      with:
        container: alpine
        arch: arm
    - name: Print architecture from within container
      shell: run-in-container.sh {0}
      run: echo "Arch in container: $(uname -m)"

Matrix jobs

Combining this Action with https://github.com/SanderVocke/setup-shell-wrapper makes it possible to run matrix jobs where some jobs run within containers and some don't.

jobs:
  test:
    strategy:
      matrix:
        job:
           - container: false
             arch: false
           - container: alpine
             arch: arm
    runs-on: ubuntu-latest
    steps:
    - name: Start container
      if: ${{ matrix.job.container }}
      uses: sandervocke/setup-qemu-container@v1
      with:
        container: ${{ matrix.job.container }}
        arch: ${{ matrix.job.arch }}

    - name: Setup Shell Wrapper
      uses: sandervocke/setup-shell-wrapper@v1

    - name: Use regular shell   # Only triggered for non-container jobs
      if: ${{ ! matrix.job.container }}
      shell: bash
      run: echo "WRAP_SHELL=bash" >> $GITHUB_ENV

    - name: Use container shell   # Only triggered for container jobs
      if: ${{ matrix.job.container }}
      shell: bash
      run: echo "WRAP_SHELL=run-in-container.sh" >> $GITHUB_ENV

    - name: Print architecture and OS
      shell: wrap-shell.sh {0}
      run: |
        echo "Architecture: $(uname -m)"
        cat /etc/os-release

For more examples, see .github/workflows/test.yml for examples on how to use this step.