summaryrefslogtreecommitdiff
path: root/util/docker_build.sh
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2024-06-24 12:29:30 +1000
committerGitHub <noreply@github.com>2024-06-24 12:29:30 +1000
commit03e688e91f28d73416ada41c6db209c04d18cba7 (patch)
tree616d15901ba5e729d9c12d0c0f44e2ab29b4bf32 /util/docker_build.sh
parentd5e0562a7043bf372c3f349420dd765ee3a9653d (diff)
Add support for userspace to docker build commands. (#23988)
Diffstat (limited to 'util/docker_build.sh')
-rwxr-xr-xutil/docker_build.sh84
1 files changed, 1 insertions, 83 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
4errcho() { 3./util/docker_cmd.sh make "$@"
5 echo "$@" >&2
6}
7
8USAGE="Usage: $0 [keyboard[:keymap[:target]]]"
9
10# Check preconditions
11for arg; do
12 if [ "$arg" = "--help" ]; then
13 echo "$USAGE"
14 exit 0
15 fi
16done
17if [ $# -gt 1 ]; then
18 errcho "$USAGE"
19 exit 1
20fi
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
25if [ -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
38fi
39
40
41# Determine arguments
42if [ $# -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
46else
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
54fi
55if [ -z "$keyboard" ]; then
56 keyboard=all
57fi
58if [ -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
69fi
70dir=$(pwd -W 2>/dev/null) || dir=$PWD # Use Windows path if on Windows
71
72if [ "$RUNTIME" = "docker" ]; then
73 uid_arg="--user $(id -u):$(id -g)"
74fi
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}"