From f5bbd617845e190c40265bcdc835ee2ac14afbad Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 5 Mar 2022 19:19:20 -0800 Subject: [PATCH] Simplify our docker execution (#1124) * Switch docker to no longer build a bundle separate from the kaleidoscope dir. Stop copying over a bunch of tarballs we don't need. * fix shellcheck * Stop copying the core-bundled copies of Kaleidoscope over to docker * Symlink our Kaleidoscope into the versions packaged into the arduino cores when running in docker. We need to do this to satisfy the sketch_header.h/sketch_footer.h system we use to be able to amend arduino sketches on avr and virtual. (This feature is not used by the core and may be removed in the future) * Reimplement docker-clean to do much less work and get the same result * Add a stub at docs for the docker test runner --- Makefile | 2 +- bin/docs/example-to-doc | 2 +- bin/run-docker | 23 +++++++++++++++++++---- docs/codebase/docker.md | 25 +++++++++++++++++++++++++ etc/Dockerfile | 4 +++- etc/docker-entrypoint.sh | 6 ++++-- 6 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 docs/codebase/docker.md diff --git a/Makefile b/Makefile index 82ec0b93..d5ca96dd 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ docker-simulator-tests: ARDUINO_DIRECTORIES_USER="$(ARDUINO_DIRECTORIES_USER)" ./bin/run-docker "make simulator-tests $(TEST_PATH_ARG)" docker-clean: - ARDUINO_DIRECTORIES_USER="$(ARDUINO_DIRECTORIES_USER)" ./bin/run-docker "make clean" + _NO_SYNC_KALEIDOSCOPE=1 ARDUINO_DIRECTORIES_USER="$(ARDUINO_DIRECTORIES_USER)" ./bin/run-docker "rm -rf -- testing/googletest/build/* _build/* /kaleidoscope-persist/temp/*" docker-bash: ARDUINO_DIRECTORIES_USER="$(ARDUINO_DIRECTORIES_USER)" ./bin/run-docker "bash" diff --git a/bin/docs/example-to-doc b/bin/docs/example-to-doc index f960bf63..0bcb2f07 100755 --- a/bin/docs/example-to-doc +++ b/bin/docs/example-to-doc @@ -1,6 +1,6 @@ #!/bin/sh -export EXAMPLE=$1 +export EXAMPLE="$1" EXNAME=$(echo "${EXAMPLE}" |cut -c 3-) cd examples ||exit; \ install -d dirname "${EXAMPLE}" diff --git a/bin/run-docker b/bin/run-docker index c00b8f58..aac051e0 100755 --- a/bin/run-docker +++ b/bin/run-docker @@ -19,13 +19,28 @@ else ARDUINO_LOCAL_LIB_PATH="${ARDUINO_LOCAL_LIB_PATH:-${HOME}/Arduino}" fi -echo "Preparing Kaleidoscope and the bundle..." + +if [ ! -d ./.arduino/user/hardware ]; then + echo "Running tests in Docker requires that your Arduino environment be installed in .arduino inside the top-level Kaleidoscope directory. To set this up, run 'make setup'" + exit 1 +fi + + XFER_DIR="$(pwd)/.docker_xfer" mkdir -p "${XFER_DIR}" +if [ -z "$_NO_SYNC_KALEIDOSCOPE" ]; then + +echo "Preparing Kaleidoscope..." + + +echo "The bundle is coming from ${ARDUINO_DIRECTORIES_USER}/hardware/keyboardio" tar -cf "${XFER_DIR}/kaleidoscope.tar" \ --exclude .arduino/data \ + --exclude .arduino/downloads \ + --exclude .arduino/user/hardware/keyboardio/avr/libraries/Kaleidoscope \ + --exclude .arduino/user/hardware/keyboardio/gd32/libraries/Kaleidoscope \ --exclude bin/arduino-cli \ --exclude .docker_xfer \ --exclude .git \ @@ -33,9 +48,8 @@ tar -cf "${XFER_DIR}/kaleidoscope.tar" \ --exclude testing/googletest/build \ . -echo "The bundle is coming from ${ARDUINO_DIRECTORIES_USER}/hardware/keyboardio" -(cd "${ARDUINO_DIRECTORIES_USER}/hardware/keyboardio" && tar -cf "${XFER_DIR}/bundle.tar" \ - --exclude .git --exclude avr/libraries/Kaleidoscope .) +fi + echo "Building the docker image..." docker build -q -t kaleidoscope/docker etc @@ -49,6 +63,7 @@ docker run --rm $DOCKER_RUN_INTERACTIVE_OPTS \ --mount type=volume,source=kaleidoscope-build,destination=/kaleidoscope/_build,consistency=delegated \ --env ARDUINO_DIRECTORIES_DATA=/arduino-cli/data \ --env ARDUINO_DIRECTORIES_USER=/kaleidoscope/.arduino/user/ \ + --env _NO_SYNC_KALEIDOSCOPE=${_NO_SYNC_KALEIDOSCOPE} \ kaleidoscope/docker "$*" diff --git a/docs/codebase/docker.md b/docs/codebase/docker.md new file mode 100644 index 00000000..d2fd712e --- /dev/null +++ b/docs/codebase/docker.md @@ -0,0 +1,25 @@ +# Docker + +It's possible to use Docker to run Kaleidoscope's test suite. + +## Running tests in Docker + +``` +# make docker-simulator-tests +``` + +## Cleaning out stale data in the Docker image: + +``` +# make docker-clean +``` + + +## Removing the Kaleidoscope Docker image entirely: + +``` +# docker volume rm kaleidoscope-persist +# docker volume rm kaleidoscope-googletest-build +# docker volume rm kaleidoscope-build +# docker image rm kaleidoscope/docker +``` diff --git a/etc/Dockerfile b/etc/Dockerfile index 82670697..0e6e0e5a 100644 --- a/etc/Dockerfile +++ b/etc/Dockerfile @@ -12,11 +12,13 @@ RUN curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/inst sh RUN ARDUINO_DIRECTORIES_DATA=/arduino-cli/data \ - ARDUINO_BOARD_MANAGER_ADDITIONAL_URLS=https://raw.githubusercontent.com/keyboardio/boardsmanager/master/package_keyboardio_index.json \ + ARDUINO_BOARD_MANAGER_ADDITIONAL_URLS=https://raw.githubusercontent.com/keyboardio/boardsmanager/master/devel/package_kaleidoscope_devel_index.json \ /bin/arduino-cli config init RUN ARDUINO_DIRECTORIES_DATA=/arduino-cli/data /bin/arduino-cli update RUN ARDUINO_DIRECTORIES_DATA=/arduino-cli/data /bin/arduino-cli core update-index RUN ARDUINO_DIRECTORIES_DATA=/arduino-cli/data /bin/arduino-cli core install arduino:avr +RUN ARDUINO_DIRECTORIES_DATA=/arduino-cli/data /bin/arduino-cli core install "keyboardio:avr-tools-only" +RUN ARDUINO_DIRECTORIES_DATA=/arduino-cli/data /bin/arduino-cli core install "keyboardio:gd32-tools-only" COPY docker-entrypoint.sh /usr/local/bin/entrypoint diff --git a/etc/docker-entrypoint.sh b/etc/docker-entrypoint.sh index 7a819c83..30de89c9 100755 --- a/etc/docker-entrypoint.sh +++ b/etc/docker-entrypoint.sh @@ -6,13 +6,15 @@ install -d /kaleidoscope/ \ /kaleidoscope-persist/temp \ /kaleidoscope-persist/ccache/cache +if [ -z $_NO_SYNC_KALEIDOSCOPE ]; then echo "Syncing Kaleidoscope..." tar xf /kaleidoscope-src/kaleidoscope.tar -C /kaleidoscope/ -echo "Syncing the bundle..." -tar xf /kaleidoscope-src/bundle.tar -C /kaleidoscope/.arduino/user/hardware/keyboardio +ln -s /kaleidoscope /kaleidoscope/.arduino/user/hardware/keyboardio/avr/libraries/Kaleidoscope +ln -s /kaleidoscope /kaleidoscope/.arduino/user/hardware/keyboardio/gd32/libraries/Kaleidoscope +fi cd /kaleidoscope/ export ARDUINO_DIRECTORIES_DATA=/arduino-cli/data