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

feat(qemu_static_image): add qemu_static_image option #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ The action also accepts some optional input parameters:
* `dockerRunArgs`: Additional arguments to pass to `docker run`, such as volume mappings. See [`docker run` documentation](https://docs.docker.com/engine/reference/commandline/run).
* `setup`: Shell commands to execute on the host before running the container, such as creating directories for volume mappings.
* `install`: Shell commands to execute in the container as part of `docker build`, such as installing dependencies. This speeds up subsequent builds if `githubToken` is also used, but note that the image layer will be publicly available in your projects GitHub Package Registry, so make sure the resulting image does not have any secrets cached in logs or state.
* `base_image`: Specify a custom base image, such as [busybox](https://hub.docker.com/_/busybox), `arch` and `distro` should be set to `none` in this case. This will allow you to chose direcly the image that will be used in the *FROM* clause of the internal docker container without needing to create a Dockerfile.arch.distro for a specific arch/distro pair. For more detials, see [PR #103](https://github.com/uraimo/run-on-arch-action/pull/103#issuecomment-1363810049). Known limitation: Only one base_image configuration for each workflow if you use GitHub images caching.
* `base_image`: Specify a custom base image, such as [busybox](https://hub.docker.com/_/busybox), `arch` and `distro` should be set to `none` in this case. This will allow you to chose direcly the image that will be used in the *FROM* clause of the internal docker container without needing to create a Dockerfile.arch.distro for a specific arch/distro pair. For more details, see [PR #103](https://github.com/uraimo/run-on-arch-action/pull/103#issuecomment-1363810049). Known limitation: Only one base_image configuration for each workflow if you use GitHub images caching.
* `qemu_static_image`: Specify a custom image for registering QEMU emulators. If not set, **multiarch/qemu-user-static** will be used by default.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would that work with aptman/qus (https://dbhi.github.io/qus/) ?
AFAIK QUS is also still on QEMU 7.1 but I wonder how generic this new setting is - does it support any qemu-user-static provider or just forks of multiarch/qemu-user-static.

One thing I like better in QUS is that it works on other platforms too, e.g. you can emulate x86_64 on aarch64 machine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, I have tested with my own fork of multiarch/qemu-user-static, which can be used from longhronshens/qemu-user-static:latest. This fork has been updated to use qemu 7.2. As for aptman/qus, this is more complicated than what run-on-arch-action does. That is not very good for simple cases. This is why I'd rather to use run-on-arch-action.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As for emulating x86_64 on aarch64 machine, I think my fork can also be used like that, since I have pushed qemu-user-static:latest with multiple architectures. But since uraimo/run-on-arch-action can only be used on GitHub Action runner which runs on x86_64 by default, multi-arch support is somewhat meaningless.


### Basic example

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ inputs:
description: 'Specify a custom base image, such as \"busybox\" or your predefined base image. This will replace the \"FROM\" claus in the default Dockerfile on the fly. This is optional. Hint: with this option you are able to use all the available archs other than the ones showed by default. See the [advanced example](./.github/workflows/advanced-example.yml) in this repo. For more detials, see [PR #103](https://github.com/uraimo/run-on-arch-action/pull/103#issuecomment-1363810049).'
required: false
default: ''
qemu_static_image:
description: 'Specify a custom image for registering QEMU emulators. If not set, \"multiarch/qemu-user-static\" will be used by default.'
required: false
default: 'multiarch/qemu-user-static'

runs:
using: 'node16'
Expand Down
3 changes: 2 additions & 1 deletion src/run-on-arch.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async function main() {
const arch = core.getInput('arch', { required: true });
const distro = core.getInput('distro', { required: true });
const base_image = core.getInput('base_image', { required: false });
const qemu_static_image = core.getInput('qemu_static_image', { required: false });

if((arch==='none' || distro==='none') && !base_image){
throw new Error(`run-on-arch: If arch and distro are not specified, base_image is required.`);
Expand Down Expand Up @@ -126,7 +127,7 @@ async function main() {
console.log('Configuring Docker for multi-architecture support');
await exec(
path.join(__dirname, 'run-on-arch.sh'),
[ dockerFile, containerName, ...dockerRunArgs ],
[ dockerFile, containerName, qemu_static_image, ...dockerRunArgs ],
{ env },
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/run-on-arch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ set -euo pipefail
# Args
DOCKERFILE=$1
CONTAINER_NAME=$2
QEMU_STATIC_CONTAINER=$3

# Remainder of args get passed to docker
declare -a DOCKER_RUN_ARGS=${@:3:${#@}}
declare -a DOCKER_RUN_ARGS=${@:4:${#@}}

# Defaults
ACTION_DIR="$(cd "$(dirname "$0")"/.. >/dev/null 2>&1 ; pwd -P)"
Expand Down Expand Up @@ -35,9 +37,7 @@ install_deps () {
# Install support for non-x86 emulation in Docker via QEMU.
# Platforms: linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x,
# linux/386, linux/arm/v7, linux/arm/v6
sudo apt-get update -q -y
sudo apt-get -qq install -y qemu qemu-user-static
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes --credential yes
docker run --rm --privileged $QEMU_STATIC_CONTAINER --reset -p yes --credential yes
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this answers my earlier question. It won't work with QUS because it uses different options' names (https://dbhi.github.io/qus/tests.html)

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, currently I think we can only use multiarch/qemu-user-static compatible images.

}

build_container () {
Expand Down