From f3a71db6bb43fa53b696927101d367d4874ab22f Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Mon, 31 Dec 2018 00:33:25 -0700 Subject: [PATCH] improve docker build and script --- .dockerignore | 6 ++++++ build.sh | 39 ++++++++++++++++++++++++++++++++------- uas-ugv.code-workspace | 1 - 3 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8bd4527 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +/.git +/.vscode +/build +/cmake-build* +/components +/main diff --git a/build.sh b/build.sh index 050fddb..fdd9711 100755 --- a/build.sh +++ b/build.sh @@ -1,37 +1,62 @@ #!/bin/bash -set -e -x +set -e + +TPUT=$(which tput 2>/dev/null || echo true) +echo $TPUT DIR=$(cd "$(dirname "$0")"; pwd -P) TOOLCHAIN_IMAGE="esp32-toolchain:latest" : ${BUILD_DIR:="$DIR/cmake-build"} DOCKERFILE="$DIR/Dockerfile" -DOCKER_RUN_FLAGS=(--interactive --rm) -# if stdin is a terminal, tell docker to allocate a tty -if [ -t 0 ]; then - DOCKER_RUN_FLAGS+=(--tty) -fi +echo_status() { + echo "$($TPUT setaf 2)==> $@$($TPUT sgr0)" +} +get_docker_run_flags() { + if [ -z "$DOCKER_RUN_FLAGS" ]; then + DOCKER_RUN_FLAGS=(--interactive --rm) + # if stdin is a terminal, tell docker to allocate a tty + if [ -t 0 ]; then + DOCKER_RUN_FLAGS+=(--tty) + fi + USB_SERIAL_DEVICES=$(find /dev -name 'ttyUSB0' -o -name 'ttyACM*') + for device in $USB_SERIAL_DEVICES; do + DOCKER_RUN_FLAGS+=(--device $device) + echo_status "Adding device $device to container" + done + fi +} build_docker_container() { + echo_status "Building docker container image" docker build -f "$DOCKERFILE" -t "$TOOLCHAIN_IMAGE" "$DIR" + echo_status "Built docker container image and tagged as $TOOLCHAIN_IMAGE" } build_docker() { build_docker_container + get_docker_run_flags + local targets="$@" + if [ -z "$targets" ]; then + targets="all" + fi + echo_status "Building target(s) $targets in container" docker run \ --volume="$DIR:/esp/uas-ugv" \ "${DOCKER_RUN_FLAGS[@]}" \ "$TOOLCHAIN_IMAGE" \ - /esp/uas-ugv/build.sh cmake "$@" + /esp/uas-ugv/build.sh cmake "$targets" } build_cmake() { mkdir -p "$BUILD_DIR" cd "$BUILD_DIR" + echo_status "CMake configure" cmake -G Ninja "$DIR" + echo_status "CMake build $@" cmake --build "$BUILD_DIR" -- "$@" } diff --git a/uas-ugv.code-workspace b/uas-ugv.code-workspace index 39b8cec..3117d58 100644 --- a/uas-ugv.code-workspace +++ b/uas-ugv.code-workspace @@ -9,7 +9,6 @@ "Ninja", "Unix Makefiles" ], - "cmake.buildDirectory": "${workspaceRoot}/cmake-build", "cmake.configureOnOpen": true, "files.associations": { "Dockerfile.*": "dockerfile",