diff options
| author | Nick Brassel <nick@tzarc.org> | 2024-06-24 12:29:30 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-24 12:29:30 +1000 |
| commit | 03e688e91f28d73416ada41c6db209c04d18cba7 (patch) | |
| tree | 616d15901ba5e729d9c12d0c0f44e2ab29b4bf32 /util | |
| parent | d5e0562a7043bf372c3f349420dd765ee3a9653d (diff) | |
Add support for userspace to docker build commands. (#23988)
Diffstat (limited to 'util')
| -rwxr-xr-x | util/docker_build.sh | 84 | ||||
| -rwxr-xr-x | util/docker_cmd.sh | 30 |
2 files changed, 25 insertions, 89 deletions
diff --git a/util/docker_build.sh b/util/docker_build.sh index 828b5751af..2234fc96f6 100755 --- a/util/docker_build.sh +++ b/util/docker_build.sh | |||
| @@ -1,85 +1,3 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | # NOTE: This script uses tabs for indentation | ||
| 3 | 2 | ||
| 4 | errcho() { | 3 | ./util/docker_cmd.sh make "$@" |
| 5 | echo "$@" >&2 | ||
| 6 | } | ||
| 7 | |||
| 8 | USAGE="Usage: $0 [keyboard[:keymap[:target]]]" | ||
| 9 | |||
| 10 | # Check preconditions | ||
| 11 | for arg; do | ||
| 12 | if [ "$arg" = "--help" ]; then | ||
| 13 | echo "$USAGE" | ||
| 14 | exit 0 | ||
| 15 | fi | ||
| 16 | done | ||
| 17 | if [ $# -gt 1 ]; then | ||
| 18 | errcho "$USAGE" | ||
| 19 | exit 1 | ||
| 20 | fi | ||
| 21 | |||
| 22 | # Allow $RUNTIME to be overridden by the user as an environment variable | ||
| 23 | # Else check if either podman or docker exit and set them as runtime | ||
| 24 | # if none are found error out | ||
| 25 | if [ -z "$RUNTIME" ]; then | ||
| 26 | if command -v podman >/dev/null 2>&1; then | ||
| 27 | RUNTIME="podman" | ||
| 28 | elif command -v docker >/dev/null 2>&1; then | ||
| 29 | RUNTIME="docker" | ||
| 30 | else | ||
| 31 | errcho "Error: no compatible container runtime found." | ||
| 32 | errcho "Either podman or docker are required." | ||
| 33 | errcho "See https://podman.io/getting-started/installation" | ||
| 34 | errcho "or https://docs.docker.com/install/#supported-platforms" | ||
| 35 | errcho "for installation instructions." | ||
| 36 | exit 2 | ||
| 37 | fi | ||
| 38 | fi | ||
| 39 | |||
| 40 | |||
| 41 | # Determine arguments | ||
| 42 | if [ $# -eq 0 ]; then | ||
| 43 | printf "keyboard=" && read -r keyboard | ||
| 44 | [ -n "$keyboard" ] && printf "keymap=" && read -r keymap | ||
| 45 | [ -n "$keymap" ] && printf "target=" && read -r target | ||
| 46 | else | ||
| 47 | IFS=':' read -r keyboard keymap target x <<-EOF | ||
| 48 | $1 | ||
| 49 | EOF | ||
| 50 | if [ -n "$x" ]; then | ||
| 51 | errcho "$USAGE" | ||
| 52 | exit 1 | ||
| 53 | fi | ||
| 54 | fi | ||
| 55 | if [ -z "$keyboard" ]; then | ||
| 56 | keyboard=all | ||
| 57 | fi | ||
| 58 | if [ -n "$target" ]; then | ||
| 59 | # IF we are using docker on non Linux and docker-machine isn't working print an error | ||
| 60 | # ELSE set usb_args | ||
| 61 | if [ ! "$(uname)" = "Linux" ] && [ "$RUNTIME" = "docker" ] && ! docker-machine active >/dev/null 2>&1; then | ||
| 62 | errcho "Error: target requires docker-machine to work on your platform" | ||
| 63 | errcho "See http://gw.tnode.com/docker/docker-machine-with-usb-support-on-windows-macos" | ||
| 64 | errcho "Consider flashing with QMK Toolbox (https://github.com/qmk/qmk_toolbox) instead" | ||
| 65 | exit 3 | ||
| 66 | else | ||
| 67 | usb_args="--privileged -v /dev:/dev" | ||
| 68 | fi | ||
| 69 | fi | ||
| 70 | dir=$(pwd -W 2>/dev/null) || dir=$PWD # Use Windows path if on Windows | ||
| 71 | |||
| 72 | if [ "$RUNTIME" = "docker" ]; then | ||
| 73 | uid_arg="--user $(id -u):$(id -g)" | ||
| 74 | fi | ||
| 75 | |||
| 76 | # Run container and build firmware | ||
| 77 | "$RUNTIME" run --rm -it $usb_args \ | ||
| 78 | $uid_arg \ | ||
| 79 | -w /qmk_firmware \ | ||
| 80 | -v "$dir":/qmk_firmware \ | ||
| 81 | -e ALT_GET_KEYBOARDS=true \ | ||
| 82 | -e SKIP_GIT="$SKIP_GIT" \ | ||
| 83 | -e MAKEFLAGS="$MAKEFLAGS" \ | ||
| 84 | ghcr.io/qmk/qmk_cli \ | ||
| 85 | make "$keyboard${keymap:+:$keymap}${target:+:$target}" | ||
diff --git a/util/docker_cmd.sh b/util/docker_cmd.sh index 4a82890603..18725db068 100755 --- a/util/docker_cmd.sh +++ b/util/docker_cmd.sh | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | # vim: set ft=sh ts=4 sw=4 noexpandtab | ||
| 2 | # NOTE: This script uses tabs for indentation | 3 | # NOTE: This script uses tabs for indentation |
| 3 | 4 | ||
| 4 | errcho() { | 5 | errcho() { |
| @@ -37,13 +38,26 @@ fi | |||
| 37 | # IF we are using docker on non Linux and docker-machine isn't working print an error | 38 | # IF we are using docker on non Linux and docker-machine isn't working print an error |
| 38 | # ELSE set usb_args | 39 | # ELSE set usb_args |
| 39 | if [ ! "$(uname)" = "Linux" ] && [ "$RUNTIME" = "docker" ] && ! docker-machine active >/dev/null 2>&1; then | 40 | if [ ! "$(uname)" = "Linux" ] && [ "$RUNTIME" = "docker" ] && ! docker-machine active >/dev/null 2>&1; then |
| 40 | errcho "Error: target requires docker-machine to work on your platform" | 41 | errcho "Error: target requires docker-machine to work on your platform" |
| 41 | errcho "See http://gw.tnode.com/docker/docker-machine-with-usb-support-on-windows-macos" | 42 | errcho "See http://gw.tnode.com/docker/docker-machine-with-usb-support-on-windows-macos" |
| 42 | exit 3 | 43 | exit 3 |
| 43 | else | 44 | else |
| 44 | usb_args="--privileged -v /dev:/dev" | 45 | usb_args="--privileged -v /dev:/dev" |
| 46 | fi | ||
| 47 | |||
| 48 | qmk_firmware_dir=$(pwd -W 2>/dev/null) || qmk_firmware_dir=$PWD # Use Windows path if on Windows | ||
| 49 | qmk_userspace_dir="" | ||
| 50 | userspace_docker_args="" | ||
| 51 | |||
| 52 | if [ -n "$QMK_USERSPACE" ] && [ -e "$QMK_USERSPACE/qmk.json" ]; then | ||
| 53 | qmk_userspace_dir=$(cd "$QMK_USERSPACE" && pwd -W 2>/dev/null) || qmk_userspace_dir=$QMK_USERSPACE # Use Windows path if on Windows | ||
| 54 | elif [ -n "$(which qmk 2>/dev/null)" ] && [ -n "$(qmk userspace-path)" ]; then | ||
| 55 | qmk_userspace_dir=$(cd "$(qmk userspace-path)" && pwd -W 2>/dev/null) || qmk_userspace_dir=$(qmk userspace-path) # Use Windows path if on Windows | ||
| 56 | fi | ||
| 57 | |||
| 58 | if [ -n "$qmk_userspace_dir" ]; then | ||
| 59 | userspace_docker_args="-v $qmk_userspace_dir:/qmk_userspace:z -e QMK_USERSPACE=/qmk_userspace" | ||
| 45 | fi | 60 | fi |
| 46 | dir=$(pwd -W 2>/dev/null) || dir=$PWD # Use Windows path if on Windows | ||
| 47 | 61 | ||
| 48 | if [ "$RUNTIME" = "docker" ]; then | 62 | if [ "$RUNTIME" = "docker" ]; then |
| 49 | uid_arg="--user $(id -u):$(id -g)" | 63 | uid_arg="--user $(id -u):$(id -g)" |
| @@ -54,6 +68,10 @@ fi | |||
| 54 | $usb_args \ | 68 | $usb_args \ |
| 55 | $uid_arg \ | 69 | $uid_arg \ |
| 56 | -w /qmk_firmware \ | 70 | -w /qmk_firmware \ |
| 57 | -v "$dir":/qmk_firmware \ | 71 | -v "$qmk_firmware_dir":/qmk_firmware:z \ |
| 72 | $userspace_docker_args \ | ||
| 73 | -e SKIP_GIT="$SKIP_GIT" \ | ||
| 74 | -e SKIP_VERSION="$SKIP_VERSION" \ | ||
| 75 | -e MAKEFLAGS="$MAKEFLAGS" \ | ||
| 58 | ghcr.io/qmk/qmk_cli \ | 76 | ghcr.io/qmk/qmk_cli \ |
| 59 | "$@" | 77 | "$@" |
