Include initial setup in build script
This commit is contained in:
parent
1bdb36540a
commit
ca6d17dbcf
3 changed files with 138 additions and 71 deletions
|
@ -5,13 +5,17 @@ while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
# needed when user isn't in docker group
|
# needed when user isn't in docker group
|
||||||
-s|--su)
|
-s|--su)
|
||||||
DOCKER_SUDO="sudo"
|
SUDO="sudo"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
-l|--local)
|
-l|--local)
|
||||||
RUNWITH_DOCKER="false"
|
RUNWITH_DOCKER="false"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
-c|--clear-cache)
|
||||||
|
CLEAR_CACHE="true"
|
||||||
|
;;
|
||||||
|
|
||||||
# comma or space separated list of boards (use quotes if space separated)
|
# comma or space separated list of boards (use quotes if space separated)
|
||||||
# if ommitted, will compile list of boards in build.yaml
|
# if ommitted, will compile list of boards in build.yaml
|
||||||
-b|--board)
|
-b|--board)
|
||||||
|
@ -20,7 +24,7 @@ while [[ $# -gt 0 ]]; do
|
||||||
;;
|
;;
|
||||||
|
|
||||||
-v|--version)
|
-v|--version)
|
||||||
WEST_VERSION="$2"
|
ZEPHYR_VERSION="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
@ -69,8 +73,8 @@ while [[ $# -gt 0 ]]; do
|
||||||
done
|
done
|
||||||
|
|
||||||
# Set defaults
|
# Set defaults
|
||||||
[[ -z $WEST_VERSION ]] && WEST_VERSION="3.0"
|
[[ -z $ZEPHYR_VERSION ]] && ZEPHYR_VERSION="3.0"
|
||||||
[[ -z $RUNWITH_DOCKER ]] && RUNWITH_DOCKER=true
|
[[ -z $RUNWITH_DOCKER ]] && RUNWITH_DOCKER="true"
|
||||||
|
|
||||||
[[ -z $OUTPUT_DIR ]] && OUTPUT_DIR="$WINHOME/Downloads"
|
[[ -z $OUTPUT_DIR ]] && OUTPUT_DIR="$WINHOME/Downloads"
|
||||||
[[ -z $LOG_DIR ]] && LOG_DIR="/tmp"
|
[[ -z $LOG_DIR ]] && LOG_DIR="/tmp"
|
||||||
|
@ -83,7 +87,9 @@ done
|
||||||
|
|
||||||
[[ -z $BOARDS ]] && BOARDS="$(grep '^[[:space:]]*\-[[:space:]]*board:' $HOST_CONFIG_DIR/build.yaml | sed 's/^.*: *//')"
|
[[ -z $BOARDS ]] && BOARDS="$(grep '^[[:space:]]*\-[[:space:]]*board:' $HOST_CONFIG_DIR/build.yaml | sed 's/^.*: *//')"
|
||||||
|
|
||||||
DOCKER_IMG="zmkfirmware/zmk-dev-arm:$WEST_VERSION"
|
[[ -z $CLEAR_CACHE ]] && CLEAR_CACHE="false"
|
||||||
|
|
||||||
|
DOCKER_IMG="zmkfirmware/zmk-dev-arm:$ZEPHYR_VERSION"
|
||||||
|
|
||||||
# +-------------------------+
|
# +-------------------------+
|
||||||
# | AUTOMATE CONFIG OPTIONS |
|
# | AUTOMATE CONFIG OPTIONS |
|
||||||
|
@ -121,20 +127,37 @@ fi
|
||||||
if [[ $RUNWITH_DOCKER = true ]]
|
if [[ $RUNWITH_DOCKER = true ]]
|
||||||
then
|
then
|
||||||
echo "Build mode: docker"
|
echo "Build mode: docker"
|
||||||
DOCKER_CMD="$DOCKER_SUDO docker run --name zmk --rm -w $DOCKER_ZMK_DIR/app \
|
DOCKER_CMD="$SUDO docker run --name zmk-$ZEPHYR_VERSION --rm \
|
||||||
--mount type=bind,source=$HOST_ZMK_DIR,target=$DOCKER_ZMK_DIR \
|
--mount type=bind,source=$HOST_ZMK_DIR,target=$DOCKER_ZMK_DIR \
|
||||||
--mount type=bind,source=$HOST_CONFIG_DIR,target=$DOCKER_CONFIG_DIR,readonly \
|
--mount type=bind,source=$HOST_CONFIG_DIR,target=$DOCKER_CONFIG_DIR,readonly \
|
||||||
--mount type=volume,source=zmk-root-user-$WEST_VERSION,target=/root \
|
--mount type=volume,source=zmk-root-user-$ZEPHYR_VERSION,target=/root \
|
||||||
--mount type=volume,source=zmk-zephyr-$WEST_VERSION,target=$DOCKER_ZMK_DIR/zephyr \
|
--mount type=volume,source=zmk-zephyr-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/zephyr \
|
||||||
--mount type=volume,source=zmk-zephyr-modules-$WEST_VERSION,target=$DOCKER_ZMK_DIR/modules \
|
--mount type=volume,source=zmk-zephyr-modules-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/modules \
|
||||||
--mount type=volume,source=zmk-zephyr-tools-$WEST_VERSION,target=$DOCKER_ZMK_DIR/tools \
|
--mount type=volume,source=zmk-zephyr-tools-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/tools"
|
||||||
$DOCKER_IMG"
|
|
||||||
SUFFIX="${WEST_VERSION}_docker"
|
# Reset volumes
|
||||||
|
if [[ $CLEAR_CACHE = true ]]
|
||||||
|
then
|
||||||
|
$SUDO docker volume rm $(sudo docker volume ls -q | grep "^zmk-.*-$ZEPHYR_VERSION$")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update west if needed
|
||||||
|
OLD_WEST="/root/west.yml.old"
|
||||||
|
$DOCKER_CMD -w "$DOCKER_ZMK_DIR" "$DOCKER_IMG" /bin/bash -c " \
|
||||||
|
if [[ ! -f .west/config ]]; then west init -l app/; fi \
|
||||||
|
&& if [[ -f $OLD_WEST ]]; then md5_old=\$(md5sum $OLD_WEST | cut -d' ' -f1); fi \
|
||||||
|
&& [[ \$md5_old != \$(md5sum app/west.yml | cut -d' ' -f1) ]] \
|
||||||
|
&& west update \
|
||||||
|
&& cp app/west.yml $OLD_WEST"
|
||||||
|
|
||||||
|
# Build parameters
|
||||||
|
DOCKER_PREFIX="$DOCKER_CMD -w $DOCKER_ZMK_DIR/app $DOCKER_IMG"
|
||||||
|
SUFFIX="${ZEPHYR_VERSION}_docker"
|
||||||
CONFIG_DIR="$DOCKER_CONFIG_DIR/config"
|
CONFIG_DIR="$DOCKER_CONFIG_DIR/config"
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "Build mode: local"
|
echo "Build mode: local"
|
||||||
SUFFIX="${WEST_VERSION}"
|
SUFFIX="${ZEPHYR_VERSION}"
|
||||||
CONFIG_DIR="$HOST_CONFIG_DIR/config"
|
CONFIG_DIR="$HOST_CONFIG_DIR/config"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -143,7 +166,7 @@ compile_board () {
|
||||||
echo -en "\n$(tput setaf 2)Building $1... $(tput sgr0)"
|
echo -en "\n$(tput setaf 2)Building $1... $(tput sgr0)"
|
||||||
BUILD_DIR="${1}_$SUFFIX"
|
BUILD_DIR="${1}_$SUFFIX"
|
||||||
LOGFILE="$LOG_DIR/zmk_build_$1.log"
|
LOGFILE="$LOG_DIR/zmk_build_$1.log"
|
||||||
$DOCKER_CMD west build -d "build/$BUILD_DIR" -b $1 $WEST_OPTS \
|
$DOCKER_PREFIX west build -d "build/$BUILD_DIR" -b $1 $WEST_OPTS \
|
||||||
-- -DZMK_CONFIG="$CONFIG_DIR" -Wno-dev > "$LOGFILE" 2>&1
|
-- -DZMK_CONFIG="$CONFIG_DIR" -Wno-dev > "$LOGFILE" 2>&1
|
||||||
if [[ $? -eq 0 ]]
|
if [[ $? -eq 0 ]]
|
||||||
then
|
then
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Parse input arguments
|
|
||||||
while [[ $# -gt 0 ]]; do
|
|
||||||
case $1 in
|
|
||||||
# needed when user isn't in docker group
|
|
||||||
-s|--sudu)
|
|
||||||
SUDO="sudo"
|
|
||||||
;;
|
|
||||||
|
|
||||||
-v|--version)
|
|
||||||
WEST_VERSION="$2"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
|
|
||||||
--host-zmk-dir)
|
|
||||||
HOST_ZMK_DIR="$2"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
|
|
||||||
--docker-zmk-dir)
|
|
||||||
DOCKER_ZMK_DIR="$2"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo "Unknown option $1"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
# Set defaults
|
|
||||||
[[ -z $WEST_VERSION ]] && WEST_VERSION="3.0"
|
|
||||||
[[ -z $HOST_ZMK_DIR ]] && HOST_ZMK_DIR="$HOME/zmk"
|
|
||||||
[[ -z $DOCKER_ZMK_DIR ]] && DOCKER_ZMK_DIR="/workspace/zmk"
|
|
||||||
|
|
||||||
DOCKER_IMG="zmkfirmware/zmk-dev-arm:$WEST_VERSION"
|
|
||||||
DOCKER_CMD="$SUDO docker run --name zmk-$WEST_VERSION --rm \
|
|
||||||
--mount type=bind,source=$HOST_ZMK_DIR,target=$DOCKER_ZMK_DIR \
|
|
||||||
--mount type=volume,source=zmk-root-user-$WEST_VERSION,target=/root \
|
|
||||||
--mount type=volume,source=zmk-zephyr-$WEST_VERSION,target=$DOCKER_ZMK_DIR/zephyr \
|
|
||||||
--mount type=volume,source=zmk-zephyr-modules-$WEST_VERSION,target=$DOCKER_ZMK_DIR/modules \
|
|
||||||
--mount type=volume,source=zmk-zephyr-tools-$WEST_VERSION,target=$DOCKER_ZMK_DIR/tools"
|
|
||||||
|
|
||||||
# Reset volumes
|
|
||||||
$SUDO docker volume rm $(sudo docker volume ls -q | grep "^zmk-.*-$WEST_VERSION$")
|
|
||||||
|
|
||||||
# Install west
|
|
||||||
$DOCKER_CMD -w "$DOCKER_ZMK_DIR" "$DOCKER_IMG" west init -l app/
|
|
||||||
$DOCKER_CMD -w "$DOCKER_ZMK_DIR" "$DOCKER_IMG" west update
|
|
||||||
|
|
||||||
# Install docosaurus
|
|
||||||
$DOCKER_CMD -w "$DOCKER_ZMK_DIR/docs" "$DOCKER_IMG" npm ci
|
|
||||||
|
|
101
scripts/zmk_run_docker.sh
Executable file
101
scripts/zmk_run_docker.sh
Executable file
|
@ -0,0 +1,101 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# This script sets up a docker development environment and starts an interactive shell.
|
||||||
|
# For a one-stop-shop script for building boards, which sets up a build environment in
|
||||||
|
# the background and re-uses it across runs, see zmk_build.sh instead.
|
||||||
|
|
||||||
|
# Parse input arguments
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
# needed when user isn't in docker group
|
||||||
|
-s|--sudu)
|
||||||
|
SUDO="sudo"
|
||||||
|
;;
|
||||||
|
|
||||||
|
-c|--clear-cache)
|
||||||
|
CLEAR_CACHE="true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
-d|--install-doc-tools)
|
||||||
|
DOC_TOOLS="true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
-v|--version)
|
||||||
|
ZEPHYR_VERSION="$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
|
--host-config-dir)
|
||||||
|
HOST_CONFIG_DIR="$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
|
--host-zmk-dir)
|
||||||
|
HOST_ZMK_DIR="$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
|
--docker-config-dir)
|
||||||
|
DOCKER_CONFIG_DIR="$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
|
--docker-zmk-dir)
|
||||||
|
DOCKER_ZMK_DIR="$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Unknown option $1"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
# Set defaults
|
||||||
|
[[ -z $ZEPHYR_VERSION ]] && ZEPHYR_VERSION="3.0"
|
||||||
|
|
||||||
|
[[ -z $HOST_ZMK_DIR ]] && HOST_ZMK_DIR="$HOME/zmk"
|
||||||
|
[[ -z $HOST_CONFIG_DIR ]] && HOST_CONFIG_DIR="$HOME/zmk-config"
|
||||||
|
|
||||||
|
[[ -z $DOCKER_ZMK_DIR ]] && DOCKER_ZMK_DIR="/workspace/zmk"
|
||||||
|
[[ -z $DOCKER_CONFIG_DIR ]] && DOCKER_CONFIG_DIR="/workspace/zmk-config"
|
||||||
|
|
||||||
|
[[ -z $CLEAR_CACHE ]] && CLEAR_CACHE="false"
|
||||||
|
[[ -z $DOC_TOOLS ]] && DOC_TOOLS="false"
|
||||||
|
|
||||||
|
DOCKER_IMG="zmkfirmware/zmk-dev-arm:$ZEPHYR_VERSION"
|
||||||
|
DOCKER_CMD="$SUDO docker run --name zmk-$ZEPHYR_VERSION --rm \
|
||||||
|
--mount type=bind,source=$HOST_ZMK_DIR,target=$DOCKER_ZMK_DIR \
|
||||||
|
--mount type=bind,source=$HOST_CONFIG_DIR,target=$DOCKER_CONFIG_DIR \
|
||||||
|
--mount type=volume,source=zmk-root-user-$ZEPHYR_VERSION,target=/root \
|
||||||
|
--mount type=volume,source=zmk-zephyr-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/zephyr \
|
||||||
|
--mount type=volume,source=zmk-zephyr-modules-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/modules \
|
||||||
|
--mount type=volume,source=zmk-zephyr-tools-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/tools"
|
||||||
|
|
||||||
|
# Reset volumes
|
||||||
|
if [[ $CLEAR_CACHE = true ]]
|
||||||
|
then
|
||||||
|
$SUDO docker volume rm $(sudo docker volume ls -q | grep "^zmk-.*-$ZEPHYR_VERSION$")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update west if needed
|
||||||
|
OLD_WEST="/root/west.yml.old"
|
||||||
|
$DOCKER_CMD -w "$DOCKER_ZMK_DIR" "$DOCKER_IMG" /bin/bash -c " \
|
||||||
|
if [[ ! -f .west/config ]]; then west init -l app/; fi \
|
||||||
|
&& if [[ -f $OLD_WEST ]]; then md5_old=\$(md5sum $OLD_WEST | cut -d' ' -f1); fi \
|
||||||
|
&& [[ \$md5_old != \$(md5sum app/west.yml | cut -d' ' -f1) ]] \
|
||||||
|
&& cp app/west.yml $OLD_WEST \
|
||||||
|
&& west update"
|
||||||
|
|
||||||
|
# Install docosaurus
|
||||||
|
if [[ $DOC_TOOLS = true ]]
|
||||||
|
then
|
||||||
|
$DOCKER_CMD -w "$DOCKER_ZMK_DIR/docs" "$DOCKER_IMG" npm ci
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Start interactive shell
|
||||||
|
$DOCKER_CMD -w "$DOCKER_ZMK_DIR" -it "$DOCKER_IMG" /bin/bash
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue