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

Pass arch to docker #63

Open
wants to merge 4 commits 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
1 change: 1 addition & 0 deletions .github/workflows/advanced-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:

# Run steps on a matrix of 4 arch/distro combinations
strategy:
fail-fast: false
matrix:
include:
- arch: aarch64
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jobs:
name: Test

strategy:
fail-fast: false
matrix:
include:
# The full matrix of Dockerfiles would be extensive, so just
Expand Down
2 changes: 1 addition & 1 deletion Dockerfiles/Dockerfile.aarch64.archarm_latest
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM agners/archlinuxarm-arm64v8:latest
FROM danhunsaker/archlinuxarm-arm64v8:latest

COPY ./run-on-arch-install.sh /root/run-on-arch-install.sh
RUN chmod +x /root/run-on-arch-install.sh && /root/run-on-arch-install.sh
2 changes: 1 addition & 1 deletion Dockerfiles/Dockerfile.armv7.archarm_latest
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM agners/archlinuxarm-arm32v7:latest
FROM danhunsaker/archlinuxarm-arm32v7:latest

COPY ./run-on-arch-install.sh /root/run-on-arch-install.sh
RUN chmod +x /root/run-on-arch-install.sh && /root/run-on-arch-install.sh
15 changes: 14 additions & 1 deletion src/run-on-arch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ function slug(str) {
return str.replace(/[^a-zA-Z0-9]/g, '-').toLowerCase();
}

function dockerArch(qemuArch) {
const matrix = {
'i386': '386',
'x86_64': 'amd64',
'armv5': 'arm/v5',
'armv6': 'arm/v6',
'armv7': 'arm/v7',
'aarch64': 'arm64',
};

return matrix[qemuArch] || qemuArch;
}

async function main() {
if (process.platform !== 'linux') {
throw new Error('run-on-arch supports only Linux')
Expand Down Expand Up @@ -108,7 +121,7 @@ async function main() {
console.log('Configuring Docker for multi-architecture support')
await exec(
path.join(__dirname, 'run-on-arch.sh'),
[ dockerFile, containerName, ...dockerRunArgs ],
[ dockerArch(arch), dockerFile, containerName, ...dockerRunArgs ],
{ env },
);
}
Expand Down
24 changes: 15 additions & 9 deletions src/run-on-arch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
set -euo pipefail

# Args
DOCKERFILE=$1
CONTAINER_NAME=$2
TARGET_ARCH=$1
DOCKERFILE=$2
CONTAINER_NAME=$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 @@ -47,8 +48,9 @@ build_container () {
# cached between builds.
if [[ -z "${GITHUB_TOKEN:-}" ]]
then
docker build \
docker buildx build \
"${ACTION_DIR}/Dockerfiles" \
--platform "linux/${TARGET_ARCH}" \
--file "$DOCKERFILE" \
--tag "${CONTAINER_NAME}:latest"
else
Expand All @@ -68,8 +70,9 @@ build_container () {
set "$BASH_FLAGS"

docker pull "$PACKAGE_REGISTRY:latest" || true
docker build \
docker buildx build \
"${ACTION_DIR}/Dockerfiles" \
--platform "linux/${TARGET_ARCH}" \
--file "$DOCKERFILE" \
--tag "${CONTAINER_NAME}:latest" \
--cache-from="$PACKAGE_REGISTRY"
Expand All @@ -87,7 +90,8 @@ run_container () {
# Interpolate DOCKER_RUN_ARGS, to support evaluation of $VAR references
for i in "${!DOCKER_RUN_ARGS[@]}"
do
DOCKER_RUN_ARGS[$i]=$(eval echo "${DOCKER_RUN_ARGS[$i]}")
# We have to do some ugly "magic" here to prevent flags from getting eaten
DOCKER_RUN_ARGS[$i]=$(eval echo _"${DOCKER_RUN_ARGS[$i]}" | sed s/^_//)
done

chmod +x "${ACTION_DIR}/src/run-on-arch-commands.sh"
Expand All @@ -97,6 +101,7 @@ run_container () {

docker run \
--workdir "${GITHUB_WORKSPACE}" \
--platform "linux/${TARGET_ARCH}" \
--rm \
-e DEBIAN_FRONTEND=noninteractive \
-e CI \
Expand Down Expand Up @@ -138,8 +143,9 @@ run_container () {
quiet rm -f build-log.txt
quiet install_deps

echo "::group::Build container"
echo "::group::Build Container"
build_container

echo "::group::Run container"
echo "::endgroup::"
echo "::group::Run Container"
run_container
echo "::endgroup::"